summaryrefslogtreecommitdiff
path: root/builtin.c
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2019-01-09 10:51:28 -0500
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2019-01-09 10:51:28 -0500
commit56f4a4139ad7e81064e25887f959a4a6e5e54a58 (patch)
tree01645ae916a19e911d2111763beead9faa1ba7ab /builtin.c
parent0e1fd064f13b220a129fc720607d3f62b55b3b19 (diff)
downloadgawk-56f4a4139ad7e81064e25887f959a4a6e5e54a58.tar.gz
Implement optional second array arg to type of returning info on variable internals.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index f2d31059..c92a5982 100644
--- a/builtin.c
+++ b/builtin.c
@@ -4069,13 +4069,28 @@ do_typeof(int nargs)
NODE *arg;
char *res = NULL;
bool deref = true;
+ NODE *dbg;
+ if (nargs == 2) { /* 2nd optional arg for debugging */
+ dbg = POP_PARAM();
+ if (dbg->type != Node_var_array)
+ fatal(_("typeof: second argument is not an array"));
+ assoc_clear(dbg);
+ }
+ else
+ dbg = NULL;
arg = POP();
switch (arg->type) {
case Node_var_array:
/* Node_var_array is never UPREF'ed */
res = "array";
deref = false;
+ if (dbg) {
+ NODE *sub = make_string("array_type", 10);
+ NODE **lhs = assoc_lookup(dbg, sub);
+ unref(*lhs);
+ *lhs = make_string(arg->array_funcs->name, strlen(arg->array_funcs->name));
+ }
break;
case Node_val:
switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) {
@@ -4104,6 +4119,13 @@ do_typeof(int nargs)
}
break;
}
+ if (dbg) {
+ const char *s = flags2str(arg->flags);
+ NODE *sub = make_string("flags", 5);
+ NODE **lhs = assoc_lookup(dbg, sub);
+ unref(*lhs);
+ *lhs = make_string(s, strlen(s));
+ }
break;
case Node_var_new:
res = "untyped";