summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2022-04-21 17:26:21 +0300
committerArnold D. Robbins <arnold@skeeve.com>2022-04-21 17:26:21 +0300
commit6cf92b53d37c1f9e3029cb1c8c0217100c7e36d8 (patch)
treedb9fc3d394519563ce81129911088aeef9992e55
parent2b4d1c796f24d1fc2fb09bd1570f859caabda419 (diff)
downloadgawk-6cf92b53d37c1f9e3029cb1c8c0217100c7e36d8.tar.gz
Pretty printing improvements for comments in switch/case.
-rw-r--r--ChangeLog9
-rw-r--r--awkgram.c2
-rw-r--r--awkgram.y1
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile.tst8
-rw-r--r--profile.c10
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am5
-rw-r--r--test/Makefile.in10
-rw-r--r--test/Maketests5
-rw-r--r--test/profile10.ok3
-rw-r--r--test/profile11.ok13
-rwxr-xr-xtest/profile17.awk18
-rw-r--r--test/profile17.ok19
-rw-r--r--test/profile5.ok18
15 files changed, 97 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index 971251ec..13f462a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-04-21 Arnold D. Robbins <arnold@skeeve.com>
+
+ Fix some profiling issues related to comments in switch / case
+ statements.
+
+ * awkgram.y (merge_comments): Remove newline between comments being
+ merged.
+ * profile.c (pprint): Improve code for Op_K_switch, Op_K_case.
+
2022-04-01 Arnold D. Robbins <arnold@skeeve.com>
Small fix from the persistent-gawk guys.
diff --git a/awkgram.c b/awkgram.c
index 2ada68d1..8daf506a 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -9183,7 +9183,7 @@ merge_comments(INSTRUCTION *c1, INSTRUCTION *c2)
}
if (c2 != NULL) {
- strcat(buffer, "\n");
+ // strcat(buffer, "\n");
strcat(buffer, c2->memory->stptr);
if (c2->comment != NULL) {
strcat(buffer, "\n");
diff --git a/awkgram.y b/awkgram.y
index b75cc2e4..2371d0b4 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -6675,7 +6675,6 @@ merge_comments(INSTRUCTION *c1, INSTRUCTION *c2)
}
if (c2 != NULL) {
- strcat(buffer, "\n");
strcat(buffer, c2->memory->stptr);
if (c2->comment != NULL) {
strcat(buffer, "\n");
diff --git a/pc/ChangeLog b/pc/ChangeLog
index 3602be5b..132b6e1c 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2022-04-21 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Regenerated.
+
2022-03-27 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.tst: Regenerated.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index cb949286..2ea1822c 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -209,6 +209,7 @@ GAWK_EXT_TESTS = \
profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
profile7 profile8 profile9 profile10 profile11 profile12 profile13 \
profile14 profile15 profile16 pty1 pty2 rebuf regexsub regnul1 regnul2 \
+ profile17 \
regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 sandbox1 shadow shadowbuiltin sortfor \
sortfor2 sortu sourcesplit split_after_fpat splitarg4 strftfld \
@@ -269,7 +270,7 @@ NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2 muldimpo
# List of tests that need --pretty-print
NEED_PRETTY = nsprof1 nsprof2 \
profile4 profile5 profile8 profile9 profile10 profile11 profile13 \
- profile14 profile15 profile16
+ profile14 profile15 profile16 profile17
# List of tests that need --re-interval
@@ -3196,6 +3197,11 @@ regnul2:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+profile17:
+ @echo $@
+ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regx8bit:
@echo $@
@echo Expect $@ to fail with DJGPP.
diff --git a/profile.c b/profile.c
index 15b33721..66932db6 100644
--- a/profile.c
+++ b/profile.c
@@ -998,9 +998,11 @@ cleanup:
fprintf(prof_fp, "%s (", op2str(pc->opcode));
pprint(pc->nexti, ip1->switch_start, NO_PPRINT_FLAGS);
t1 = pp_pop();
- fprintf(prof_fp, "%s) {\n", t1->pp_str);
+ fprintf(prof_fp, "%s) {", t1->pp_str);
if (pc->comment)
print_comment(pc->comment, 0);
+ else
+ fprintf(prof_fp, "\n");
pp_free(t1);
pprint(ip1->switch_start, ip1->switch_end, NO_PPRINT_FLAGS);
indent(SPACEOVER);
@@ -1022,9 +1024,11 @@ cleanup:
indent_in();
if (pc->comment != NULL) {
- if (pc->comment->memory->comment_type == EOL_COMMENT)
+ if (pc->comment->memory->comment_type == EOL_COMMENT) {
fprintf(prof_fp, "\t%s", pc->comment->memory->stptr);
- else {
+ if (pc->comment->comment != NULL)
+ print_comment(pc->comment->comment, indent_level);
+ } else {
fprintf(prof_fp, "\n");
print_comment(pc->comment, indent_level);
}
diff --git a/test/ChangeLog b/test/ChangeLog
index fa9f9951..4edcbf69 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2022-04-21 Arnold D. Robbins <arnold@skeeve.com>
+
+ * profile5.ok, profile10.ok, profile11.ok: Updated after code changes.
+ * profile17.awk, profile17.ok: New files.
+
2022-03-30 Arnold D. Robbins <arnold@skeeve.com>
* delarprm2.awk, delarprm2.ok: Changes to make test more helpful.
diff --git a/test/Makefile.am b/test/Makefile.am
index 0f79b8ca..04394b3c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1019,6 +1019,8 @@ EXTRA_DIST = \
profile15.ok \
profile16.awk \
profile16.ok \
+ profile17.awk \
+ profile17.ok \
prt1eval.awk \
prt1eval.ok \
prtoeval.awk \
@@ -1468,6 +1470,7 @@ GAWK_EXT_TESTS = \
profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
profile7 profile8 profile9 profile10 profile11 profile12 profile13 \
profile14 profile15 profile16 pty1 pty2 rebuf regexsub regnul1 regnul2 \
+ profile17 \
regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 sandbox1 shadow shadowbuiltin sortfor \
sortfor2 sortu sourcesplit split_after_fpat splitarg4 strftfld \
@@ -1529,7 +1532,7 @@ NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2 muldimpo
# List of tests that need --pretty-print
NEED_PRETTY = nsprof1 nsprof2 \
profile4 profile5 profile8 profile9 profile10 profile11 profile13 \
- profile14 profile15 profile16
+ profile14 profile15 profile16 profile17
# List of tests that need --re-interval
NEED_RE_INTERVAL = gsubtst3 reint reint2
diff --git a/test/Makefile.in b/test/Makefile.in
index 174d329d..7e39f325 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1285,6 +1285,8 @@ EXTRA_DIST = \
profile15.ok \
profile16.awk \
profile16.ok \
+ profile17.awk \
+ profile17.ok \
prt1eval.awk \
prt1eval.ok \
prtoeval.awk \
@@ -1734,6 +1736,7 @@ GAWK_EXT_TESTS = \
profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
profile7 profile8 profile9 profile10 profile11 profile12 profile13 \
profile14 profile15 profile16 pty1 pty2 rebuf regexsub regnul1 regnul2 \
+ profile17 \
regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 sandbox1 shadow shadowbuiltin sortfor \
sortfor2 sortu sourcesplit split_after_fpat splitarg4 strftfld \
@@ -1794,7 +1797,7 @@ NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2 muldimpo
# List of tests that need --pretty-print
NEED_PRETTY = nsprof1 nsprof2 \
profile4 profile5 profile8 profile9 profile10 profile11 profile13 \
- profile14 profile15 profile16
+ profile14 profile15 profile16 profile17
# List of tests that need --re-interval
@@ -4880,6 +4883,11 @@ regnul2:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+profile17:
+ @echo $@
+ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regx8bit:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index d206f2e4..efc168b5 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1926,6 +1926,11 @@ regnul2:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+profile17:
+ @echo $@
+ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regx8bit:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/profile10.ok b/test/profile10.ok
index 0f77bd38..09b6d238 100644
--- a/test/profile10.ok
+++ b/test/profile10.ok
@@ -16,8 +16,7 @@ BEGIN { # Comment 0
for (z = 1; z <= 10; z++) { # Comment 15
print "MNO" # Comment 16
} # Comment 17
- switch (q) {
- # Comment 18
+ switch (q) { # Comment 18
case "a": # Comment 19
case "b":
# Comment 20
diff --git a/test/profile11.ok b/test/profile11.ok
index be027371..be6ed526 100644
--- a/test/profile11.ok
+++ b/test/profile11.ok
@@ -150,11 +150,9 @@ BEGIN {
# comments/switch.awk
BEGIN {
a = 5
- switch (a) {
- # switch EOL comment
+ switch (a) { # switch EOL comment
# switch block comment
-
# lbrace EOL comment
# lbrace block comment
@@ -173,11 +171,9 @@ BEGIN {
# comments2/switch.awk
BEGIN {
a = 5
- switch (a) {
- # switch EOL comment
+ switch (a) { # switch EOL comment
# switch block comment
-
# lbrace EOL comment
# lbrace block comment
@@ -316,9 +312,7 @@ function bar(p1, p2)
# rbrace block bar
# comments2/function.awk
-
# comment
-
# comment before braces
function baz(p1, p2)
{
@@ -345,11 +339,8 @@ function callme(a, b, c)
# rbrace block baz
# comments/function.awk
-
# param comment 1
-
# param comment 2
-
# Comment between header and body
function funny(param1, param2, param3, param4)
{
diff --git a/test/profile17.awk b/test/profile17.awk
new file mode 100755
index 00000000..51da6627
--- /dev/null
+++ b/test/profile17.awk
@@ -0,0 +1,18 @@
+BEGIN {
+ switch (q) { # Comment 1
+ case "a": # Comment 2
+ # comment 3
+ a++
+ case "b":
+ # Comment 4
+ break # Comment 5
+ default: # Comment 6
+ break # Comment 7
+ } # Comment 8
+
+ switch (b) # Comment A
+ { # Comment B
+ case "a":
+ break;
+ }
+}
diff --git a/test/profile17.ok b/test/profile17.ok
new file mode 100644
index 00000000..5340b251
--- /dev/null
+++ b/test/profile17.ok
@@ -0,0 +1,19 @@
+BEGIN {
+ switch (q) { # Comment 1
+ case "a": # Comment 2
+ # comment 3
+ a++
+ case "b":
+ # Comment 4
+ break # Comment 5
+ default: # Comment 6
+ break # Comment 7
+ }
+ # Comment 8
+ switch (b) { # Comment A
+ # Comment B
+ case "a":
+ break
+ }
+}
+
diff --git a/test/profile5.ok b/test/profile5.ok
index ca25230a..a6aeb46f 100644
--- a/test/profile5.ok
+++ b/test/profile5.ok
@@ -759,8 +759,7 @@ function _BASE(c, t, P, A)
function _DS(c, t, P, a, A)
{
######################################################
- switch (c) {
- #___________________________________________________________
+ switch (c) { #___________________________________________________________
case "_lib_CMDLN":
return t
#_____________________________________________________
@@ -930,8 +929,7 @@ function _FILEIO(c, t, P, A)
function _FILEVER(c, t, P, a, A)
{
#################################################
- switch (c) {
- #___________________________________________________________
+ switch (c) { #___________________________________________________________
case "_lib_CMDLN":
return t
#_____________________________________________________
@@ -4218,8 +4216,7 @@ function _qstrq(t)
function _rEG(c, t, P, a, A)
{
#####################################################
- switch (c) {
- #___________________________________________________________
+ switch (c) { #___________________________________________________________
case "_lib_CMDLN":
return t
#_____________________________________________________
@@ -4940,8 +4937,7 @@ function _rxpfn(R, t, p, i, f, A)
function _sHARE(c, t, P, a, A)
{
###################################################
- switch (c) {
- #___________________________________________________________
+ switch (c) { #___________________________________________________________
case "_lib_CMDLN":
return t
#_____________________________________________________
@@ -4968,8 +4964,7 @@ function _sHARE(c, t, P, a, A)
function _sYS(c, t, P, a, A)
{
#####################################################
- switch (c) {
- #___________________________________________________________
+ switch (c) { #___________________________________________________________
case "_lib_CMDLN":
return t
#_____________________________________________________
@@ -5460,8 +5455,7 @@ function _sysinfo(D, h)
#########################################################
function _tOBJ(c, t, P)
{
- switch (c) {
- #___________________________________________________________
+ switch (c) { #___________________________________________________________
case "_lib_CMDLN":
return t
#___________________________________________________________