aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index 3d57234b..9a64dde0 100644
--- a/builtin.c
+++ b/builtin.c
@@ -4071,13 +4071,31 @@ 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));
+ if (dbg->astore != NULL)
+ (*dbg->astore)(dbg, sub);
+ unref(sub);
+ }
break;
case Node_val:
switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) {
@@ -4106,6 +4124,16 @@ 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));
+ if (dbg->astore != NULL)
+ (*dbg->astore)(dbg, sub);
+ unref(sub);
+ }
break;
case Node_var_new:
res = "untyped";