1) fixed problem in global structure init
[fw/sdcc] / src / SDCCast.c
index 99d536cfaab8e9f9228a60a8e0b9bc85e7b0d518..f2321e04ddaab8f19f540773619aca83a806af1e 100644 (file)
@@ -447,7 +447,7 @@ symbol *funcOfType (char *name, link *type, link *argType,
                    int nArgs , int rent)
 {
     symbol *sym;    
-       
+    int argStack = 0;  
     /* create the symbol */
     sym = newSymbol (name,0);
        
@@ -458,6 +458,7 @@ symbol *funcOfType (char *name, link *type, link *argType,
        args = sym->args = newValue();
 
        while (nArgs--) {
+           argStack += getSize(type);
            args->type = copyLinkChain(argType);
            args->etype = getSpec(args->type);
            if (!nArgs)
@@ -476,6 +477,7 @@ symbol *funcOfType (char *name, link *type, link *argType,
     /* save it */
     addSymChain(sym);
     sym->cdef = 1;
+    sym->argStack = (rent ? argStack : 0);
     allocVariables (sym);
     return sym;
     
@@ -593,7 +595,7 @@ ast *createIvalType ( ast *sym,link  *type, initList *ilist)
        ilist =  ilist->init.deep  ;
     
     iExpr = decorateType(resolveSymbols(list2expr(ilist)));
-    return newNode('=',sym,iExpr);
+    return decorateType(newNode('=',sym,iExpr));
 }
 
 /*-----------------------------------------------------------------*/
@@ -620,8 +622,8 @@ ast *createIvalStruct (ast *sym,link *type,initList *ilist)
        if (!iloop)
            break;
        sflds->implicit = 1;
-       lAst = decorateType(resolveSymbols(newNode('.',sym,
-                                                  newAst(EX_VALUE,symbolVal(sflds)))));
+       lAst = newNode(PTR_OP,newNode('&',sym,NULL),newAst(EX_VALUE,symbolVal(sflds)));
+       lAst = decorateType(resolveSymbols(lAst));
        rast = createIval (lAst, sflds->type, iloop,rast);
     }
     return rast ;
@@ -786,7 +788,7 @@ ast  *createIval  (ast *sym, link *type, initList *ilist, ast *wid)
 }
 
 /*-----------------------------------------------------------------*/
-/* initAggregates - initialises aggregate variables with initv */
+/* initAggregates - initialises aggregate variables with initv     */
 /*-----------------------------------------------------------------*/
 ast *initAggregates ( symbol *sym, initList *ival, ast *wid)
 {
@@ -1224,7 +1226,12 @@ bool isConformingBody (ast *pbody, symbol *sym, ast *body)
                return FALSE;
            else
                return isConformingBody(pbody->left,sym,body) ;
-       } 
+       } else {
+           if (astHasSymbol(pbody->left,sym) ||
+               astHasSymbol(pbody->right,sym))
+               return FALSE;
+       }
+
        
        /*------------------------------------------------------------------*/
     case  '|':
@@ -1515,7 +1522,7 @@ ast *decorateType (ast *tree)
                  TTYPE(tree) = TETYPE(tree) =
                    tree->opval.val->type = tree->opval.val->sym->type = 
                    tree->opval.val->etype = tree->opval.val->sym->etype = 
-                   copyLinkChain(intType);
+                   copyLinkChain(INTTYPE);
                }
                else {
                  
@@ -1761,7 +1768,10 @@ ast *decorateType (ast *tree)
                    if (SPEC_SCLS(tree->left->etype) == S_IDATA)
                        DCL_TYPE(p) = IPOINTER ;
                    else
-                       DCL_TYPE(p) = POINTER ;
+                       if (SPEC_SCLS(tree->left->etype) == S_EEPROM)
+                           DCL_TYPE(p) = EEPPOINTER ;
+                       else
+                           DCL_TYPE(p) = POINTER ;
 
        if (IS_AST_SYM_VALUE(tree->left)) {
            AST_SYMBOL(tree->left)->addrtaken = 1;
@@ -2208,7 +2218,11 @@ ast *decorateType (ast *tree)
            return tree;
        }
        LRVAL(tree) = RRVAL(tree) = 1;
-       COPYTYPE(TTYPE(tree),TETYPE(tree),LTYPE(tree));
+       if (IS_LITERAL(LTYPE(tree)) && !IS_LITERAL(RTYPE(tree))) {          
+           COPYTYPE(TTYPE(tree),TETYPE(tree),RTYPE(tree));     
+       } else {
+           COPYTYPE(TTYPE(tree),TETYPE(tree),LTYPE(tree));
+       }
        return tree ;
         
        /*------------------------------------------------------------------*/
@@ -2773,7 +2787,7 @@ ast *backPatchLabels (ast *tree, symbol *trueLabel, symbol *falseLabel )
     
     /* change not */
     if (IS_NOT(tree)) {
-       tree->left = backPatchLabels (tree->left,trueLabel,falseLabel);
+       tree->left = backPatchLabels (tree->left,falseLabel,trueLabel);
        
        /* if the left is already a IFX */
        if ( ! IS_IFX(tree->left) ) 
@@ -3076,7 +3090,7 @@ ast *createFor ( symbol *trueLabel, symbol *continueLabel ,
     /* vanilla for statement */
     condExpr = backPatchLabels(condExpr,trueLabel,falseLabel);
     
-    if (!IS_IFX(condExpr)) 
+    if (condExpr && !IS_IFX(condExpr)) 
        condExpr = newIfxNode(condExpr,trueLabel,falseLabel);