* as/mcs51/lkarea.c (lnkarea, lnkarea2): improved BSEG size calculation,
[fw/sdcc] / src / SDCCast.c
index 84a6c7f1bd914cc6cefe33102ed847ab8f729bc8..3cfdde6a9c2754ad7548ec87b4ead54003e04547 100644 (file)
@@ -573,7 +573,7 @@ funcOfType (char *name, sym_link * type, sym_link * argType,
     }
 
   /* save it */
-  addSymChain (sym);
+  addSymChain (&sym);
   sym->cdef = 1;
   allocVariables (sym);
   return sym;
@@ -613,7 +613,7 @@ funcOfTypeVarg (char *name, char * rtype, int nArgs , char **atypes)
     }
 
     /* save it */
-    addSymChain (sym);
+    addSymChain (&sym);
     sym->cdef = 1;
     allocVariables (sym);
     return sym;
@@ -1283,7 +1283,7 @@ stringToSymbol (value * val)
   if (noAlloc == 0)
     {
       /* allocate it */
-      addSymChain (sym);
+      addSymChain (&sym);
       allocVariables (sym);
     }
   sym->ival = NULL;
@@ -1533,6 +1533,8 @@ isLoopCountable (ast * initExpr, ast * condExpr, ast * loopExpr,
         }
 
     }
+  else
+    return FALSE;
 
   /* check loop expression is of the form <sym>++ */
   if (!IS_AST_OP (loopExpr))
@@ -3563,11 +3565,37 @@ decorateType (ast * tree, RESULT_TYPE resultType)
       if (IS_ADDRESS_OF_OP(tree->right)
           && IS_AST_SYM_VALUE (tree->right->left)
           && SPEC_ABSA (AST_SYMBOL (tree->right->left)->etype)) {
+        
+        symbol * sym = AST_SYMBOL (tree->right->left);
+        unsigned int gptype = 0;
+        unsigned int addr = SPEC_ADDR (sym->etype);
 
+        if (IS_GENPTR (LTYPE (tree)) && GPTRSIZE > FPTRSIZE)
+          {
+            switch (SPEC_SCLS (sym->etype))
+              {
+              case S_CODE:
+                gptype = GPTYPE_CODE;
+                break;
+              case S_XDATA:
+                gptype = GPTYPE_FAR;
+                break;
+              case S_DATA:
+              case S_IDATA:
+                gptype = GPTYPE_NEAR;
+                break;
+              case S_PDATA:
+                gptype = GPTYPE_XSTACK;
+                break;
+              default:
+                gptype = 0;
+              }
+            addr |= gptype << (8*(GPTRSIZE - 1));
+          }
+        
         tree->type = EX_VALUE;
         tree->opval.val =
-          valCastLiteral (LTYPE (tree),
-                          SPEC_ADDR (AST_SYMBOL (tree->right->left)->etype));
+          valCastLiteral (LTYPE (tree), addr);
         TTYPE (tree) = tree->opval.val->type;
         TETYPE (tree) = getSpec (TTYPE (tree));
         tree->left = NULL;
@@ -3933,7 +3961,8 @@ decorateType (ast * tree, RESULT_TYPE resultType)
 
     case ':':
       /* if they don't match we have a problem */
-      if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
+      if ((compareType (LTYPE (tree), RTYPE (tree)) == 0) &&
+          (compareType (RTYPE (tree), LTYPE (tree)) == 0))
         {
           werror (E_TYPE_MISMATCH, "conditional operator", " ");
           goto errorTreeReturn;
@@ -4149,8 +4178,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
         }
 
       /* require a function or pointer to function */
-      if (!IS_FUNC (LTYPE (tree))
-          && !(IS_CODEPTR (LTYPE (tree)) && IS_FUNC (LTYPE (tree)->next)))
+      if (!IS_FUNC (LTYPE (tree)) && !IS_FUNCPTR (LTYPE (tree)))
         {
           werrorfl (tree->filename, tree->lineno, E_FUNCTION_EXPECTED);
           goto errorTreeReturn;
@@ -4164,7 +4192,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
           sym_link *functype;      
           parmNumber = 1;
 
-          if (IS_CODEPTR(LTYPE(tree)))
+          if (IS_FUNCPTR (LTYPE (tree)))
             functype = LTYPE (tree)->next;
           else
             functype = LTYPE (tree);
@@ -5312,7 +5340,7 @@ createFunction (symbol * name, ast * body)
     }
   else
     {
-      addSymChain (name);
+      addSymChain (&name);
       allocVariables (name);
     }
   name->lastLine = mylineno;
@@ -5320,7 +5348,7 @@ createFunction (symbol * name, ast * body)
 
   /* set the stack pointer */
   stackPtr  = -port->stack.direction * port->stack.call_overhead;
-  xstackPtr = -port->stack.direction * port->stack.call_overhead;
+  xstackPtr = 0;
 
   if (IFFUNC_ISISR (name->type))
     stackPtr -= port->stack.direction * port->stack.isr_overhead;