aboutsummaryrefslogtreecommitdiffstats
path: root/awkgram.y
diff options
context:
space:
mode:
Diffstat (limited to 'awkgram.y')
-rw-r--r--awkgram.y46
1 files changed, 21 insertions, 25 deletions
diff --git a/awkgram.y b/awkgram.y
index a1bbc775..a5707429 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-2013 the Free Software Foundation, Inc.
+ * Copyright (C) 1986, 1988, 1989, 1991-2014 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -864,7 +864,7 @@ non_compound_stmt
(void) list_prepend($$, instruction(Op_push_i));
$$->nexti->memory = dupnode(Nnull_string);
} else {
- if (do_optimize > 1
+ if (do_optimize
&& $3->lasti->opcode == Op_func_call
&& strcmp($3->lasti->func_name, in_function) == 0
) {
@@ -1368,7 +1368,7 @@ common_exp
*/
}
- if (do_optimize > 1
+ if (do_optimize
&& $1->nexti == $1->lasti && $1->nexti->opcode == Op_push_i
&& $2->nexti == $2->lasti && $2->nexti->opcode == Op_push_i
) {
@@ -1506,7 +1506,7 @@ non_post_simp_exp
$$ = list_append(list_append(list_create($1),
instruction(Op_field_spec)), $2);
} else {
- if (do_optimize > 1 && $2->nexti == $2->lasti
+ if (do_optimize && $2->nexti == $2->lasti
&& $2->nexti->opcode == Op_push_i
&& ($2->nexti->memory->flags & (MPFN|MPZN)) == 0
) {
@@ -4218,7 +4218,7 @@ mk_function(INSTRUCTION *fi, INSTRUCTION *def)
thisfunc = fi->func_body;
assert(thisfunc != NULL);
- if (do_optimize > 1 && def->lasti->opcode == Op_pop) {
+ if (do_optimize && def->lasti->opcode == Op_pop) {
/* tail call which does not return any value. */
INSTRUCTION *t;
@@ -4369,18 +4369,9 @@ func_use(const char *name, enum defref how)
len = strlen(name);
ind = hash(name, len, HASHSIZE, NULL);
- for (fp = ftable[ind]; fp != NULL; fp = fp->next) {
- if (strcmp(fp->name, name) == 0) {
- if (how == FUNC_DEFINE)
- fp->defined++;
- else if (how == FUNC_EXT) {
- fp->defined++;
- fp->extension++;
- } else
- fp->used++;
- return;
- }
- }
+ for (fp = ftable[ind]; fp != NULL; fp = fp->next)
+ if (strcmp(fp->name, name) == 0)
+ goto update_value;
/* not in the table, fall through to allocate a new one */
@@ -4388,6 +4379,10 @@ func_use(const char *name, enum defref how)
memset(fp, '\0', sizeof(struct fdesc));
emalloc(fp->name, char *, len + 1, "func_use");
strcpy(fp->name, name);
+ fp->next = ftable[ind];
+ ftable[ind] = fp;
+
+update_value:
if (how == FUNC_DEFINE)
fp->defined++;
else if (how == FUNC_EXT) {
@@ -4395,8 +4390,6 @@ func_use(const char *name, enum defref how)
fp->extension++;
} else
fp->used++;
- fp->next = ftable[ind];
- ftable[ind] = fp;
}
/* track_ext_func --- add an extension function to the table */
@@ -4746,7 +4739,7 @@ mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op)
if (s2->lasti == ip2 && ip2->opcode == Op_push_i) {
/* do any numeric constant folding */
ip1 = s1->nexti;
- if (do_optimize > 1
+ if (do_optimize
&& ip1 == s1->lasti && ip1->opcode == Op_push_i
&& (ip1->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
&& (ip2->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
@@ -5093,8 +5086,13 @@ mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op)
case Op_push_array:
tp->opcode = Op_push_lhs;
break;
+ case Op_field_assign:
+ yyerror(_("cannot assign a value to the result of a field post-increment expression"));
+ break;
default:
- cant_happen();
+ yyerror(_("invalid target of assignment (opcode %s)"),
+ opcode2str(tp->opcode));
+ break;
}
tp->do_reference = (op->opcode != Op_assign); /* check for uninitialized reference */
@@ -5164,10 +5162,8 @@ optimize_assignment(INSTRUCTION *exp)
i2 = NULL;
i1 = exp->lasti;
- if ( ! do_optimize
- || ( i1->opcode != Op_assign
- && i1->opcode != Op_field_assign)
- )
+ if ( i1->opcode != Op_assign
+ && i1->opcode != Op_field_assign)
return list_append(exp, instruction(Op_pop));
for (i2 = exp->nexti; i2 != i1; i2 = i2->nexti) {