diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-10-18 19:22:28 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-10-18 19:22:28 +0300 |
commit | 3d6d06827c2a84b5b3a22de5b546857b3c3991e1 (patch) | |
tree | 26959c55eebe15fc055ab2cf7b8f15369c0863da | |
parent | d100c8c8db2edd4a06a90c238cddf2a224689409 (diff) | |
parent | 51181b9f13fe0b26135a448e2a5f3d4e4d82e151 (diff) | |
download | egawk-3d6d06827c2a84b5b3a22de5b546857b3c3991e1.tar.gz egawk-3d6d06827c2a84b5b3a22de5b546857b3c3991e1.tar.bz2 egawk-3d6d06827c2a84b5b3a22de5b546857b3c3991e1.zip |
Merge branch 'gawk-5.1-stable'
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | awkgram.c | 8 | ||||
-rw-r--r-- | awkgram.y | 8 | ||||
-rw-r--r-- | pc/Makefile.tst | 67 | ||||
-rw-r--r-- | profile.c | 7 | ||||
-rw-r--r-- | symbol.c | 26 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/Makefile.am | 10 | ||||
-rw-r--r-- | test/Makefile.in | 15 | ||||
-rw-r--r-- | test/Maketests | 5 | ||||
-rw-r--r-- | test/profile16.awk | 16 | ||||
-rw-r--r-- | test/profile16.ok | 18 |
12 files changed, 143 insertions, 58 deletions
@@ -1,3 +1,19 @@ +2021-10-18 Arnold D. Robbins <arnold@skeeve.com> + + Factor duplicated code out into a separate function. + D.R.Y. principle. + + * symbol.c (get_name_from_awk_ns): New function. + (lookup): Use it. + (install): Use it. + + * awkgram.y (check_qualified_special): Use awk_namespace instead of a + string constant. + * profile.c (pprint): Ditto. + (adjust_namespace): Ditto. Also, fix the check for the qualified + name to look for the "::" in case one namespace is a prefix of + another. + 2021-10-13 Arnold D. Robbins <arnold@skeeve.com> * README: Update version, copyright year. @@ -9274,8 +9274,8 @@ check_qualified_special(char *token) * Now it's more complicated. Here are the rules. * * 1. Namespace name cannot be a standard awk reserved word or function. - * 2. Subordinate part of the name cannot be standard awk reserved word or function. - * 3. If namespace part is explicitly "awk", return result of check_special(). + * 2. Subordinate part of the name cannot be a standard awk reserved word or function. + * 3. If the namespace part is explicitly "awk", return the result of check_special(). * 4. Else return -1 (gawk extensions allowed, we check standard awk in step 2). */ @@ -9307,12 +9307,12 @@ check_qualified_special(char *token) // Now check the subordinate part i = check_special(subname); - if (i >= 0 && (tokentab[i].flags & GAWKX) == 0 && strcmp(ns, "awk") != 0) { + if (i >= 0 && (tokentab[i].flags & GAWKX) == 0 && strcmp(ns, awk_namespace) != 0) { error_ln(sourceline, _("using reserved identifier `%s' as second component of a qualified name is not allowed"), subname); goto done; } - if (strcmp(ns, "awk") == 0) { + if (strcmp(ns, awk_namespace) == 0) { i = check_special(subname); if (i >= 0) { if ((tokentab[i].flags & GAWKX) != 0 && tokentab[i].class == LEX_BUILTIN) @@ -6766,8 +6766,8 @@ check_qualified_special(char *token) * Now it's more complicated. Here are the rules. * * 1. Namespace name cannot be a standard awk reserved word or function. - * 2. Subordinate part of the name cannot be standard awk reserved word or function. - * 3. If namespace part is explicitly "awk", return result of check_special(). + * 2. Subordinate part of the name cannot be a standard awk reserved word or function. + * 3. If the namespace part is explicitly "awk", return the result of check_special(). * 4. Else return -1 (gawk extensions allowed, we check standard awk in step 2). */ @@ -6799,12 +6799,12 @@ check_qualified_special(char *token) // Now check the subordinate part i = check_special(subname); - if (i >= 0 && (tokentab[i].flags & GAWKX) == 0 && strcmp(ns, "awk") != 0) { + if (i >= 0 && (tokentab[i].flags & GAWKX) == 0 && strcmp(ns, awk_namespace) != 0) { error_ln(sourceline, _("using reserved identifier `%s' as second component of a qualified name is not allowed"), subname); goto done; } - if (strcmp(ns, "awk") == 0) { + if (strcmp(ns, awk_namespace) == 0) { i = check_special(subname); if (i >= 0) { if ((tokentab[i].flags & GAWKX) != 0 && tokentab[i].class == LEX_BUILTIN) diff --git a/pc/Makefile.tst b/pc/Makefile.tst index 5b985250..c4b98e49 100644 --- a/pc/Makefile.tst +++ b/pc/Makefile.tst @@ -206,9 +206,9 @@ GAWK_EXT_TESTS = \ nsindirect2 nsprof1 nsprof2 octdec patsplit posix printfbad1 \ printfbad2 printfbad3 printfbad4 printhuge procinfs profile0 \ profile1 profile10 profile11 profile12 profile13 profile14 \ - profile15 profile2 profile3 profile4 profile5 profile6 profile7 \ - profile8 profile9 pty1 pty2 rebuf regexsub reginttrad regnul1 \ - regnul2 regx8bit reint reint2 rsgetline rsglstdin rsstart1 \ + profile15 profile16 profile2 profile3 profile4 profile5 profile6 \ + profile7 profile8 profile9 pty1 pty2 rebuf regexsub reginttrad \ + regnul1 regnul2 regx8bit reint reint2 rsgetline rsglstdin rsstart1 \ rsstart2 rsstart3 rstest6 sandbox1 shadow shadowbuiltin sortfor \ sortfor2 sortu sourcesplit split_after_fpat splitarg4 strftfld \ strftime strtonum strtonum1 stupid1 stupid2 stupid3 stupid4 \ @@ -268,7 +268,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 + profile14 profile15 profile16 # List of tests that need --re-interval @@ -2735,11 +2735,6 @@ fsfwfs: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -funlen: - @echo $@ - @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ - @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ - functab1: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @@ -2760,6 +2755,11 @@ functab6: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +funlen: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + fwtest: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @@ -2946,14 +2946,14 @@ lintlength: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --lint >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -lintplus: +lintold: @echo $@ - @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --lint >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --lint-old < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -lintold: +lintplus: @echo $@ - @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --lint-old < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --lint >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ lintset: @@ -3118,42 +3118,47 @@ procinfs: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -profile4: +profile10: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -profile8: +profile11: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -profile9: +profile13: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -profile10: +profile14: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -profile11: +profile15: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -profile13: +profile16: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -profile14: +profile4: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -profile15: +profile8: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +profile9: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ @@ -3295,6 +3300,16 @@ symtab1: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +symtab10: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +symtab11: + @echo $@ $(ZOS_FAIL) + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + symtab2: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @@ -3320,16 +3335,6 @@ symtab7: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ -symtab10: - @echo $@ - @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ - @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ - -symtab11: - @echo $@ $(ZOS_FAIL) - @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ - @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ - timeout: @echo $@ $(ZOS_FAIL) @echo Expect $@ to fail with DJGPP and MinGW. @@ -647,7 +647,7 @@ cleanup: { const char *fname; if (pc->opcode == Op_builtin) { - bool prepend_awk = (current_namespace != awk_namespace && strcmp(current_namespace, "awk") != 0); + bool prepend_awk = (current_namespace != awk_namespace && strcmp(current_namespace, awk_namespace) != 0); fname = getfname(pc->builtin, prepend_awk); } else fname = (pc + 1)->func_name; @@ -2098,7 +2098,7 @@ adjust_namespace(char *name, bool *malloced) // unadorned name from symbol table, add awk:: if not in awk:: n.s. if (strchr(name, ':') == NULL && current_namespace != awk_namespace && // can be equal if namespace never changed - strcmp(current_namespace, "awk") != 0 && + strcmp(current_namespace, awk_namespace) != 0 && ! is_all_upper(name)) { char *buf; size_t len = 5 + strlen(name) + 1; @@ -2113,7 +2113,8 @@ adjust_namespace(char *name, bool *malloced) // qualifed name, remove <ns>:: if in that n.s. size_t len = strlen(current_namespace); - if (strncmp(current_namespace, name, len) == 0) { + if (strncmp(current_namespace, name, len) == 0 && + name[len] == ':' && name[len+1] == ':') { char *ret = name + len + 2; return ret; @@ -39,6 +39,7 @@ static void (*install_func)(NODE *) = NULL; static NODE *make_symbol(const char *name, NODETYPE type); static NODE *install(const char *name, NODE *parm, NODETYPE type); static void free_bcpool(INSTRUCTION_POOL *pl); +static NODE *get_name_from_awk_ns(const char *name); static AWK_CONTEXT *curr_ctxt = NULL; static int ctxt_level; @@ -102,10 +103,7 @@ lookup(const char *name) tables[3] = symbol_table; /* then globals */ tables[4] = NULL; - if (strncmp(name, "awk::", 5) == 0) - tmp = make_string(name + 5, strlen(name) - 5); - else - tmp = make_string(name, strlen(name)); + tmp = get_name_from_awk_ns(name); n = NULL; for (i = 0; tables[i] != NULL; i++) { @@ -307,10 +305,7 @@ install(const char *name, NODE *parm, NODETYPE type) NODE *n_name; NODE *prev; - if (strncmp(name, "awk::", 5) == 0) - n_name = make_string(name + 5, strlen(name) - 5); - else - n_name = make_string(name, strlen(name)); + n_name = get_name_from_awk_ns(name); table = symbol_table; @@ -988,3 +983,18 @@ is_all_upper(const char *name) return true; } + +/* get_name_from_awk_ns --- get the name after awk:: or the full name */ + +static NODE * +get_name_from_awk_ns(const char *name) +{ + NODE *tmp; + + if (strncmp(name, "awk::", 5) == 0) + tmp = make_string(name + 5, strlen(name) - 5); + else + tmp = make_string(name, strlen(name)); + + return tmp; +} diff --git a/test/ChangeLog b/test/ChangeLog index c130c7a3..dc4f6da9 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2021-10-18 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (EXTRA_DIST): profile16, new test. + * profile16.awk, profile16.ok: New files. + 2021-10-13 Arnold D. Robbins <arnold@skeeve.com> * Gentest: Add check for ZOS_FAIL targets that have to diff --git a/test/Makefile.am b/test/Makefile.am index e95d097d..7a2289bd 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1011,6 +1011,8 @@ EXTRA_DIST = \ profile14.ok \ profile15.awk \ profile15.ok \ + profile16.awk \ + profile16.ok \ prt1eval.awk \ prt1eval.ok \ prtoeval.awk \ @@ -1455,9 +1457,9 @@ GAWK_EXT_TESTS = \ nsindirect2 nsprof1 nsprof2 octdec patsplit posix printfbad1 \ printfbad2 printfbad3 printfbad4 printhuge procinfs profile0 \ profile1 profile10 profile11 profile12 profile13 profile14 \ - profile15 profile2 profile3 profile4 profile5 profile6 profile7 \ - profile8 profile9 pty1 pty2 rebuf regexsub reginttrad regnul1 \ - regnul2 regx8bit reint reint2 rsgetline rsglstdin rsstart1 \ + profile15 profile16 profile2 profile3 profile4 profile5 profile6 \ + profile7 profile8 profile9 pty1 pty2 rebuf regexsub reginttrad \ + regnul1 regnul2 regx8bit reint reint2 rsgetline rsglstdin rsstart1 \ rsstart2 rsstart3 rstest6 sandbox1 shadow shadowbuiltin sortfor \ sortfor2 sortu sourcesplit split_after_fpat splitarg4 strftfld \ strftime strtonum strtonum1 stupid1 stupid2 stupid3 stupid4 \ @@ -1518,7 +1520,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 + profile14 profile15 profile16 # List of tests that need --re-interval NEED_RE_INTERVAL = gsubtst3 reint reint2 diff --git a/test/Makefile.in b/test/Makefile.in index b950d09d..c37ab80a 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1277,6 +1277,8 @@ EXTRA_DIST = \ profile14.ok \ profile15.awk \ profile15.ok \ + profile16.awk \ + profile16.ok \ prt1eval.awk \ prt1eval.ok \ prtoeval.awk \ @@ -1721,9 +1723,9 @@ GAWK_EXT_TESTS = \ nsindirect2 nsprof1 nsprof2 octdec patsplit posix printfbad1 \ printfbad2 printfbad3 printfbad4 printhuge procinfs profile0 \ profile1 profile10 profile11 profile12 profile13 profile14 \ - profile15 profile2 profile3 profile4 profile5 profile6 profile7 \ - profile8 profile9 pty1 pty2 rebuf regexsub reginttrad regnul1 \ - regnul2 regx8bit reint reint2 rsgetline rsglstdin rsstart1 \ + profile15 profile16 profile2 profile3 profile4 profile5 profile6 \ + profile7 profile8 profile9 pty1 pty2 rebuf regexsub reginttrad \ + regnul1 regnul2 regx8bit reint reint2 rsgetline rsglstdin rsstart1 \ rsstart2 rsstart3 rstest6 sandbox1 shadow shadowbuiltin sortfor \ sortfor2 sortu sourcesplit split_after_fpat splitarg4 strftfld \ strftime strtonum strtonum1 stupid1 stupid2 stupid3 stupid4 \ @@ -1783,7 +1785,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 + profile14 profile15 profile16 # List of tests that need --re-interval @@ -4817,6 +4819,11 @@ profile15: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +profile16: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + profile4: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index ec749212..0c5d74f9 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1881,6 +1881,11 @@ profile15: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +profile16: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + profile4: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/profile16.awk b/test/profile16.awk new file mode 100644 index 00000000..e0c9c42b --- /dev/null +++ b/test/profile16.awk @@ -0,0 +1,16 @@ +BEGIN { + foo::foo_bar() + foofoo::xxx() +} + +@namespace "foo" + +function foo_bar() +{ + print "foo::foo_bar" +} + +function foofoo::xxx() +{ + print "foofoo::xxx" +} diff --git a/test/profile16.ok b/test/profile16.ok new file mode 100644 index 00000000..b954b1c5 --- /dev/null +++ b/test/profile16.ok @@ -0,0 +1,18 @@ +BEGIN { + foo::foo_bar() + foofoo::xxx() +} + + +@namespace "foo" + + +function foo_bar() +{ + print "foo::foo_bar" +} + +function foofoo::xxx() +{ + print "foofoo::xxx" +} |