From: epetrich Date: Sun, 19 Oct 2003 04:39:13 +0000 (+0000) Subject: * src/SDCCicode.c (geniCodePreInc, geniCodePreDec, ast2iCode): X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=97faf59930af27354b4434fb57dbd922ae746fdf;p=fw%2Fsdcc * src/SDCCicode.c (geniCodePreInc, geniCodePreDec, ast2iCode): Fixed bug #818696 * src/SDCCast.c (ast_print): Fixed --dumptree so that preincrement and predecrement operand is displayed git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2954 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index fd4ce637..b242f43f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-10-19 Erik Petrich + + * src/SDCCicode.c (geniCodePreInc, geniCodePreDec, ast2iCode): + Fixed bug #818696 + * src/SDCCast.c (ast_print): Fixed --dumptree so that preincrement + and predecrement operand is displayed + 2003-10-13 Bernhard Held * src/SDCCval.c (valMinus): fixed bug #826041 diff --git a/src/SDCCast.c b/src/SDCCast.c index f1cc4b78..0c160a1b 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -1596,7 +1596,7 @@ isConformingBody (ast * pbody, symbol * sym, ast * body) return TRUE; /*------------------------------------------------------------------*/ - case INC_OP: /* incerement operator unary so left only */ + case INC_OP: case DEC_OP: /* sure we are not sym is not modified */ @@ -2221,7 +2221,7 @@ decorateType (ast * tree) /*----------------------------*/ /* ++/-- operation */ /*----------------------------*/ - case INC_OP: /* increment operator unary so left only */ + case INC_OP: case DEC_OP: { sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree)); @@ -4985,18 +4985,28 @@ void ast_print (ast * tree, FILE *outfile, int indent) /*----------------------------*/ /* ++/-- operation */ /*----------------------------*/ - case INC_OP: /* incerement operator unary so left only */ + case INC_OP: + if (tree->left) + fprintf(outfile,"post-"); + else + fprintf(outfile,"pre-"); fprintf(outfile,"INC_OP (%p) type (",tree); printTypeChain(tree->ftype,outfile); fprintf(outfile,")\n"); - ast_print(tree->left,outfile,indent+2); + ast_print(tree->left,outfile,indent+2); /* postincrement case */ + ast_print(tree->right,outfile,indent+2); /* preincrement case */ return ; case DEC_OP: + if (tree->left) + fprintf(outfile,"post-"); + else + fprintf(outfile,"pre-"); fprintf(outfile,"DEC_OP (%p) type (",tree); printTypeChain(tree->ftype,outfile); fprintf(outfile,")\n"); - ast_print(tree->left,outfile,indent+2); + ast_print(tree->left,outfile,indent+2); /* postdecrement case */ + ast_print(tree->right,outfile,indent+2); /* predecrement case */ return ; /*------------------------------------------------------------------*/ diff --git a/src/SDCCicode.c b/src/SDCCicode.c index eef790d2..99996df9 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2226,7 +2226,7 @@ geniCodeArray (operand * left, operand * right,int lvl) { iCode *ic; sym_link *ltype = operandType (left); - + if (IS_PTR (ltype)) { if (IS_PTR (ltype->next) && left->isaddr) @@ -2258,6 +2258,7 @@ geniCodeArray (operand * left, operand * right,int lvl) IC_RESULT (ic)->isaddr = (!IS_AGGREGATE (ltype->next)); ADDTOCHAIN (ic); + return IC_RESULT (ic); } @@ -2348,7 +2349,7 @@ geniCodePostInc (operand * op) /* geniCodePreInc - generate code for preIncrement */ /*-----------------------------------------------------------------*/ operand * -geniCodePreInc (operand * op) +geniCodePreInc (operand * op, bool lvalue) { iCode *ic; sym_link *optype = operandType (op); @@ -2374,8 +2375,11 @@ geniCodePreInc (operand * op) IC_RESULT (ic) = result = newiTempOperand (roptype, 0); ADDTOCHAIN (ic); - - return geniCodeAssign (op, result, 0); + (void) geniCodeAssign (op, result, 0); + if (lvalue) + return op; + else + return result; } /*-----------------------------------------------------------------*/ @@ -2428,7 +2432,7 @@ geniCodePostDec (operand * op) /* geniCodePreDec - generate code for pre decrement */ /*-----------------------------------------------------------------*/ operand * -geniCodePreDec (operand * op) +geniCodePreDec (operand * op, bool lvalue) { iCode *ic; sym_link *optype = operandType (op); @@ -2454,8 +2458,11 @@ geniCodePreDec (operand * op) IC_RESULT (ic) = result = newiTempOperand (roptype, 0); ADDTOCHAIN (ic); - - return geniCodeAssign (op, result, 0); + (void) geniCodeAssign (op, result, 0); + if (lvalue) + return op; + else + return result; } @@ -3612,13 +3619,13 @@ ast2iCode (ast * tree,int lvl) if (left) return geniCodePostInc (left); else - return geniCodePreInc (right); + return geniCodePreInc (right, tree->lvalue); case DEC_OP: /* decrement operator */ if (left) return geniCodePostDec (left); else - return geniCodePreDec (right); + return geniCodePreDec (right, tree->lvalue); case '&': /* bitwise and or address of operator */ if (right)