the real constExprTree()
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 24 Dec 2001 15:20:35 +0000 (15:20 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 24 Dec 2001 15:20:35 +0000 (15:20 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1736 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
src/SDCCast.h
src/SDCCglue.c
support/Util/SDCCerr.c

index 5b9eb78cadacf925218370db5729d3a7ce9106f8..c121d7c2081ee3ff6eecb3b3867a77fb7ffd779c 100644 (file)
@@ -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);
index 69f95c0ad0d0c64572287c3788aab3c997c49dcd..31a12aceed63d2b62808a7a46a51f0ea9bb21248 100644 (file)
@@ -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 *);
index b1c6751ee96f59f1dedaf2f7de917ac396062b5a..6f89cb01db600a67b5fc981255b6ae4edcead1cf 100644 (file)
@@ -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) &&
index f40432d9e0f444af7b275fdf10973cf103511aee..e28cb9aa9612d6f8bb68f52886b30f177db0575a 100644 (file)
@@ -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" },