missing return values is a warning now
[fw/sdcc] / src / SDCCast.c
index 093a90435dbc5b5ec61c79d1989326f0ffa7c3ec..91a4f81e08fe35e461a888234810291af6c47aa9 100644 (file)
@@ -47,7 +47,7 @@ int labelKey = 1;
 
 int noLineno = 0;
 int noAlloc = 0;
-symbol *currFunc;
+symbol *currFunc=NULL;
 static ast *createIval (ast *, sym_link *, initList *, ast *);
 static ast *createIvalCharPtr (ast *, sym_link *, ast *);
 static ast *optimizeCompare (ast *);
@@ -448,7 +448,7 @@ resolveSymbols (ast * tree)
          /* mark it as returning an int     */
          if (tree->funcName)
            {
-             tree->opval.val->sym->type = newLink ();
+             tree->opval.val->sym->type = newLink (DECLARATOR);
              DCL_TYPE (tree->opval.val->sym->type) = FUNCTION;
              tree->opval.val->sym->type->next =
                tree->opval.val->sym->etype = newIntLink ();
@@ -501,7 +501,7 @@ funcOfType (char *name, sym_link * type, sym_link * argType,
   sym = newSymbol (name, 0);
 
   /* setup return value */
-  sym->type = newLink ();
+  sym->type = newLink (DECLARATOR);
   DCL_TYPE (sym->type) = FUNCTION;
   sym->type->next = copyLinkChain (type);
   sym->etype = getSpec (sym->type);
@@ -545,7 +545,7 @@ funcOfTypeVarg (char *name, char * rtype, int nArgs , char **atypes)
     sym = newSymbol (name, 0);
     
     /* setup return value */
-    sym->type = newLink ();
+    sym->type = newLink (DECLARATOR);
     DCL_TYPE (sym->type) = FUNCTION;
     sym->type->next = typeFromStr(rtype);
     sym->etype = getSpec (sym->type);
@@ -1211,14 +1211,14 @@ processBlockVars (ast * tree, int *stack, int action)
       ast *autoInit;
 
       if (action == ALLOCATE)
-       {
+        {
          *stack += allocVariables (tree->values.sym);
          autoInit = gatherAutoInit (tree->values.sym);
-
+       
          /* if there are auto inits then do them */
          if (autoInit)
            tree->left = newNode (NULLOP, autoInit, tree->left);
-       }
+        }
       else                     /* action is deallocate */
        deallocLocal (tree->values.sym);
     }
@@ -1275,7 +1275,7 @@ bool constExprTree (ast *cexpr) {
        return constExprTree(cexpr->right);
       }
       if (cexpr->opval.op==CAST) {
-       // jwk: cast ignored, maybe we should throw a warning here
+       // cast ignored, maybe we should throw a warning here?
        return constExprTree(cexpr->right);
       }
       if (cexpr->opval.op=='&') { 
@@ -2061,6 +2061,9 @@ decorateType (ast * tree)
        }
       RRVAL (tree) = 1;
       COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree)->next);
+      if (IS_PTR(LTYPE(tree))) {
+       SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree));
+      }
       return tree;
 
       /*------------------------------------------------------------------*/
@@ -2141,7 +2144,7 @@ decorateType (ast * tree)
       {
        sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree));
        COPYTYPE (TTYPE (tree), TETYPE (tree), ltc);
-       if (!tree->initMode && IS_CONSTANT (TTYPE (tree)))
+       if (!tree->initMode && IS_CONSTANT(TETYPE(tree)))
          werror (E_CODE_WRITE, tree->opval.op==INC_OP ? "++" : "--");
 
        if (tree->right)
@@ -2205,8 +2208,7 @@ decorateType (ast * tree)
       /*----------------------------*/
       /*  address of                */
       /*----------------------------*/
-      p = newLink ();
-      p->class = DECLARATOR;
+      p = newLink (DECLARATOR);
       /* if bit field then error */
       if (IS_BITVAR (tree->left->etype))
        {
@@ -2238,7 +2240,10 @@ decorateType (ast * tree)
          goto errorTreeReturn;
        }
       if (SPEC_SCLS (tree->left->etype) == S_CODE)
-       DCL_TYPE (p) = CPOINTER;
+       {
+         DCL_TYPE (p) = CPOINTER;
+         DCL_PTR_CONST (p) = port->mem.code_ro;
+       }
       else if (SPEC_SCLS (tree->left->etype) == S_XDATA)
        DCL_TYPE (p) = FPOINTER;
       else if (SPEC_SCLS (tree->left->etype) == S_XSTACK)
@@ -2261,6 +2266,8 @@ decorateType (ast * tree)
       p->next = LTYPE (tree);
       TTYPE (tree) = p;
       TETYPE (tree) = getSpec (TTYPE (tree));
+      DCL_PTR_CONST (p) = SPEC_CONST (TETYPE (tree));   
+      DCL_PTR_VOLATILE (p) = SPEC_VOLATILE (TETYPE (tree)); 
       LLVAL (tree) = 1;
       TLVAL (tree) = 1;
       return tree;
@@ -2390,9 +2397,9 @@ decorateType (ast * tree)
              werror (E_LVALUE_REQUIRED, "pointer deref");
              goto errorTreeReturn;
            }
-         TTYPE (tree) = copyLinkChain ((IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree))) ?
-                                       LTYPE (tree)->next : NULL);
+         TTYPE (tree) = copyLinkChain (LTYPE (tree)->next);
          TETYPE (tree) = getSpec (TTYPE (tree));
+         SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree));
          return tree;
        }
 
@@ -2556,7 +2563,7 @@ decorateType (ast * tree)
              return tree;
            }
          LRVAL (tree) = 1;
-         TTYPE (tree) = LTYPE (tree);
+         TETYPE(tree) = getSpec (TTYPE (tree) = LTYPE (tree));
          return tree;
        }
 
@@ -2783,7 +2790,7 @@ decorateType (ast * tree)
                         ((int)floatFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */  {
                      sym_link *rest = LTYPE(tree)->next;
                      werror(W_LITERAL_GENERIC);                      
-                     TTYPE(tree) = newLink();
+                     TTYPE(tree) = newLink(DECLARATOR);
                      DCL_TYPE(TTYPE(tree)) = FPOINTER;
                      TTYPE(tree)->next = rest;
                      tree->left->opval.lnk = TTYPE(tree);
@@ -2923,7 +2930,7 @@ decorateType (ast * tree)
        }
       /* if unsigned value < 0  then always false */
       /* if (unsigned value) > 0 then (unsigned value) */
-      if (SPEC_USIGN(LETYPE(tree)) && IS_LITERAL(RTYPE(tree)) && 
+      if (SPEC_USIGN(LETYPE(tree)) && IS_LITERAL(RTYPE(tree))  && 
          ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0) {
 
          if (tree->opval.op == '<') {
@@ -3117,7 +3124,7 @@ decorateType (ast * tree)
       RRVAL (tree) = 1;
       TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree));
 
-      if (!tree->initMode && IS_CONSTANT (LTYPE (tree)))
+      if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
        werror (E_CODE_WRITE, "&= or |= or ^= or >>= or <<=");
 
       if (LRVAL (tree))
@@ -3152,7 +3159,7 @@ decorateType (ast * tree)
                               computeType (LTYPE (tree),
                                            RTYPE (tree)));
 
-      if (!tree->initMode && IS_CONSTANT (LTYPE (tree)))
+      if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
        werror (E_CODE_WRITE, "-=");
 
       if (LRVAL (tree))
@@ -3193,7 +3200,7 @@ decorateType (ast * tree)
                               computeType (LTYPE (tree),
                                            RTYPE (tree)));
 
-      if (!tree->initMode && IS_CONSTANT (LTYPE (tree)))
+      if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
        werror (E_CODE_WRITE, "+=");
 
       if (LRVAL (tree))
@@ -3241,7 +3248,7 @@ decorateType (ast * tree)
       RRVAL (tree) = 1;
       LLVAL (tree) = 1;
       if (!tree->initMode ) {
-       if (IS_CONSTANT (LTYPE (tree)))
+       if ((IS_SPEC(LETYPE(tree)) && IS_CONSTANT (LETYPE (tree))))
          werror (E_CODE_WRITE, "=");
       }
       if (LRVAL (tree))
@@ -3323,7 +3330,7 @@ decorateType (ast * tree)
 
       if (!IS_VOID (currFunc->type->next) && tree->right == NULL)
        {
-         werror (E_VOID_FUNC, currFunc->name);
+         werror (W_VOID_FUNC, currFunc->name);
          goto errorTreeReturn;
        }
 
@@ -3533,12 +3540,12 @@ createBlock (symbol * decl, ast * body)
   ast *ex;
 
   /* if the block has nothing */
-  if (!body)
+  if (!body && !decl)
     return NULL;
 
   ex = newNode (BLOCK, NULL, body);
   ex->values.sym = decl;
-
+  
   ex->right = ex->right;
   ex->level++;
   ex->lineno = 0;
@@ -4390,6 +4397,7 @@ skipall:
 
   /* dealloc the block variables */
   processBlockVars (body, &stack, DEALLOCATE);
+  outputDebugStackSymbols();
   /* deallocate paramaters */
   deallocParms (FUNC_ARGS(name->type));
 
@@ -4404,8 +4412,8 @@ skipall:
   addSet (&operKeyReset, name);
   applyToSet (operKeyReset, resetParmKey);
 
-  if (options.debug)
-    cdbStructBlock (1, cdbFile);
+  if (options.debug)    
+    cdbStructBlock(1);
 
   cleanUpLevel (LabelTab, 0);
   cleanUpBlock (StructTab, 1);
@@ -4451,7 +4459,7 @@ void ast_print (ast * tree, FILE *outfile, int indent)
                value *args=FUNC_ARGS(tree->left->opval.val->type);
                fprintf(outfile,"FUNCTION (%s=%p) type (", 
                        tree->left->opval.val->name, tree);
-               printTypeChain (tree->ftype,outfile);
+               printTypeChain (tree->left->opval.val->type->next,outfile);
                fprintf(outfile,") args (");
                do {
                  if (arg) {