aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--profile.c26
-rw-r--r--test/ChangeLog6
-rw-r--r--test/Makefile.am12
-rw-r--r--test/Makefile.in12
-rw-r--r--test/profile7.awk12
-rw-r--r--test/profile7.ok15
7 files changed, 82 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index a74dadd9..dd3a494a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-11-02 Arnold D. Robbins <arnold@skeeve.com>
+
+ * profile.c (div_on_left_mul_on_right): New function.
+ (parenthesize): Call it.
+
2014-10-30 Arnold D. Robbins <arnold@skeeve.com>
* configure: Regenerated after fix to m4/readline.m4.
diff --git a/profile.c b/profile.c
index ed17e62b..316ba393 100644
--- a/profile.c
+++ b/profile.c
@@ -1180,6 +1180,26 @@ pp_parenthesize(NODE *sp)
sp->flags |= CAN_FREE;
}
+/* div_on_left_mul_on_right --- have / or % on left and * on right */
+
+static bool
+div_on_left_mul_on_right(int o1, int o2)
+{
+ OPCODE op1 = (OPCODE) o1;
+ OPCODE op2 = (OPCODE) o2;
+
+ switch (op1) {
+ case Op_quotient:
+ case Op_quotient_i:
+ case Op_mod:
+ case Op_mod_i:
+ return (op2 == Op_times || op2 == Op_times_i);
+
+ default:
+ return false;
+ }
+}
+
/* parenthesize --- parenthesize two nodes relative to parent node type */
static void
@@ -1189,9 +1209,11 @@ parenthesize(int type, NODE *left, NODE *right)
int lprec = prec_level(left->type);
int prec = prec_level(type);
- if (lprec < prec)
+ if (lprec < prec
+ || (lprec == prec && div_on_left_mul_on_right(left->type, type)))
pp_parenthesize(left);
- if (rprec < prec)
+ if (rprec < prec
+ || (rprec == prec && div_on_left_mul_on_right(type, right->type)))
pp_parenthesize(right);
}
diff --git a/test/ChangeLog b/test/ChangeLog
index 7899db9b..ab6c9431 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-02 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (profile7): New test.
+ (profile6): Add missing @ in front of gawk run.
+ * profile7.awk, profile7.ok: New files.
+
2014-11-01 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (profile6): Actually run profiling. Should make test
diff --git a/test/Makefile.am b/test/Makefile.am
index fe8806a1..f8db2833 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -708,6 +708,8 @@ EXTRA_DIST = \
profile5.ok \
profile6.awk \
profile6.ok \
+ profile7.awk \
+ profile7.ok \
prt1eval.awk \
prt1eval.ok \
prtoeval.awk \
@@ -1019,7 +1021,7 @@ GAWK_EXT_TESTS = \
manyfiles match1 match2 match3 mbstr1 \
nastyparm next nondec nondec2 \
patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \
- profile1 profile2 profile3 profile4 profile5 profile6 pty1 \
+ profile1 profile2 profile3 profile4 profile5 profile6 profile7 pty1 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \
splitarg4 strftime \
@@ -1703,7 +1705,13 @@ profile5:
profile6:
@echo $@
- $(AWK) --profile=ap-$@.out -f "$(srcdir)"/$@.awk > /dev/null
+ @$(AWK) --profile=ap-$@.out -f "$(srcdir)"/$@.awk > /dev/null
+ @sed 1,2d < ap-$@.out > _$@; rm ap-$@.out
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+profile7:
+ @echo $@
+ @$(AWK) --profile=ap-$@.out -f "$(srcdir)"/$@.awk > /dev/null
@sed 1,2d < ap-$@.out > _$@; rm ap-$@.out
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
diff --git a/test/Makefile.in b/test/Makefile.in
index 48e9d9bf..a337288b 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -954,6 +954,8 @@ EXTRA_DIST = \
profile5.ok \
profile6.awk \
profile6.ok \
+ profile7.awk \
+ profile7.ok \
prt1eval.awk \
prt1eval.ok \
prtoeval.awk \
@@ -1264,7 +1266,7 @@ GAWK_EXT_TESTS = \
manyfiles match1 match2 match3 mbstr1 \
nastyparm next nondec nondec2 \
patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \
- profile1 profile2 profile3 profile4 profile5 profile6 pty1 \
+ profile1 profile2 profile3 profile4 profile5 profile6 profile7 pty1 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \
splitarg4 strftime \
@@ -2127,7 +2129,13 @@ profile5:
profile6:
@echo $@
- $(AWK) --profile=ap-$@.out -f "$(srcdir)"/$@.awk > /dev/null
+ @$(AWK) --profile=ap-$@.out -f "$(srcdir)"/$@.awk > /dev/null
+ @sed 1,2d < ap-$@.out > _$@; rm ap-$@.out
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+profile7:
+ @echo $@
+ @$(AWK) --profile=ap-$@.out -f "$(srcdir)"/$@.awk > /dev/null
@sed 1,2d < ap-$@.out > _$@; rm ap-$@.out
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
diff --git a/test/profile7.awk b/test/profile7.awk
new file mode 100644
index 00000000..454694f9
--- /dev/null
+++ b/test/profile7.awk
@@ -0,0 +1,12 @@
+BEGIN {
+ print 1 / 10 * 10
+ print 1 / (10 * 10)
+ print 1 % 10 * 10
+ print 1 % (10 * 10)
+ print (10 * 5) / 2
+ print 10 * (5 / 2)
+ a = 5
+ b = 3
+ print a - 1 - b
+ print a + 1 - b
+}
diff --git a/test/profile7.ok b/test/profile7.ok
new file mode 100644
index 00000000..d65afa86
--- /dev/null
+++ b/test/profile7.ok
@@ -0,0 +1,15 @@
+ # BEGIN rule(s)
+
+ BEGIN {
+ 1 print 1 / 10 * 10
+ 1 print 1 / (10 * 10)
+ 1 print 1 % 10 * 10
+ 1 print 1 % (10 * 10)
+ 1 print 10 * 5 / 2
+ 1 print 10 * 5 / 2
+ 1 a = 5
+ 1 b = 3
+ 1 print a - 1 - b
+ 1 print a + 1 - b
+ }
+