From: epetrich Date: Tue, 11 Nov 2003 07:21:52 +0000 (+0000) Subject: * src/SDCCast.c (removePostIncDecOps, removePreIncDecOps), X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=390778daf6c7d78a63950d9429a9a70be5f90675;p=fw%2Fsdcc * src/SDCCast.c (removePostIncDecOps, removePreIncDecOps), * src/SDCCast.h, * src/SDCC.y: fixed bug #819403 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3010 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 16011036..52acb65e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-11-11 Erik Petrich + + * src/SDCCast.c (removePostIncDecOps, removePreIncDecOps), + * src/SDCCast.h, + * src/SDCC.y: fixed bug #819403 + 2003-11-08 Erik Petrich * support/regression/fwk/lib/testfwk.c: printn is recursive and thus needs diff --git a/src/SDCC.y b/src/SDCC.y index 91eb6aec..fa781d1d 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -402,34 +402,45 @@ assignment_expr $$ = newNode($2,$1,$3); break; case MUL_ASSIGN: - $$ = newNode('=',$1,newNode('*',removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode('*',removePreIncDecOps(copyAst($1)),$3)); break; case DIV_ASSIGN: - $$ = newNode('=',$1,newNode('/',removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode('/',removePreIncDecOps(copyAst($1)),$3)); break; case MOD_ASSIGN: - $$ = newNode('=',$1,newNode('%',removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode('%',removePreIncDecOps(copyAst($1)),$3)); break; case ADD_ASSIGN: - $$ = newNode('=',$1,newNode('+',removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode('+',removePreIncDecOps(copyAst($1)),$3)); break; case SUB_ASSIGN: - $$ = newNode('=',$1,newNode('-',removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode('-',removePreIncDecOps(copyAst($1)),$3)); break; case LEFT_ASSIGN: - $$ = newNode('=',$1,newNode(LEFT_OP,removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode(LEFT_OP,removePreIncDecOps(copyAst($1)),$3)); break; case RIGHT_ASSIGN: - $$ = newNode('=',$1,newNode(RIGHT_OP,removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode(RIGHT_OP,removePreIncDecOps(copyAst($1)),$3)); break; case AND_ASSIGN: - $$ = newNode('=',$1,newNode('&',removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode('&',removePreIncDecOps(copyAst($1)),$3)); break; case XOR_ASSIGN: - $$ = newNode('=',$1,newNode('^',removeIncDecOps(copyAst($1)),$3)); + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode('^',removePreIncDecOps(copyAst($1)),$3)); break; case OR_ASSIGN: - $$ = newNode('=',$1,newNode('|',removeIncDecOps(copyAst($1)),$3)); + /* $$ = newNode('=',$1,newNode('|',removeIncDecOps(copyAst($1)),$3)); */ + $$ = newNode('=',removePostIncDecOps(copyAst($1)), + newNode('|',removePreIncDecOps(copyAst($1)),$3)); break; default : $$ = NULL; diff --git a/src/SDCCast.c b/src/SDCCast.c index 354a70b2..a788e69a 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -273,6 +273,52 @@ ast *removeIncDecOps (ast * tree) { return tree; } +/*-----------------------------------------------------------------*/ +/* removePreIncDecOps: remove for side effects in *_ASSIGN's */ +/* "*++s += 3" -> "*++s = *++s + 3" */ +/*-----------------------------------------------------------------*/ +ast *removePreIncDecOps (ast * tree) { + + // traverse the tree and remove pre-inc/dec ops + + if (!tree) + return NULL; + + if (tree->type == EX_OP && + (tree->opval.op == INC_OP || tree->opval.op == DEC_OP)) { + if (tree->right) + tree=tree->right; + } + + tree->left=removePreIncDecOps(tree->left); + tree->right=removePreIncDecOps(tree->right); + + return tree; +} + +/*-----------------------------------------------------------------*/ +/* removePostIncDecOps: remove for side effects in *_ASSIGN's */ +/* "*s++ += 3" -> "*s++ = *s++ + 3" */ +/*-----------------------------------------------------------------*/ +ast *removePostIncDecOps (ast * tree) { + + // traverse the tree and remove pre-inc/dec ops + + if (!tree) + return NULL; + + if (tree->type == EX_OP && + (tree->opval.op == INC_OP || tree->opval.op == DEC_OP)) { + if (tree->left) + tree=tree->left; + } + + tree->left=removePostIncDecOps(tree->left); + tree->right=removePostIncDecOps(tree->right); + + return tree; +} + /*-----------------------------------------------------------------*/ /* hasSEFcalls - returns TRUE if tree has a function call */ /*-----------------------------------------------------------------*/ @@ -3539,11 +3585,11 @@ decorateType (ast * tree) TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)); if (!tree->initMode && IS_CONSTANT (LTYPE (tree))) - werror (E_CODE_WRITE, *tree->opval.op==MUL_ASSIGN ? "*=" : "/="); + werror (E_CODE_WRITE, tree->opval.op==MUL_ASSIGN ? "*=" : "/="); if (LRVAL (tree)) { - werror (E_LVALUE_REQUIRED, *tree->opval.op==MUL_ASSIGN ? "*=" : "/="); + werror (E_LVALUE_REQUIRED, tree->opval.op==MUL_ASSIGN ? "*=" : "/="); goto errorTreeReturn; } LLVAL (tree) = 1; diff --git a/src/SDCCast.h b/src/SDCCast.h index 24cc4f7a..2054e1df 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -183,6 +183,8 @@ void initAst (); ast *newNode (long, ast *, ast *); ast *copyAst (ast *); ast *removeIncDecOps (ast *); +ast *removePreIncDecOps (ast *); +ast *removePostIncDecOps (ast *); value *sizeofOp (sym_link *); value *evalStmnt (ast *); ast *createFunction (symbol *, ast *);