diff options
Diffstat (limited to 'interpret.h')
-rw-r--r-- | interpret.h | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/interpret.h b/interpret.h index 2934c5c0..e9896672 100644 --- a/interpret.h +++ b/interpret.h @@ -303,22 +303,16 @@ uninitialized_scalar: if (r == NULL) { r = make_array(); r->parent_array = t1; - lhs = assoc_lookup(t1, t2); - unref(*lhs); - *lhs = r; t2 = force_string(t2); r->vname = estrdup(t2->stptr, t2->stlen); /* the subscript in parent array */ - - /* execute post-assignment routine if any */ - if (t1->astore != NULL) - (*t1->astore)(t1, t2); + assoc_set(t1, t2, r); } else if (r->type != Node_var_array) { t2 = force_string(t2); fatal(_("attempt to use scalar `%s[\"%.*s\"]' as an array"), array_vname(t1), (int) t2->stlen, t2->stptr); - } + } else + DEREF(t2); - DEREF(t2); PUSH(r); break; @@ -351,16 +345,19 @@ uninitialized_scalar: * 3. Values that awk code stuck into SYMTAB not related to variables (Node_value) * For 1, since we are giving it a value, we have to change the type to Node_var. * For 1 and 2, we have to step through the Node_var to get to the value. - * For 3, we just us the value we got from assoc_lookup(), above. + * For 3, we fatal out. This avoids confusion on things like + * SYMTAB["a foo"] = 42 # variable with a space in its name? */ if (t1 == func_table) fatal(_("cannot assign to elements of FUNCTAB")); - else if ( t1 == symbol_table - && ( (*lhs)->type == Node_var + else if (t1 == symbol_table) { + if (( (*lhs)->type == Node_var || (*lhs)->type == Node_var_new)) { - update_global_values(); /* make sure stuff like NF, NR, are up to date */ - (*lhs)->type = Node_var; /* in case was Node_var_new */ - lhs = & ((*lhs)->var_value); /* extra level of indirection */ + update_global_values(); /* make sure stuff like NF, NR, are up to date */ + (*lhs)->type = Node_var; /* in case was Node_var_new */ + lhs = & ((*lhs)->var_value); /* extra level of indirection */ + } else + fatal(_("cannot assign to arbitrary elements of SYMTAB")); } assert(set_idx == NULL); @@ -661,22 +658,25 @@ mod: /* * Changing something in FUNCTAB is not allowed. * - * SYMTAB is a little more messy. Three kinds of values may - * be stored in SYMTAB: + * SYMTAB is a little more messy. Three possibilities for SYMTAB: * 1. Variables that don"t yet have a value (Node_var_new) * 2. Variables that have a value (Node_var) * 3. Values that awk code stuck into SYMTAB not related to variables (Node_value) * For 1, since we are giving it a value, we have to change the type to Node_var. * For 1 and 2, we have to step through the Node_var to get to the value. - * For 3, we just us the value we got from assoc_lookup(), above. + * For 3, we fatal out. This avoids confusion on things like + * SYMTAB["a foo"] = 42 # variable with a space in its name? */ if (t1 == func_table) fatal(_("cannot assign to elements of FUNCTAB")); - else if ( t1 == symbol_table - && ( (*lhs)->type == Node_var + else if (t1 == symbol_table) { + if (( (*lhs)->type == Node_var || (*lhs)->type == Node_var_new)) { - (*lhs)->type = Node_var; /* in case was Node_var_new */ - lhs = & ((*lhs)->var_value); /* extra level of indirection */ + update_global_values(); /* make sure stuff like NF, NR, are up to date */ + (*lhs)->type = Node_var; /* in case was Node_var_new */ + lhs = & ((*lhs)->var_value); /* extra level of indirection */ + } else + fatal(_("cannot assign to arbitrary elements of SYMTAB")); } unref(*lhs); @@ -1108,7 +1108,7 @@ match_re: ni = setup_frame(pc); JUMPTO(ni); /* Op_func */ } - f = lookup(t1->stptr); + f = lookup(t1->stptr, true); } if (f == NULL) { @@ -1172,7 +1172,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 */ |