From: johanknol Date: Mon, 24 Dec 2001 15:20:35 +0000 (+0000) Subject: the real constExprTree() X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=e66b24b02e50bd0b7ae4b8a2f2b7407a7f6ce32e;p=fw%2Fsdcc the real constExprTree() git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1736 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCast.c b/src/SDCCast.c index 5b9eb78c..c121d7c2 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -1162,12 +1162,27 @@ bool constExprTree (ast *cexpr) { switch (cexpr->type) { case EX_VALUE: - return (IS_AST_LIT_VALUE(cexpr)); + if (IS_AST_LIT_VALUE(cexpr)) { + // this is a literal + return TRUE; + } + if (IS_AST_SYM_VALUE(cexpr) && IS_FUNC(AST_SYMBOL(cexpr)->type)) { + // a function's address will never change + return TRUE; + } + return FALSE; case EX_LINK: werror (E_INTERNAL_ERROR, __FILE__, __LINE__, "unexpected link in expression tree\n"); return FALSE; case EX_OP: + if (cexpr->opval.op==ARRAYINIT) { + // this is a list of literals + return TRUE; + } + if (cexpr->opval.op=='=') { + return constExprTree(cexpr->right); + } if (cexpr->opval.op==CAST) { // jwk: cast ignored, maybe we should throw a warning here return constExprTree(cexpr->right); diff --git a/src/SDCCast.h b/src/SDCCast.h index 69f95c0a..31a12ace 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -198,6 +198,7 @@ ast *createFor (symbol *, symbol *, symbol *, symbol *, ast *, ast *, ast *, ast void eval2icode (ast *); value *constExprValue (ast *, int); bool constExprTree (ast *); +int setAstLineno (ast *, int); 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 b1c6751e..6f89cb01 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -260,7 +260,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) } codeOutFile = statsg->oFile; -#if 1 +#if 0 if (ival) { // set ival's lineno to where the symbol was defined lineno=ival->lineno=sym->lineDef; @@ -271,9 +271,9 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) #else if (ival) { // set ival's lineno to where the symbol was defined - lineno=ival->lineno=sym->lineDef; + setAstLineno (ival, lineno=sym->lineDef); // check if this is a constant expression - if (constExprTree(ival->right)) { + if (constExprTree(ival)) { allocInfo = 0; eBBlockFromiCode (iCodeFromAst (ival)); allocInfo = 1; @@ -391,10 +391,10 @@ initPointer (initList * ilist) (&some_struct)->element */ if (IS_AST_OP (expr->left) && expr->left->opval.op == PTR_OP && - IS_ADDRESS_OF_OP (expr->left->left)) - return valForStructElem (expr->left->left->left, - expr->left->right); - + IS_ADDRESS_OF_OP (expr->left->left)) { + return valForStructElem (expr->left->left->left, + expr->left->right); + } } /* case 3. (((char *) &a) +/- constant) */ if (IS_AST_OP (expr) && diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index f40432d9..e28cb9aa 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -311,7 +311,7 @@ struct { W_POSSBUG, ERROR_LEVEL_WARNING, "possible code generation error at line %d,\n" " send source to sandeep.dutta@usa.net" }, -{ E_INCOMPAT_PTYPES, ERROR_LEVEL_WARNING, +{ E_INCOMPAT_PTYPES, ERROR_LEVEL_ERROR, "pointer types incompatible " }, { W_UNKNOWN_MODEL, ERROR_LEVEL_WARNING, "unknown memory model at %s : %d" },