aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--awkgram.c11
-rw-r--r--awkgram.y11
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am11
-rw-r--r--test/Makefile.in11
-rw-r--r--test/profile8.awk4
-rw-r--r--test/profile8.ok23
8 files changed, 70 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 3913097e..d7aaa6e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-12-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awkgram.y (mk_condition): Revise to correctly handle
+ empty else part for pretty printing. Bug report by
+ ziyunfei <446240525@qq.com>.
+
2015-12-16 Arnold D. Robbins <arnold@skeeve.com>
* io.c (two_way_open): Remove unneeded close of slave in the
diff --git a/awkgram.c b/awkgram.c
index 8e408cac..bc91d406 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -7223,14 +7223,12 @@ mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
*/
INSTRUCTION *ip;
+ bool setup_else_part = true;
if (false_branch == NULL) {
false_branch = list_create(instruction(Op_no_op));
- if (elsep != NULL) { /* else { } */
- if (do_pretty_print)
- (void) list_prepend(false_branch, elsep);
- else
- bcfree(elsep);
+ if (elsep == NULL) { /* else { } */
+ setup_else_part = false;
}
} else {
/* assert(elsep != NULL); */
@@ -7238,6 +7236,9 @@ mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
/* avoid a series of no_op's: if .. else if .. else if .. */
if (false_branch->lasti->opcode != Op_no_op)
(void) list_append(false_branch, instruction(Op_no_op));
+ }
+
+ if (setup_else_part) {
if (do_pretty_print) {
(void) list_prepend(false_branch, elsep);
false_branch->nexti->branch_end = false_branch->lasti;
diff --git a/awkgram.y b/awkgram.y
index 2592d13a..facf3090 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -4884,14 +4884,12 @@ mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
*/
INSTRUCTION *ip;
+ bool setup_else_part = true;
if (false_branch == NULL) {
false_branch = list_create(instruction(Op_no_op));
- if (elsep != NULL) { /* else { } */
- if (do_pretty_print)
- (void) list_prepend(false_branch, elsep);
- else
- bcfree(elsep);
+ if (elsep == NULL) { /* else { } */
+ setup_else_part = false;
}
} else {
/* assert(elsep != NULL); */
@@ -4899,6 +4897,9 @@ mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
/* avoid a series of no_op's: if .. else if .. else if .. */
if (false_branch->lasti->opcode != Op_no_op)
(void) list_append(false_branch, instruction(Op_no_op));
+ }
+
+ if (setup_else_part) {
if (do_pretty_print) {
(void) list_prepend(false_branch, elsep);
false_branch->nexti->branch_end = false_branch->lasti;
diff --git a/test/ChangeLog b/test/ChangeLog
index cc709b5c..6bed9696 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (profile8): New test.
+ * profile8.awk, profile8.ok: New files.
+
2015-11-24 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (watchpoint1): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index 779a1063..01c15233 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -750,6 +750,8 @@ EXTRA_DIST = \
profile6.ok \
profile7.awk \
profile7.ok \
+ profile8.awk \
+ profile8.ok \
prt1eval.awk \
prt1eval.ok \
prtoeval.awk \
@@ -1083,7 +1085,8 @@ GAWK_EXT_TESTS = \
muldimposix \
nastyparm negtime next nondec nondec2 \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge procinfs \
- profile0 profile1 profile2 profile3 profile4 profile5 profile6 profile7 pty1 \
+ profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
+ profile7 profile8 pty1 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \
splitarg4 strftime \
@@ -1801,6 +1804,12 @@ profile7:
@sed 1,2d < ap-$@.out > _$@; rm ap-$@.out
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+profile8:
+ @echo $@
+ @$(AWK) --pretty=ap-$@.out -f "$(srcdir)"/$@.awk < /dev/null
+ @sed 1,2d < ap-$@.out > _$@; rm ap-$@.out
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
posix2008sub:
@echo $@
@$(AWK) --posix -f "$(srcdir)"/$@.awk > _$@ 2>&1
diff --git a/test/Makefile.in b/test/Makefile.in
index eb7748ab..a89fc862 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1007,6 +1007,8 @@ EXTRA_DIST = \
profile6.ok \
profile7.awk \
profile7.ok \
+ profile8.awk \
+ profile8.ok \
prt1eval.awk \
prt1eval.ok \
prtoeval.awk \
@@ -1339,7 +1341,8 @@ GAWK_EXT_TESTS = \
muldimposix \
nastyparm negtime next nondec nondec2 \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge procinfs \
- profile0 profile1 profile2 profile3 profile4 profile5 profile6 profile7 pty1 \
+ profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
+ profile7 profile8 pty1 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \
splitarg4 strftime \
@@ -2240,6 +2243,12 @@ profile7:
@sed 1,2d < ap-$@.out > _$@; rm ap-$@.out
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+profile8:
+ @echo $@
+ @$(AWK) --pretty=ap-$@.out -f "$(srcdir)"/$@.awk < /dev/null
+ @sed 1,2d < ap-$@.out > _$@; rm ap-$@.out
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
posix2008sub:
@echo $@
@$(AWK) --posix -f "$(srcdir)"/$@.awk > _$@ 2>&1
diff --git a/test/profile8.awk b/test/profile8.awk
new file mode 100644
index 00000000..68d0622e
--- /dev/null
+++ b/test/profile8.awk
@@ -0,0 +1,4 @@
+{if(0){}else{}}
+{while(0){}}
+{do{}while(0)}
+{for(;;){}}
diff --git a/test/profile8.ok b/test/profile8.ok
new file mode 100644
index 00000000..763c6fef
--- /dev/null
+++ b/test/profile8.ok
@@ -0,0 +1,23 @@
+ # Rule(s)
+
+ {
+ if (0) {
+ } else {
+ }
+ }
+
+ {
+ while (0) {
+ }
+ }
+
+ {
+ do {
+ } while (0)
+ }
+
+ {
+ for (;;) {
+ }
+ }
+