From: johanknol Date: Sun, 23 Dec 2001 15:06:34 +0000 (+0000) Subject: fixed the remainder of bug #485513 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=c1156eac66b833f3c65dc82c3e92bd21004e2150;p=fw%2Fsdcc fixed the remainder of bug #485513 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1723 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCast.c b/src/SDCCast.c index 26f59d09..69e8b026 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -1146,6 +1146,44 @@ processBlockVars (ast * tree, int *stack, int action) return tree; } +/*-------------------------------------------------------------*/ +/* constExprTree - returns TRUE if this tree is a constant */ +/* expression */ +/*-------------------------------------------------------------*/ +bool constExprTree (ast *cexpr) { + + if (!cexpr) { + return TRUE; + } + + cexpr = decorateType (resolveSymbols (cexpr)); + + switch (cexpr->type) + { + case EX_VALUE: + return (IS_AST_LIT_VALUE(cexpr)); + case EX_LINK: + werror (E_INTERNAL_ERROR, __FILE__, __LINE__, + "unexpected link in expression tree\n"); + return FALSE; + case EX_OP: + if (cexpr->opval.op==CAST) { + // jwk: cast ignored, maybe we should throw a warning here + return constExprTree(cexpr->right); + } + if (cexpr->opval.op=='&') { + return TRUE; + } + if (cexpr->opval.op==CALL || cexpr->opval.op==PCALL) { + return FALSE; + } + if (constExprTree(cexpr->left) && constExprTree(cexpr->right)) { + return TRUE; + } + } + return FALSE; +} + /*-----------------------------------------------------------------*/ /* constExprValue - returns the value of a constant expression */ /* or NULL if it is not a constant expression */ diff --git a/src/SDCCast.h b/src/SDCCast.h index 1504f69e..7620e47f 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -198,6 +198,7 @@ ast *createDo (symbol *, symbol *, symbol *, ast *, ast *); ast *createFor (symbol *, symbol *, symbol *, symbol *, ast *, ast *, ast *, ast *); void eval2icode (ast *); value *constExprValue (ast *, int); +bool constExprTree (ast *); symbol *funcOfType (char *, sym_link *, sym_link *, int, int); symbol * funcOfTypeVarg (char *, char * , int , char **); ast *initAggregates (symbol *, initList *, ast *); diff --git a/src/SDCCglue.c b/src/SDCCglue.c index bb4e41b6..e0d0619a 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -259,12 +259,20 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) decorateType (resolveSymbols (list2expr (sym->ival)))); } codeOutFile = statsg->oFile; - allocInfo = 0; - - // set ival's lineno to where the symbol was defined - if (ival) ival->lineno=sym->lineDef; - eBBlockFromiCode (iCodeFromAst (ival)); - allocInfo = 1; + + if (ival) { + // set ival's lineno to where the symbol was defined + lineno=ival->lineno=sym->lineDef; + + // check if this is a constant expression + if (constExprTree(ival->right)) { + allocInfo = 0; + eBBlockFromiCode (iCodeFromAst (ival)); + allocInfo = 1; + } else { + werror (E_CONST_EXPECTED, "found expression"); + } + } } /* if the ival is a symbol assigned to an aggregate, @@ -559,7 +567,11 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, FILE * oFile) werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef); } - val = list2val (ilist); + if (!(val = list2val (ilist))) { + // assuming a warning has been thrown + val=constVal("0"); + } + if (val->type != type) { val = valCastLiteral(type, floatFromVal(val)); }