Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Add DEBUG tracing to arithmetic $(( )) parsing & eval...
details: https://anonhg.NetBSD.org/src/rev/023f137fc1da
branches: trunk
changeset: 353958:023f137fc1da
user: kre <kre%NetBSD.org@localhost>
date: Mon May 29 22:54:07 2017 +0000
description:
Add DEBUG tracing to arithmetic $(( )) parsing & evaluation.
NFC for non-DEBUG shells.
diffstat:
bin/sh/arith_token.c | 14 +++++++++++---
bin/sh/arithmetic.c | 25 +++++++++++++++++++++++--
2 files changed, 34 insertions(+), 5 deletions(-)
diffs (173 lines):
diff -r 2f4d78992d80 -r 023f137fc1da bin/sh/arith_token.c
--- a/bin/sh/arith_token.c Mon May 29 22:27:47 2017 +0000
+++ b/bin/sh/arith_token.c Mon May 29 22:54:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arith_token.c,v 1.3 2017/03/20 13:12:35 kre Exp $ */
+/* $NetBSD: arith_token.c,v 1.4 2017/05/29 22:54:07 kre Exp $ */
/*-
* Copyright (c) 2002
@@ -39,7 +39,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: arith_token.c,v 1.3 2017/03/20 13:12:35 kre Exp $");
+__RCSID("$NetBSD: arith_token.c,v 1.4 2017/05/29 22:54:07 kre Exp $");
#endif /* not lint */
#include <inttypes.h>
@@ -54,6 +54,7 @@
#include "memalloc.h"
#include "parser.h"
#include "syntax.h"
+#include "show.h"
#if ARITH_BOR + ARITH_ASS_GAP != ARITH_BORASS || \
ARITH_ASS + ARITH_ASS_GAP != ARITH_EQ
@@ -87,6 +88,8 @@
*/
a_t_val.val = strtoimax(buf, &end, 0);
arith_buf = end;
+ VTRACE(DBG_ARITH, ("Arith token ARITH_NUM=%jd\n",
+ a_t_val.val));
return ARITH_NUM;
} else if (is_name(token)) {
@@ -102,6 +105,8 @@
memcpy(a_t_val.name, p, buf - p);
a_t_val.name[buf - p] = '\0';
arith_buf = buf;
+ VTRACE(DBG_ARITH, ("Arith token ARITH_VAR=\"%s\"\n",
+ a_t_val.name));
return ARITH_VAR;
} else switch (token) {
@@ -109,9 +114,11 @@
* everything else must be some kind of
* operator, white space, or an error.
*/
+ case '\n':
+ VTRACE(DBG_ARITH, ("Arith: newline\n"));
+ /* FALLTHROUGH */
case ' ':
case '\t':
- case '\n':
buf++;
continue;
@@ -231,5 +238,6 @@
buf++;
out:
arith_buf = buf;
+ VTRACE(DBG_ARITH, ("Arith token: %d\n", token));
return token;
}
diff -r 2f4d78992d80 -r 023f137fc1da bin/sh/arithmetic.c
--- a/bin/sh/arithmetic.c Mon May 29 22:27:47 2017 +0000
+++ b/bin/sh/arithmetic.c Mon May 29 22:54:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arithmetic.c,v 1.1 2017/03/20 11:26:07 kre Exp $ */
+/* $NetBSD: arithmetic.c,v 1.2 2017/05/29 22:54:07 kre Exp $ */
/*-
* Copyright (c) 1993
@@ -39,7 +39,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: arithmetic.c,v 1.1 2017/03/20 11:26:07 kre Exp $");
+__RCSID("$NetBSD: arithmetic.c,v 1.2 2017/05/29 22:54:07 kre Exp $");
#endif /* not lint */
#include <limits.h>
@@ -57,6 +57,7 @@
#include "output.h"
#include "options.h"
#include "var.h"
+#include "show.h"
#if ARITH_BOR + ARITH_ASS_GAP != ARITH_BORASS || \
ARITH_ASS + ARITH_ASS_GAP != ARITH_EQ
@@ -139,6 +140,7 @@
do_binop(int op, intmax_t a, intmax_t b)
{
+ VTRACE(DBG_ARITH, ("Arith do binop %d (%jd, %jd)\n", op, a, b));
switch (op) {
default:
arith_err("token error");
@@ -187,6 +189,9 @@
{
intmax_t result;
+ VTRACE(DBG_ARITH, ("Arith primary: token %d op %d%s\n",
+ token, op, noeval ? " noeval" : ""));
+
switch (token) {
case ARITH_LPAREN:
result = assignment(op, noeval);
@@ -226,6 +231,9 @@
int op2;
int token;
+ VTRACE(DBG_ARITH, ("Arith: binop2 %jd op %d (P:%d)%s\n",
+ a, op, precedence, noeval ? " noeval" : ""));
+
for (;;) {
token = arith_token();
val = a_t_val;
@@ -271,6 +279,8 @@
if (op != ARITH_AND)
return a;
+ VTRACE(DBG_ARITH, ("Arith: AND %jd%s\n", a, noeval ? " noeval" : ""));
+
token = arith_token();
*val = a_t_val;
@@ -289,6 +299,8 @@
if (op != ARITH_OR)
return a;
+ VTRACE(DBG_ARITH, ("Arith: OR %jd%s\n", a, noeval ? " noeval" : ""));
+
token = arith_token();
*val = a_t_val;
@@ -307,6 +319,8 @@
if (last_token != ARITH_QMARK)
return a;
+ VTRACE(DBG_ARITH, ("Arith: ?: %jd%s\n", a, noeval ? " noeval" : ""));
+
b = assignment(arith_token(), noeval | !a);
if (last_token != ARITH_COLON)
@@ -335,6 +349,9 @@
if (op != ARITH_ASS && (op < ARITH_ASS_MIN || op >= ARITH_ASS_MAX))
return cond(var, &val, op, noeval);
+ VTRACE(DBG_ARITH, ("Arith: %s ASSIGN %d%s\n", val.name, op,
+ noeval ? " noeval" : ""));
+
result = assignment(arith_token(), noeval);
if (noeval)
return result;
@@ -355,6 +372,8 @@
setstackmark(&smark);
+ CTRACE(DBG_ARITH, ("Arith(\"%s\")\n", s));
+
arith_buf = arith_startbuf = s;
result = assignment(arith_token(), 0);
@@ -364,6 +383,8 @@
popstackmark(&smark);
+ CTRACE(DBG_ARITH, ("Arith result=%jd\n", result));
+
return result;
}
Home |
Main Index |
Thread Index |
Old Index