gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, easter-eggs/detect-local, created. gawk-


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, easter-eggs/detect-local, created. gawk-4.1.0-2439-g9ed206b
Date: Thu, 23 Feb 2017 13:05:46 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, easter-eggs/detect-local has been created
        at  9ed206b61dc20af209ceca5b26c536bdb7b2edad (commit)

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=9ed206b61dc20af209ceca5b26c536bdb7b2edad

commit 9ed206b61dc20af209ceca5b26c536bdb7b2edad
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Feb 23 20:04:49 2017 +0200

    Make it possible to distinguish truly local parameters via an extension.

diff --git a/ChangeLog b/ChangeLog
index 8b87746..89c0893 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-02-23         Arnold D. Robbins     <address@hidden>
 
+       * awk.h (LOCAL): New flag, for local variables in functions.
+       * eval.c (flags2str): Add entry for LOCAL.
+       (setup_frame): Set the flag for local variables.
+       * gawkapi.h (awk_value_t): Add new member is_local indicating
+       value came from a local variable in a function.
+       * gawkapi.c (api_get_argument): Set result->is_local based
+       on the LOCAL flag.
+
+2017-02-23         Arnold D. Robbins     <address@hidden>
+
        * awk.h (boolval): Return bool instead of int.
        * eval.c (eval_condition): Same.
        * io.c (pty_vs_pipe): Same
diff --git a/awk.h b/awk.h
index aae5e7e..23b5848 100644
--- a/awk.h
+++ b/awk.h
@@ -460,6 +460,7 @@ typedef struct exp_node {
 #              define  XARRAY          0x10000
 #              define  NUMCONSTSTR     0x20000 /* have string value for 
numeric constant */
 #              define  REGEX           0x40000 /* this is a typed regex */
+#              define  LOCAL           0x80000 /* this is a truly a local var 
*/
 } NODE;
 
 #define vname sub.nodep.name
diff --git a/eval.c b/eval.c
index 73bd7fc..ba554f7 100644
--- a/eval.c
+++ b/eval.c
@@ -450,6 +450,7 @@ flags2str(int flagval)
                { XARRAY, "XARRAY" },
                { NUMCONSTSTR, "NUMCONSTSTR" },
                { REGEX, "REGEX" },
+               { LOCAL, "LOCAL" },
                { 0,    NULL },
        };
 
@@ -1299,6 +1300,7 @@ setup_frame(INSTRUCTION *pc)
                        /* local variable */
                        r->type = Node_var_new;
                        r->vname = fp[i].param;
+                       r->flags |= LOCAL;
                        continue;
                }
 
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 89be82d..4db7bab 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-23         Arnold D. Robbins     <address@hidden>
+
+       * islocal.c: New file.
+       * Makefile.am: Add support for new `islocal' extension.
+
 2017-01-21  Eli Zaretskii  <address@hidden>
 
        * testext.c (getuid) [__MINGW32__]: New function, mirrors what
diff --git a/extension/Makefile.am b/extension/Makefile.am
index 59c5cb8..52d02bb 100644
--- a/extension/Makefile.am
+++ b/extension/Makefile.am
@@ -1,7 +1,7 @@
 #
 # extension/Makefile.am --- automake input file for gawk
 #
-# Copyright (C) 1995-2006, 2012-2015 the Free Software Foundation, Inc.
+# Copyright (C) 1995-2006, 2012-2017 the Free Software Foundation, Inc.
 #
 # This file is part of GAWK, the GNU implementation of the
 # AWK Programming Language.
@@ -39,6 +39,7 @@ pkgextension_LTLIBRARIES =    \
        fnmatch.la      \
        fork.la         \
        inplace.la      \
+       islocal.la      \
        ordchr.la       \
        readdir.la      \
        readfile.la     \
@@ -69,6 +70,10 @@ inplace_la_SOURCES    = inplace.c
 inplace_la_LDFLAGS    = $(MY_MODULE_FLAGS)
 inplace_la_LIBADD     = $(MY_LIBS)
 
+islocal_la_SOURCES    = islocal.c
+islocal_la_LDFLAGS    = $(MY_MODULE_FLAGS)
+islocal_la_LIBADD     = $(MY_LIBS)
+
 ordchr_la_SOURCES     = ordchr.c
 ordchr_la_LDFLAGS     = $(MY_MODULE_FLAGS)
 ordchr_la_LIBADD      = $(MY_LIBS)
diff --git a/extension/Makefile.in b/extension/Makefile.in
index 23bb5cf..25e2617 100644
--- a/extension/Makefile.in
+++ b/extension/Makefile.in
@@ -17,7 +17,7 @@
 #
 # extension/Makefile.am --- automake input file for gawk
 #
-# Copyright (C) 1995-2006, 2012-2015 the Free Software Foundation, Inc.
+# Copyright (C) 1995-2006, 2012-2017 the Free Software Foundation, Inc.
 #
 # This file is part of GAWK, the GNU implementation of the
 # AWK Programming Language.
@@ -187,6 +187,12 @@ inplace_la_OBJECTS = $(am_inplace_la_OBJECTS)
 inplace_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(inplace_la_LDFLAGS) $(LDFLAGS) -o $@
+islocal_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
+am_islocal_la_OBJECTS = islocal.lo
+islocal_la_OBJECTS = $(am_islocal_la_OBJECTS)
+islocal_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(islocal_la_LDFLAGS) $(LDFLAGS) -o $@
 ordchr_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
 am_ordchr_la_OBJECTS = ordchr.lo
 ordchr_la_OBJECTS = $(am_ordchr_la_OBJECTS)
@@ -270,15 +276,17 @@ am__v_CCLD_ = $(address@hidden@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
 SOURCES = $(filefuncs_la_SOURCES) $(fnmatch_la_SOURCES) \
-       $(fork_la_SOURCES) $(inplace_la_SOURCES) $(ordchr_la_SOURCES) \
-       $(readdir_la_SOURCES) $(readfile_la_SOURCES) \
-       $(revoutput_la_SOURCES) $(revtwoway_la_SOURCES) \
-       $(rwarray_la_SOURCES) $(testext_la_SOURCES) $(time_la_SOURCES)
+       $(fork_la_SOURCES) $(inplace_la_SOURCES) $(islocal_la_SOURCES) \
+       $(ordchr_la_SOURCES) $(readdir_la_SOURCES) \
+       $(readfile_la_SOURCES) $(revoutput_la_SOURCES) \
+       $(revtwoway_la_SOURCES) $(rwarray_la_SOURCES) \
+       $(testext_la_SOURCES) $(time_la_SOURCES)
 DIST_SOURCES = $(filefuncs_la_SOURCES) $(fnmatch_la_SOURCES) \
-       $(fork_la_SOURCES) $(inplace_la_SOURCES) $(ordchr_la_SOURCES) \
-       $(readdir_la_SOURCES) $(readfile_la_SOURCES) \
-       $(revoutput_la_SOURCES) $(revtwoway_la_SOURCES) \
-       $(rwarray_la_SOURCES) $(testext_la_SOURCES) $(time_la_SOURCES)
+       $(fork_la_SOURCES) $(inplace_la_SOURCES) $(islocal_la_SOURCES) \
+       $(ordchr_la_SOURCES) $(readdir_la_SOURCES) \
+       $(readfile_la_SOURCES) $(revoutput_la_SOURCES) \
+       $(revtwoway_la_SOURCES) $(rwarray_la_SOURCES) \
+       $(testext_la_SOURCES) $(time_la_SOURCES)
 RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
        ctags-recursive dvi-recursive html-recursive info-recursive \
        install-data-recursive install-dvi-recursive \
@@ -511,6 +519,7 @@ pkgextension_LTLIBRARIES = \
        fnmatch.la      \
        fork.la         \
        inplace.la      \
+       islocal.la      \
        ordchr.la       \
        readdir.la      \
        readfile.la     \
@@ -537,6 +546,9 @@ fork_la_LIBADD = $(MY_LIBS)
 inplace_la_SOURCES = inplace.c
 inplace_la_LDFLAGS = $(MY_MODULE_FLAGS)
 inplace_la_LIBADD = $(MY_LIBS)
+islocal_la_SOURCES = islocal.c
+islocal_la_LDFLAGS = $(MY_MODULE_FLAGS)
+islocal_la_LIBADD = $(MY_LIBS)
 ordchr_la_SOURCES = ordchr.c
 ordchr_la_LDFLAGS = $(MY_MODULE_FLAGS)
 ordchr_la_LIBADD = $(MY_LIBS)
@@ -679,6 +691,9 @@ fork.la: $(fork_la_OBJECTS) $(fork_la_DEPENDENCIES) 
$(EXTRA_fork_la_DEPENDENCIES
 inplace.la: $(inplace_la_OBJECTS) $(inplace_la_DEPENDENCIES) 
$(EXTRA_inplace_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(inplace_la_LINK) -rpath $(pkgextensiondir) 
$(inplace_la_OBJECTS) $(inplace_la_LIBADD) $(LIBS)
 
+islocal.la: $(islocal_la_OBJECTS) $(islocal_la_DEPENDENCIES) 
$(EXTRA_islocal_la_DEPENDENCIES) 
+       $(AM_V_CCLD)$(islocal_la_LINK) -rpath $(pkgextensiondir) 
$(islocal_la_OBJECTS) $(islocal_la_LIBADD) $(LIBS)
+
 ordchr.la: $(ordchr_la_OBJECTS) $(ordchr_la_DEPENDENCIES) 
$(EXTRA_ordchr_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(ordchr_la_LINK) -rpath $(pkgextensiondir) 
$(ordchr_la_OBJECTS) $(ordchr_la_LIBADD) $(LIBS)
 
@@ -714,6 +729,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
address@hidden@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
diff --git a/gawkapi.c b/gawkapi.c
index 4c6a2f8..2153a37 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -67,6 +67,9 @@ api_get_argument(awk_ext_id_t id, size_t count,
        if (arg == NULL)
                return awk_false;
 
+       // check if this was a truly local variable
+       result->is_local = (arg->flags & LOCAL) != 0;
+
        /* if type is undefined */
        if (arg->type == Node_var_new) {
                if (wanted == AWK_UNDEFINED)
diff --git a/gawkapi.h b/gawkapi.h
index 5071adc..9ef5688 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -326,6 +326,7 @@ typedef struct awk_value {
                awk_scalar_t    scl;
                awk_value_cookie_t vc;
        } u;
+       int is_local;   /* true if parameter was a truly local variable */
 #define str_value      u.s
 #define strnum_value   str_value
 #define regex_value    str_value
diff --git a/test/ChangeLog b/test/ChangeLog
index b0ca5a9..4ed8864 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-23         Arnold D. Robbins     <address@hidden>
+
+       * Makefile.am (islocal): New test.
+       * islocal.awk, islocal.ok: New files.
+
 2017-02-21         Andrew J. Schorr     <address@hidden>
 
        * Makefile.am (mktime): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index 65336b6..4364d88 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -538,6 +538,8 @@ EXTRA_DIST = \
        intprec.ok \
        iobug1.awk \
        iobug1.ok \
+       islocal.awk \
+       islocal.ok \
        jarebug.awk \
        jarebug.in \
        jarebug.ok \
@@ -1263,6 +1265,7 @@ LOCALE_CHARSET_TESTS = \
 
 SHLIB_TESTS = \
        apiterm fnmatch filefuncs fork fork2 fts functab4 getfile inplace1 
inplace2 inplace3 \
+       islocal \
        ordchr ordchr2 readdir readfile readfile2 revout revtwoway rwarray 
testext time
 
 # List of the tests which should be run with --lint option:
diff --git a/test/Makefile.in b/test/Makefile.in
index 1a61996..d6e4865 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -796,6 +796,8 @@ EXTRA_DIST = \
        intprec.ok \
        iobug1.awk \
        iobug1.ok \
+       islocal.awk \
+       islocal.ok \
        jarebug.awk \
        jarebug.in \
        jarebug.ok \
@@ -1516,6 +1518,7 @@ LOCALE_CHARSET_TESTS = \
 
 SHLIB_TESTS = \
        apiterm fnmatch filefuncs fork fork2 fts functab4 getfile inplace1 
inplace2 inplace3 \
+       islocal \
        ordchr ordchr2 readdir readfile readfile2 revout revtwoway rwarray 
testext time
 
 
@@ -4437,6 +4440,11 @@ functab4:
        @AWKPATH="$(srcdir)" $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
        @-$(CMP) "$(srcdir)"/address@hidden _$@ && rm -f _$@
 
+islocal:
+       @echo $@
+       @AWKPATH="$(srcdir)" $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
+       @-$(CMP) "$(srcdir)"/address@hidden _$@ && rm -f _$@
+
 ordchr:
        @echo $@
        @AWKPATH="$(srcdir)" $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index d9183c0..6ea531e 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1626,6 +1626,11 @@ functab4:
        @AWKPATH="$(srcdir)" $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
        @-$(CMP) "$(srcdir)"/address@hidden _$@ && rm -f _$@
 
+islocal:
+       @echo $@
+       @AWKPATH="$(srcdir)" $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
+       @-$(CMP) "$(srcdir)"/address@hidden _$@ && rm -f _$@
+
 ordchr:
        @echo $@
        @AWKPATH="$(srcdir)" $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
diff --git a/test/islocal.awk b/test/islocal.awk
new file mode 100644
index 0000000..d4d713d
--- /dev/null
+++ b/test/islocal.awk
@@ -0,0 +1,21 @@
address@hidden "islocal"
+
+BEGIN {
+       foo()
+       print ""
+
+       foo(1)
+       print ""
+
+       foo(1, 2)
+       print ""
+
+       foo(an_undefined_var)
+}
+
+function foo(a, b, c)  
+{
+       print "a is local:", islocal(a) ? "true" : "false"
+       print "b is local:", islocal(b) ? "true" : "false"
+       print "c is local:", islocal(c) ? "true" : "false"
+}
diff --git a/test/islocal.ok b/test/islocal.ok
new file mode 100644
index 0000000..c9236a9
--- /dev/null
+++ b/test/islocal.ok
@@ -0,0 +1,15 @@
+a is local: true
+b is local: true
+c is local: true
+
+a is local: false
+b is local: true
+c is local: true
+
+a is local: false
+b is local: false
+c is local: true
+
+a is local: false
+b is local: true
+c is local: true

-----------------------------------------------------------------------


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]