[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gawk-diffs] [SCM] gawk branch, feature/namespaces, updated. gawk-4.1.0-
From: |
Arnold Robbins |
Subject: |
[gawk-diffs] [SCM] gawk branch, feature/namespaces, updated. gawk-4.1.0-2583-g28e08c9 |
Date: |
Fri, 16 Jun 2017 05:15:01 -0400 (EDT) |
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/namespaces has been updated
via 28e08c93f6cb48ab08677fa82cf6d0cbefe79dda (commit)
from 707fa4c23ee60507da9958ab9fe1ba2f6e3744a1 (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=28e08c93f6cb48ab08677fa82cf6d0cbefe79dda
commit 28e08c93f6cb48ab08677fa82cf6d0cbefe79dda
Author: Arnold D. Robbins <address@hidden>
Date: Fri Jun 16 12:14:28 2017 +0300
Add namespace knowledge to symbol lookup and management.
diff --git a/ChangeLog b/ChangeLog
index ffb30ba..5a431e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2017-06-16 Arnold D. Robbins <address@hidden>
+
+ * awk.h (lookup): Add second parameter.
+ * array.c (assoc_list): Adjust call to lookup.
+ * awkgram.y (grammar, parms_shadow, install_function, variable):
+ Ditto.
+ * command.y [Grammar]: Ditto.
+ * debug.c (find_symbol): Ditto.
+ * ext.c (make_builtin): Ditto.
+ * gawkapi.c (api_sym_lookup, api_sym_update): Ditto.
+ * interpret.h (r_interpret): Ditto.
+ * main.c (arg_assign): Ditto.
+ (main): Reset current_namespace after parsing.
+ * symbol.c (lookup): New second parameter, do_qualify. Use it
+ to qualify names or not.
+ (install): Call fix_up_namespace.
+ (is_all_upper): New helper routine.
+ (fix_up_namespace): New function.
+
2017-06-13 Arnold D. Robbins <address@hidden>
* awk.h (awk_namespace, current_namespace): Move to const char.
diff --git a/array.c b/array.c
index 3159bfd..758b87a 100644
--- a/array.c
+++ b/array.c
@@ -1320,7 +1320,7 @@ assoc_list(NODE *symbol, const char *sort_str,
sort_context_t sort_ctxt)
if (sp == sort_str || *sp != '\0')
fatal(_("`%s' is invalid as a function name"),
sort_str);
- f = lookup(sort_str);
+ f = lookup(sort_str, false);
if (f == NULL || f->type != Node_func)
fatal(_("sort comparison function `%s' is not
defined"), sort_str);
diff --git a/awk.h b/awk.h
index 63cac9b..55de2f4 100644
--- a/awk.h
+++ b/awk.h
@@ -1707,7 +1707,7 @@ extern NODE *remove_symbol(NODE *r);
extern void destroy_symbol(NODE *r);
extern void release_symbols(NODE *symlist, int keep_globals);
extern void append_symbol(NODE *r);
-extern NODE *lookup(const char *name);
+extern NODE *lookup(const char *name, bool do_qualify);
extern NODE *make_params(char **pnames, int pcount);
extern void install_params(NODE *func);
extern void remove_params(NODE *func);
diff --git a/awkgram.c b/awkgram.c
index 5dc44e0..4b24311 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4050,7 +4050,7 @@ regular_print:
NODE *n;
if (! at_seen) {
- n = lookup((yyvsp[-3])->func_name);
+ n = lookup((yyvsp[-3])->func_name, true);
if (n != NULL && n->type != Node_func
&& n->type != Node_ext_func) {
error_ln((yyvsp[-3])->source_line,
@@ -6640,7 +6640,7 @@ retry:
goto out;
case FUNC_BODY:
/* in body, name must be in symbol table for it
to be a parameter */
- if ((f = lookup(tokstart)) != NULL) {
+ if ((f = lookup(tokstart, false)) != NULL) {
if (f->type == Node_builtin_func)
break;
else
@@ -7121,7 +7121,7 @@ parms_shadow(INSTRUCTION *pc, bool *shadow)
* about all shadowed parameters.
*/
for (i = 0; i < pcount; i++) {
- if (lookup(fp[i].param) != NULL) {
+ if (lookup(fp[i].param, false) != NULL) {
warning(
_("function `%s': parameter `%s' shadows global variable"),
fname, fp[i].param);
@@ -7291,7 +7291,7 @@ install_function(char *fname, INSTRUCTION *fi,
INSTRUCTION *plist)
NODE *r, *f;
int pcount = 0;
- r = lookup(fname);
+ r = lookup(fname, true);
if (r != NULL) {
error_ln(fi->source_line, _("function name `%s' previously
defined"), fname);
return -1;
@@ -7495,7 +7495,7 @@ variable(int location, char *name, NODETYPE type)
{
NODE *r;
- if ((r = lookup(name)) != NULL) {
+ if ((r = lookup(name, true)) != NULL) {
if (r->type == Node_func || r->type == Node_ext_func )
error_ln(location, _("function `%s' called with space
between name and `(',\nor used as a variable or an array"),
r->vname);
diff --git a/awkgram.y b/awkgram.y
index efc4d08..3c3aa8c 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -1892,7 +1892,7 @@ direct_func_call
NODE *n;
if (! at_seen) {
- n = lookup($1->func_name);
+ n = lookup($1->func_name, true);
if (n != NULL && n->type != Node_func
&& n->type != Node_ext_func) {
error_ln($1->source_line,
@@ -4206,7 +4206,7 @@ retry:
goto out;
case FUNC_BODY:
/* in body, name must be in symbol table for it
to be a parameter */
- if ((f = lookup(tokstart)) != NULL) {
+ if ((f = lookup(tokstart, false)) != NULL) {
if (f->type == Node_builtin_func)
break;
else
@@ -4687,7 +4687,7 @@ parms_shadow(INSTRUCTION *pc, bool *shadow)
* about all shadowed parameters.
*/
for (i = 0; i < pcount; i++) {
- if (lookup(fp[i].param) != NULL) {
+ if (lookup(fp[i].param, false) != NULL) {
warning(
_("function `%s': parameter `%s' shadows global variable"),
fname, fp[i].param);
@@ -4857,7 +4857,7 @@ install_function(char *fname, INSTRUCTION *fi,
INSTRUCTION *plist)
NODE *r, *f;
int pcount = 0;
- r = lookup(fname);
+ r = lookup(fname, true);
if (r != NULL) {
error_ln(fi->source_line, _("function name `%s' previously
defined"), fname);
return -1;
@@ -5061,7 +5061,7 @@ variable(int location, char *name, NODETYPE type)
{
NODE *r;
- if ((r = lookup(name)) != NULL) {
+ if ((r = lookup(name, true)) != NULL) {
if (r->type == Node_func || r->type == Node_ext_func )
error_ln(location, _("function `%s' called with space
between name and `(',\nor used as a variable or an array"),
r->vname);
diff --git a/command.c b/command.c
index a0469bb..26b4e80 100644
--- a/command.c
+++ b/command.c
@@ -1959,7 +1959,7 @@ yyreduce:
#line 471 "command.y" /* yacc.c:1646 */
{
NODE *n;
- n = lookup((yyvsp[0])->a_string);
+ n = lookup((yyvsp[0])->a_string, true);
if (n == NULL || n->type != Node_func)
yyerror(_("no such function - \"%s\""),
(yyvsp[0])->a_string);
else {
diff --git a/command.y b/command.y
index 4597dba..158b480 100644
--- a/command.y
+++ b/command.y
@@ -470,7 +470,7 @@ func_name
: D_STRING
{
NODE *n;
- n = lookup($1->a_string);
+ n = lookup($1->a_string, true);
if (n == NULL || n->type != Node_func)
yyerror(_("no such function - \"%s\""), $1->a_string);
else {
diff --git a/debug.c b/debug.c
index fc0f94c..0274b47 100644
--- a/debug.c
+++ b/debug.c
@@ -1024,7 +1024,7 @@ NODE *find_symbol(const char *name, char **pname)
if (prog_running)
r = find_param(name, cur_frame, pname);
if (r == NULL)
- r = lookup(name);
+ r = lookup(name, false); // for now, require fully qualified
name
if (r == NULL)
fprintf(out_fp, _("no symbol `%s' in current context\n"), name);
return r;
@@ -5523,7 +5523,7 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
return false;
}
- f = lookup("@eval");
+ f = lookup("@eval", false);
assert(f != NULL);
if (this_func == NULL) { /* in main */
/* do a function call */
diff --git a/ext.c b/ext.c
index 609b3b2..64757c9 100644
--- a/ext.c
+++ b/ext.c
@@ -113,7 +113,8 @@ make_builtin(const awk_ext_func_t *funcinfo)
return awk_false;
}
- f = lookup(name);
+ // FIXME: Handle namespaces here
+ f = lookup(name, false);
if (f != NULL) {
if (f->type == Node_func) {
diff --git a/gawkapi.c b/gawkapi.c
index 4c6a2f8..e529dc9 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -683,10 +683,11 @@ api_sym_lookup(awk_ext_id_t id,
update_global_values(); /* make sure stuff like NF, NR, are up
to date */
+ // FIXME, need to handle namespaces if name not null and not empty
if ( name == NULL
|| *name == '\0'
|| result == NULL
- || (node = lookup(name)) == NULL)
+ || (node = lookup(name, false)) == NULL)
return awk_false;
if (is_off_limits_var(name)) /* a built-in variable */
@@ -746,7 +747,8 @@ api_sym_update(awk_ext_id_t id,
return awk_false;
}
- node = lookup(name);
+ // FIXME: Deal with namespaces
+ node = lookup(name, false);
if (node == NULL) {
/* new value to be installed */
diff --git a/interpret.h b/interpret.h
index 13394e2..f0e617b 100644
--- a/interpret.h
+++ b/interpret.h
@@ -1076,7 +1076,7 @@ match_re:
ni = setup_frame(pc);
JUMPTO(ni); /* Op_func */
}
- f = lookup(t1->stptr);
+ f = lookup(t1->stptr, false);
}
if (f == NULL) {
@@ -1140,7 +1140,7 @@ match_re:
/* retrieve function definition node */
f = pc->func_body;
if (f == NULL) {
- f = lookup(pc->func_name);
+ f = lookup(pc->func_name, true);
if (f == NULL || (f->type != Node_func &&
f->type != Node_ext_func))
fatal(_("function `%s' not defined"),
pc->func_name);
pc->func_body = f; /* save for next call */
diff --git a/main.c b/main.c
index 195684c..481a5ee 100644
--- a/main.c
+++ b/main.c
@@ -461,6 +461,11 @@ main(int argc, char **argv)
if (do_intl)
exit(EXIT_SUCCESS);
+ if (current_namespace != awk_namespace) {
+ efree((char *) current_namespace);
+ current_namespace = awk_namespace;
+ }
+
install_builtins();
if (do_lint)
@@ -1146,7 +1151,7 @@ arg_assign(char *arg, bool initing)
fatal(_("cannot use gawk builtin `%s' as variable
name"), arg);
if (! initing) {
- var = lookup(arg);
+ var = lookup(arg, false);
if (var != NULL && var->type == Node_func)
fatal(_("cannot use function `%s' as variable
name"), arg);
}
diff --git a/symbol.c b/symbol.c
index ea5ee0a..af92e52 100644
--- a/symbol.c
+++ b/symbol.c
@@ -38,6 +38,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 const char *fix_up_namespace(const char *name);
static AWK_CONTEXT *curr_ctxt = NULL;
static int ctxt_level;
@@ -87,7 +88,7 @@ install_symbol(const char *name, NODETYPE type)
*/
NODE *
-lookup(const char *name)
+lookup(const char *name, bool do_qualify)
{
NODE *n;
NODE *tmp;
@@ -101,6 +102,9 @@ lookup(const char *name)
tables[3] = symbol_table; /* then globals */
tables[4] = NULL;
+ if (do_qualify)
+ name = fix_up_namespace(name);
+
tmp = make_string(name, strlen(name));
n = NULL;
@@ -304,6 +308,8 @@ install(const char *name, NODE *parm, NODETYPE type)
NODE *n_name;
NODE *prev;
+ name = fix_up_namespace(name);
+
n_name = make_string(name, strlen(name));
table = symbol_table;
@@ -944,3 +950,64 @@ free_bcpool(INSTRUCTION_POOL *pl)
for (i = 0; i < MAX_INSTRUCTION_ALLOC; i++)
free_bc_mempool(& pl->pool[i], i + 1);
}
+
+/* is_all_upper --- return true if name is all uppercase letters */
+
+static bool
+is_all_upper(const char *name)
+{
+ for (; *name != '\0'; name ++) {
+ switch (*name) {
+ case 'A': case 'B': case 'C': case 'D': case 'E':
+ case 'F': case 'G': case 'H': case 'I': case 'J':
+ case 'K': case 'L': case 'M': case 'N': case 'O':
+ case 'P': case 'Q': case 'R': case 'S': case 'T':
+ case 'U': case 'V': case 'W': case 'X': case 'Y':
+ case 'Z':
+ break;
+ default:
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/* fix_up_namespace --- qualify / dequalify a simple name */
+
+static const char *
+fix_up_namespace(const char *name)
+{
+ static char awk_ns[] = "awk::";
+ const size_t awk_ns_len = sizeof(awk_ns) - 1; // don't include
trailing \0
+ static size_t len = 0;
+ static char *buf = NULL;
+ char *cp;
+
+ // first, check if it's qualified
+ if ((cp = strchr(name, ':')) != NULL) {
+ // does it start with awk:: ?
+ if (strncmp(name, awk_ns, awk_ns_len) == 0)
+ return cp + 2; // just trailing part
+
+ // otherwise it's fully qualified, not in the awk n.s.
+ return name;
+ }
+
+ // not fully qualified
+ if (current_namespace == awk_namespace || is_all_upper(name))
+ return name; // put it into awk namespace
+
+ size_t needed = strlen(current_namespace) + 2 + strlen(name) + 1;
+ if (len == 0) {
+ emalloc(buf, char *, needed, "fix_up_namespace");
+ len = needed;
+ } else if (len < needed) {
+ erealloc(buf, char *, needed, "fix_up_namespace");
+ len = needed;
+ } // else
+ // nothing to do, just sprintf into the buffer
+
+ sprintf(buf, "%s::%s", current_namespace, name);
+ return buf;
+}
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 19 +++++++++++++++++
array.c | 2 +-
awk.h | 2 +-
awkgram.c | 10 ++++-----
awkgram.y | 10 ++++-----
command.c | 2 +-
command.y | 2 +-
debug.c | 4 ++--
ext.c | 3 ++-
gawkapi.c | 6 ++++--
interpret.h | 4 ++--
main.c | 7 ++++++-
symbol.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
13 files changed, 117 insertions(+), 23 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gawk-diffs] [SCM] gawk branch, feature/namespaces, updated. gawk-4.1.0-2583-g28e08c9,
Arnold Robbins <=