diff options
Diffstat (limited to 'awkgram.c')
-rw-r--r-- | awkgram.c | 44 |
1 files changed, 20 insertions, 24 deletions
@@ -2860,7 +2860,7 @@ regular_loop: (void) list_prepend((yyval), instruction(Op_push_i)); (yyval)->nexti->memory = dupnode(Nnull_string); } else { - if (do_optimize > 1 + if (do_optimize && (yyvsp[(3) - (4)])->lasti->opcode == Op_func_call && strcmp((yyvsp[(3) - (4)])->lasti->func_name, in_function) == 0 ) { @@ -3530,7 +3530,7 @@ regular_print: */ } - if (do_optimize > 1 + if (do_optimize && (yyvsp[(1) - (2)])->nexti == (yyvsp[(1) - (2)])->lasti && (yyvsp[(1) - (2)])->nexti->opcode == Op_push_i && (yyvsp[(2) - (2)])->nexti == (yyvsp[(2) - (2)])->lasti && (yyvsp[(2) - (2)])->nexti->opcode == Op_push_i ) { @@ -3730,7 +3730,7 @@ regular_print: (yyval) = list_append(list_append(list_create((yyvsp[(1) - (2)])), instruction(Op_field_spec)), (yyvsp[(2) - (2)])); } else { - if (do_optimize > 1 && (yyvsp[(2) - (2)])->nexti == (yyvsp[(2) - (2)])->lasti + if (do_optimize && (yyvsp[(2) - (2)])->nexti == (yyvsp[(2) - (2)])->lasti && (yyvsp[(2) - (2)])->nexti->opcode == Op_push_i && ((yyvsp[(2) - (2)])->nexti->memory->flags & (MPFN|MPZN)) == 0 ) { @@ -6766,7 +6766,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; @@ -6917,18 +6917,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 */ @@ -6936,6 +6927,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) { @@ -6943,8 +6938,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 */ @@ -7294,7 +7287,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 @@ -7641,8 +7634,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 */ @@ -7712,10 +7710,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) { |