]> git.gag.com Git - fw/sdcc/commitdiff
fixed the remainder of bug #485513
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 23 Dec 2001 15:06:34 +0000 (15:06 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 23 Dec 2001 15:06:34 +0000 (15:06 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1723 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
src/SDCCast.h
src/SDCCglue.c

index 26f59d09957b9cb66d39ae3c9e8ed3a8456d7620..69e8b02696df0304435334cbf921c18d1fa8419f 100644 (file)
@@ -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     */
index 1504f69e54eb2ae32562aa02e989d2e4dbf00d75..7620e47f45f4a80185594826a9dc3115525627a6 100644 (file)
@@ -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 *);
index bb4e41b695da5fc509ade3d08e9e0f6fcdf38703..e0d0619a6eea9029e4ba5bc6e0fc9eae79ebf34d 100644 (file)
@@ -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));
        }