X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCast.c;h=e21105ca710c613f11c4dcd0f8b50945e006bf64;hb=0694926e60ec83b31f87590e601f7e0d8f86c512;hp=354a70b2e99e0dbed33c6c9ddf7594e1ebe3f3f2;hpb=c34cf61917860a821a4631edda334443633805e7;p=fw%2Fsdcc diff --git a/src/SDCCast.c b/src/SDCCast.c index 354a70b2..e21105ca 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 */ /*-----------------------------------------------------------------*/ @@ -2196,6 +2242,10 @@ decorateType (ast * tree) break; } + /* This breaks with extern declarations, bitfields, and perhaps other */ + /* cases (gcse). Let's leave this optimization disabled for now and */ + /* ponder if there's a safe way to do this. -- EEP */ + #if 0 if (IS_ADDRESS_OF_OP (tree->left) && IS_AST_SYM_VALUE(tree->left->left) && SPEC_ABSA (AST_SYMBOL (tree->left->left)->etype)) { @@ -2228,7 +2278,8 @@ decorateType (ast * tree) tree->left = NULL; tree->right = NULL; } - + #endif + return tree; /*------------------------------------------------------------------*/ @@ -2337,7 +2388,7 @@ decorateType (ast * tree) goto errorTreeReturn; } - if (SPEC_SCLS (tree->left->etype) == S_REGISTER) + if (LETYPE(tree) && SPEC_SCLS (tree->left->etype) == S_REGISTER) { werror (E_ILLEGAL_ADDR, "address of register variable"); goto errorTreeReturn; @@ -2360,7 +2411,9 @@ decorateType (ast * tree) werror (E_LVALUE_REQUIRED, "address of"); goto errorTreeReturn; } - if (SPEC_SCLS (tree->left->etype) == S_CODE) + if (!LETYPE (tree)) + DCL_TYPE (p) = POINTER; + else if (SPEC_SCLS (tree->left->etype) == S_CODE) DCL_TYPE (p) = CPOINTER; else if (SPEC_SCLS (tree->left->etype) == S_XDATA) DCL_TYPE (p) = FPOINTER; @@ -3539,11 +3592,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; @@ -5648,3 +5701,29 @@ void PA(ast *t) { ast_print(t,stdout,0); } + + + +/*-----------------------------------------------------------------*/ +/* astErrors : returns non-zero if errors present in tree */ +/*-----------------------------------------------------------------*/ +int astErrors(ast *t) +{ + int errors=0; + + if (t) + { + if (t->isError) + errors++; + + if (t->type == EX_VALUE + && t->opval.val->sym + && t->opval.val->sym->undefined) + errors++; + + errors += astErrors(t->left); + errors += astErrors(t->right); + } + + return errors; +}