added :-)
[fw/sdcc] / src / SDCCast.c
index fae7603b018357613382957213e2ce2a961a3baf..c50f127d8ce03256b84ece9276cc47bccfc5f989 100644 (file)
@@ -78,7 +78,7 @@ newAst_ (unsigned type)
   ex = Safe_alloc ( sizeof (ast));
 
   ex->type = type;
-  ex->lineno = (noLineno ? oldLineno : yylineno);
+  ex->lineno = (noLineno ? oldLineno : mylineno);
   ex->filename = currFname;
   ex->level = NestLevel;
   ex->block = currBlockno;
@@ -110,14 +110,6 @@ newAst_LINK (sym_link * val)
   return ex;
 }
 
-ast *
-newAst_STMNT (unsigned val)
-{
-  ast *ex = newAst_ (EX_STMNT);
-  ex->opval.stmnt = val;
-  return ex;
-}
-
 /*-----------------------------------------------------------------*/
 /* newNode - creates a new node                                    */
 /*-----------------------------------------------------------------*/
@@ -1287,9 +1279,12 @@ bool constExprTree (ast *cexpr) {
       if (constExprTree(cexpr->left) && constExprTree(cexpr->right)) {
        return TRUE;
       }
+      return FALSE;
+    case EX_OPERAND:
+      return IS_CONSTANT(operandType(cexpr->opval.oprnd));
     }
   return FALSE;
-}  
+}
     
 /*-----------------------------------------------------------------*/
 /* constExprValue - returns the value of a constant expression     */
@@ -2002,7 +1997,7 @@ decorateType (ast * tree)
     if (IS_AST_OP(tree) &&
        (tree->opval.op == CAST || tree->opval.op == '=') &&
        (getSize(LTYPE(tree)) > getSize(RTYPE(tree))) &&
-       (getSize(RTYPE(tree)) < INTSIZE)) {
+       (getSize(RTYPE(tree)) < (unsigned) INTSIZE)) {
       // this is a cast/assign to a bigger type
       if (IS_AST_OP(tree->right) &&
          IS_INTEGRAL(tree->right->ftype) &&
@@ -2786,10 +2781,10 @@ decorateType (ast * tree)
                      tree->right = NULL;
                      TTYPE (tree) = tree->opval.val->type;
                      tree->values.literalFromCast = 1;
-             } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) && 
+             } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) &&
                         ((int)floatFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */  {
                      sym_link *rest = LTYPE(tree)->next;
-                     werror(W_LITERAL_GENERIC);                      
+                     werror(W_LITERAL_GENERIC);
                      TTYPE(tree) = newLink(DECLARATOR);
                      DCL_TYPE(TTYPE(tree)) = FPOINTER;
                      TTYPE(tree)->next = rest;
@@ -2808,7 +2803,7 @@ decorateType (ast * tree)
       /* if pointer to struct then check names */
       if (IS_PTR(LTYPE(tree)) && IS_STRUCT(LTYPE(tree)->next) &&
          IS_PTR(RTYPE(tree)) && IS_STRUCT(RTYPE(tree)->next) &&
-         strcmp(SPEC_STRUCT(LETYPE(tree))->tag,SPEC_STRUCT(RETYPE(tree))->tag)) 
+         strcmp(SPEC_STRUCT(LETYPE(tree))->tag,SPEC_STRUCT(RETYPE(tree))->tag))
        {
          werror(W_CAST_STRUCT_PTR,SPEC_STRUCT(RETYPE(tree))->tag,
                 SPEC_STRUCT(LETYPE(tree))->tag);
@@ -2999,6 +2994,9 @@ decorateType (ast * tree)
                case V_STRUCT:
                    typeofv = TYPEOF_STRUCT;
                    break;
+               case V_BITFIELD:
+                   typeofv = TYPEOF_BITFIELD;
+                   break;
                case V_BIT:
                    typeofv = TYPEOF_BIT;
                    break;
@@ -3232,7 +3230,6 @@ decorateType (ast * tree)
        {
          werror (E_TYPE_MISMATCH, "assignment", " ");
          printFromToType(RTYPE(tree),LTYPE(tree));
-         //goto errorTreeReturn;
        }
 
       /* if the left side of the tree is of type void
@@ -3283,12 +3280,15 @@ decorateType (ast * tree)
       if ((options.stackAuto || IFFUNC_ISREENT (LTYPE (tree))) && 
          !IFFUNC_ISBUILTIN(LTYPE(tree)))
        {
-         //FUNC_ARGS(tree->left->ftype) = 
-         //reverseVal (FUNC_ARGS(tree->left->ftype));
          reverseParms (tree->right);
        }
 
-      TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)->next);
+      if (IS_CODEPTR(LTYPE(tree))) {
+       TTYPE(tree) = LTYPE(tree)->next->next;
+      } else {
+       TTYPE(tree) = LTYPE(tree)->next;
+      }
+      TETYPE (tree) = getSpec (TTYPE (tree));
       return tree;
 
       /*------------------------------------------------------------------*/
@@ -3330,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;
        }
 
@@ -4318,7 +4318,7 @@ createFunction (symbol * name, ast * body)
       addSymChain (name);
       allocVariables (name);
     }
-  name->lastLine = yylineno;
+  name->lastLine = mylineno;
   currFunc = name;
 
   /* set the stack pointer */
@@ -4507,11 +4507,14 @@ void ast_print (ast * tree, FILE *outfile, int indent)
        /* just get the type        */
        if (tree->type == EX_VALUE) {
 
-               if (IS_LITERAL (tree->opval.val->etype)) {                      
-                       fprintf(outfile,"CONSTANT (%p) value = %d, 0x%x, %g", tree,
-                               (int) floatFromVal(tree->opval.val),
-                               (int) floatFromVal(tree->opval.val),
-                               floatFromVal(tree->opval.val));
+               if (IS_LITERAL (tree->opval.val->etype)) {
+                       fprintf(outfile,"CONSTANT (%p) value = ", tree);
+                       if (SPEC_USIGN (tree->opval.val->etype))
+                               fprintf(outfile,"%u", (TYPE_UDWORD) floatFromVal(tree->opval.val));
+                       else
+                               fprintf(outfile,"%d", (TYPE_DWORD) floatFromVal(tree->opval.val));
+                       fprintf(outfile,", 0x%x, %g", (TYPE_UDWORD) floatFromVal(tree->opval.val),
+                                                     floatFromVal(tree->opval.val));
                } else if (tree->opval.val->sym) {
                        /* if the undefined flag is set then give error message */
                        if (tree->opval.val->sym->undefined) {