gawk-diffs
[Top][All Lists]
Advanced

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

[SCM] gawk branch, feature/bool, updated. gawk-4.1.0-4253-g5fd7d2f


From: Arnold Robbins
Subject: [SCM] gawk branch, feature/bool, updated. gawk-4.1.0-4253-g5fd7d2f
Date: Mon, 8 Mar 2021 11:32:04 -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, feature/bool has been updated
       via  5fd7d2faf13484c595f7cd74468711282816796d (commit)
      from  b9931e852ba21180c380639135f96cdcd0a3015f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

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

commit 5fd7d2faf13484c595f7cd74468711282816796d
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Mon Mar 8 18:31:52 2021 +0200

    More progress on bool.

diff --git a/ChangeLog b/ChangeLog
index 52b74a7..e248bcc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2021-03-08         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * awk.h (warn_bool, do_bool): Add function declarations.
+       * awkgram.y (tokentab): Add entry for "bool" builtin.
+       * builtin.c (warn_bool): New function.
+       (do_index, do_substr, do_toupper, do_tolower, do_match,
+       do_length): Call it.
+       (do_sub): If first arg to sub/gsub is bool, fatal error.
+       (do_bool): New function.
+       * field.c (do_split, do_patsplit): Call warn_bool.
+       * main.c (load_procinfo_bools): Removed function and call.
+
 2021-03-05         Arnold D. Robbins     <arnold@skeeve.com>
 
        Start on a bool type for gawk.
diff --git a/awk.h b/awk.h
index ee055f4..f4fa4d4 100644
--- a/awk.h
+++ b/awk.h
@@ -1455,6 +1455,7 @@ extern bool is_identchar(int c);
 extern NODE *make_regnode(NODETYPE type, NODE *exp);
 extern bool validate_qualified_name(char *token);
 /* builtin.c */
+extern void warn_bool(const char *func, int argnum, NODE *n);
 extern double double_to_int(double d);
 extern NODE *do_exp(int nargs);
 extern NODE *do_fflush(int nargs);
@@ -1504,6 +1505,7 @@ extern int strncasecmpmbs(const unsigned char *,
                          const unsigned char *, size_t);
 extern int sanitize_exit_status(int status);
 extern void check_symtab_functab(NODE *dest, const char *fname, const char 
*msg);
+extern NODE *do_bool(int nargs);
 /* debug.c */
 extern void init_debug(void);
 extern int debug_prog(INSTRUCTION *pc);
diff --git a/awkgram.c b/awkgram.c
index 9c2700a..40c3cbd 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4779,6 +4779,7 @@ static const struct token tokentab[] = {
 {"asorti",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   
do_asorti,      0},
 {"atan2",      Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(2),   do_atan2,       
MPF(atan2)},
 {"bindtextdomain",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2),        
do_bindtextdomain,      0},
+{"bool",       Op_builtin,    LEX_BUILTIN,     GAWKX|A(1),     do_bool,        
0},
 {"break",      Op_K_break,      LEX_BREAK,     0,              0,      0},
 {"case",       Op_K_case,       LEX_CASE,      GAWKX,          0,      0},
 {"close",      Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(1)|A(2),      
do_close,       0},
diff --git a/awkgram.y b/awkgram.y
index 6dfbe7e..3fe0272 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2277,6 +2277,7 @@ static const struct token tokentab[] = {
 {"asorti",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   
do_asorti,      0},
 {"atan2",      Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(2),   do_atan2,       
MPF(atan2)},
 {"bindtextdomain",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2),        
do_bindtextdomain,      0},
+{"bool",       Op_builtin,    LEX_BUILTIN,     GAWKX|A(1),     do_bool,        
0},
 {"break",      Op_K_break,      LEX_BREAK,     0,              0,      0},
 {"case",       Op_K_case,       LEX_CASE,      GAWKX,          0,      0},
 {"close",      Op_builtin,      LEX_BUILTIN,   NOT_OLD|A(1)|A(2),      
do_close,       0},
diff --git a/bool.notes b/bool.notes
index 51ea726..df3ec69 100644
--- a/bool.notes
+++ b/bool.notes
@@ -33,8 +33,13 @@ numbers, and false before true.
 6. These string function generate a runtime fatal error
 if given an argument / target of boolean type:
 
-       substr  match   index   gensub  gsub
-       sub     length  split   patsplit
+       gsub sub
+
+These functions merely treat the value as a string
+but issue a lint warning.
+
+       substr  match   index   gensub
+       length  split   patsplit
        tolower toupper
 
 7. Updates to API needed for an additional type, and the table
diff --git a/builtin.c b/builtin.c
index 67a89bd..1158fad 100644
--- a/builtin.c
+++ b/builtin.c
@@ -381,6 +381,8 @@ do_index(int nargs)
 
        s1 = force_string(s1);
        s2 = force_string(s2);
+       warn_bool("index", 1, s1);
+       warn_bool("index", 2, s2);
 
        p1 = s1->stptr;
        p2 = s2->stptr;
@@ -552,6 +554,7 @@ do_length(int nargs)
        if (do_lint && (fixtype(tmp)->flags & STRING) == 0)
                lintwarn(_("%s: received non-string argument"), "length");
        tmp = force_string(tmp);
+       warn_bool("length", 1, tmp);
 
        if (gawk_mb_cur_max > 1) {
                tmp = force_wstring(tmp);
@@ -1779,6 +1782,16 @@ do_sqrt(int nargs)
        return make_number((AWKNUM) sqrt(arg));
 }
 
+/* warn_bool --- warn that bool parameter is used as a string */
+
+void
+warn_bool(const char *func, int argnum, NODE *n)
+{
+       if (do_lint && (n->flags & BOOL) != 0)
+               lintwarn(_("%s: argument %d of type bool used as a string"),
+                       func, argnum);
+}
+
 /* do_substr --- do the substr function */
 
 NODE *
@@ -1802,6 +1815,7 @@ do_substr(int nargs)
        DEREF(t1);
 
        t1 = POP_STRING();
+       warn_bool("substr", 1, t1);
 
        if (nargs == 3) {
                if (! (d_length >= 1)) {
@@ -2407,6 +2421,7 @@ do_tolower(int nargs)
        NODE *t1, *t2;
 
        t1 = POP_SCALAR();
+       warn_bool("tolower", 1, t1);
        if (do_lint && (fixtype(t1)->flags & STRING) == 0)
                lintwarn(_("%s: received non-string argument"), "tolower");
        t1 = force_string(t1);
@@ -2438,6 +2453,7 @@ do_toupper(int nargs)
        NODE *t1, *t2;
 
        t1 = POP_SCALAR();
+       warn_bool("toupper", 1, t1);
        if (do_lint && (fixtype(t1)->flags & STRING) == 0)
                lintwarn(_("%s: received non-string argument"), "toupper");
        t1 = force_string(t1);
@@ -2662,6 +2678,7 @@ do_match(int nargs)
        tre = POP();
        rp = re_update(tre);
        t1 = POP_STRING();
+       warn_bool("mastch", 1, t1);
 
        rstart = research(rp, t1->stptr, 0, t1->stlen, RE_NEED_START);
        if (rstart >= 0) {      /* match succeded */
@@ -2882,6 +2899,7 @@ do_sub(int nargs, unsigned int flags)
                rp = re_update(tmp);
 
                target = POP_STRING();  /* original string */
+               warn_bool("gensub", 3, target);
 
                glob_flag = POP_SCALAR();       /* value of global flag */
                if (   (glob_flag->flags & STRING) != 0
@@ -2924,6 +2942,10 @@ do_sub(int nargs, unsigned int flags)
                }
        }
 
+       if ((target->flags & BOOL) != 0)
+               fatal(_("%s: target cannot be of type bool"),
+                       (flags & GSUB) != 0 ? "gsub" : "sub");
+
        global = (how_many == -1);
 
        rep_node = POP_STRING();        /* replacement text */
@@ -4324,3 +4346,18 @@ check_symtab_functab(NODE *dest, const char *fname, 
const char *msg)
        else if (dest == func_table)
                fatal(msg, fname, "FUNCTAB");
 }
+
+/* do_bool --- create boolean values */
+
+NODE *
+do_bool(int nargs)
+{
+       NODE *tmp;
+       bool result;
+
+       tmp = POP_SCALAR();
+       result = boolval(tmp);
+       DEREF(tmp);
+
+       return make_bool_node(result);
+}
diff --git a/field.c b/field.c
index c21046b..2bd5886 100644
--- a/field.c
+++ b/field.c
@@ -1019,6 +1019,7 @@ do_split(int nargs)
        assoc_clear(arr);
 
        src = TOP_STRING();
+       warn_bool("split", 1, src);
        if (src->stlen == 0) {
                /*
                 * Skip the work if first arg is the null string.
@@ -1096,6 +1097,7 @@ do_patsplit(int nargs)
                        _("%s: cannot use %s as second argument"));
 
        src = TOP_STRING();
+       warn_bool("patsplit", 1, src);
 
        if ((sep->flags & REGEX) != 0)
                sep = sep->typed_re;
diff --git a/main.c b/main.c
index 9833d84..76f2828 100644
--- a/main.c
+++ b/main.c
@@ -982,23 +982,6 @@ load_procinfo_argv()
        assoc_set(PROCINFO_node, sub, argv_array);
 }
 
-/* load_procinfo_bools --- populate PROCINFO["true"] and PROCINFO["false"] */
-
-static void
-load_procinfo_bools()
-{
-       NODE *sub;
-       NODE *val;
-
-       val = make_bool_node(false);
-       sub = make_string("false", 5);
-       assoc_set(PROCINFO_node, sub, val);
-
-       val = make_bool_node(true);
-       sub = make_string("true", 4);
-       assoc_set(PROCINFO_node, sub, val);
-}
-
 /* load_procinfo --- populate the PROCINFO array */
 
 static NODE *
@@ -1085,7 +1068,6 @@ load_procinfo()
        }
 #endif
        load_procinfo_argv();
-       load_procinfo_bools();
        return PROCINFO_node;
 }
 
diff --git a/test/ChangeLog b/test/ChangeLog
index 53fe562..2604c27 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2021-03-08         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * dumpvars.ok, functab5.ok, id.ok, intest.awk, symtab11.ok,
+       symtab8.ok: Updated after code changes.
+
 2021-02-13         Arnold D. Robbins     <arnold@skeeve.com>
 
        * Makefile.am (EXTRA_DIST): argcasfile, new test.
diff --git a/test/dumpvars.ok b/test/dumpvars.ok
index 85d1c85..7caecd3 100644
--- a/test/dumpvars.ok
+++ b/test/dumpvars.ok
@@ -9,7 +9,7 @@ FILENAME: "-"
 FNR: 3
 FPAT: "[^[:space:]]+"
 FS: " "
-FUNCTAB: array, 41 elements
+FUNCTAB: array, 42 elements
 IGNORECASE: 0
 LINT: 0
 NF: 1
diff --git a/test/functab5.ok b/test/functab5.ok
index 9ac4295..ef11098 100644
--- a/test/functab5.ok
+++ b/test/functab5.ok
@@ -3,6 +3,7 @@ asort'
 asorti'
 atan2'
 bindtextdomain'
+bool'
 chdir'
 close'
 compl'
diff --git a/test/id.ok b/test/id.ok
index ab4df74..f990546 100644
--- a/test/id.ok
+++ b/test/id.ok
@@ -34,6 +34,7 @@ asort -> builtin
 asorti -> builtin
 atan2 -> builtin
 bindtextdomain -> builtin
+bool -> builtin
 close -> builtin
 compl -> builtin
 cos -> builtin
diff --git a/test/intest.awk b/test/intest.awk
index f030d07..18e0cc4 100644
--- a/test/intest.awk
+++ b/test/intest.awk
@@ -1,4 +1,4 @@
 BEGIN {
-       bool = ((b = 1) in c);
-       print bool, b   # gawk-3.0.1 prints "0 "; should print "0 1"
+       bool_result = ((b = 1) in c);
+       print bool_result, b    # gawk-3.0.1 prints "0 "; should print "0 1"
 } 
diff --git a/test/symtab11.ok b/test/symtab11.ok
index 7d4be46..da2cfcb 100644
--- a/test/symtab11.ok
+++ b/test/symtab11.ok
@@ -37,6 +37,7 @@ BEGIN -- Functab is next
 [asorti] = asorti
 [atan2] = atan2
 [bindtextdomain] = bindtextdomain
+[bool] = bool
 [close] = close
 [compl] = compl
 [cos] = cos
diff --git a/test/symtab8.ok b/test/symtab8.ok
index da29b58..0cf40fe 100644
--- a/test/symtab8.ok
+++ b/test/symtab8.ok
@@ -9,7 +9,7 @@ FIELDWIDTHS: ""
 FNR: 1
 FPAT: "[^[:space:]]+"
 FS: " "
-FUNCTAB: array, 41 elements
+FUNCTAB: array, 42 elements
 IGNORECASE: 0
 LINT: 0
 NF: 1

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

Summary of changes:
 ChangeLog        | 12 ++++++++++++
 awk.h            |  2 ++
 awkgram.c        |  1 +
 awkgram.y        |  1 +
 bool.notes       |  9 +++++++--
 builtin.c        | 37 +++++++++++++++++++++++++++++++++++++
 field.c          |  2 ++
 main.c           | 18 ------------------
 test/ChangeLog   |  5 +++++
 test/dumpvars.ok |  2 +-
 test/functab5.ok |  1 +
 test/id.ok       |  1 +
 test/intest.awk  |  4 ++--
 test/symtab11.ok |  1 +
 test/symtab8.ok  |  2 +-
 15 files changed, 74 insertions(+), 24 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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