fixed the recent bug that disabled the local structure initialisation.
[fw/sdcc] / src / SDCCast.c
index c7a3538523c238a890d9510da329cb729398ba3e..89b365c48ffe9104ca8aa360620cdf9ea4129c2c 100644 (file)
@@ -610,7 +610,6 @@ processParms (ast * func,
              int *parmNumber,
              bool rightmost)
 {
-  int castError=0;
   sym_link *fetype = func->etype;
 
   /* if none of them exist */
@@ -746,35 +745,7 @@ processParms (ast * func,
 
 
   /* the parameter type must be at least castable */
-  if (compareType (defParm->type, actParm->ftype) == 0)
-    {
-      castError++;
-    }
-
-#ifdef JWK20010916
-  if (!IS_SPEC(defParm->type) && !IS_SPEC(actParm->ftype)) {
-    // now we have two pointers, check if they point to the same
-    sym_link *dtype=defParm->type, *atype=actParm->ftype;
-    do {
-      dtype=dtype->next;
-      atype=atype->next;
-      if (
-         (dtype->next && !atype->next) ||
-         (!dtype->next && atype->next) ||
-         compareType (dtype, atype)!=1) {
-       castError++;
-      }
-    } while (dtype->next && atype->next);
-    if (IS_SPEC(dtype) && IS_SPEC(atype)) {
-      // ok so far, we have two etypes, they must have the same SCLASS
-      if (SPEC_SCLS(dtype)!=SPEC_SCLS(atype)) {
-       castError++;
-      }
-    }
-  }
-#endif
-
-  if (castError) {
+  if (compareType (defParm->type, actParm->ftype) == 0) {
     werror (W_INCOMPAT_CAST);
     fprintf (stderr, "type --> '");
     printTypeChain (actParm->ftype, stderr);
@@ -1250,6 +1221,7 @@ processBlockVars (ast * tree, int *stack, int action)
 
 /*-----------------------------------------------------------------*/
 /* constExprValue - returns the value of a constant expression     */
+/*                  or NULL if it is not a constant expression     */
 /*-----------------------------------------------------------------*/
 value *
 constExprValue (ast * cexpr, int check)
@@ -2019,10 +1991,10 @@ decorateType (ast * tree)
 
   switch (tree->opval.op)
     {
-/*------------------------------------------------------------------*/
-/*----------------------------*/
-      /*        array node          */
-/*----------------------------*/
+           /*------------------------------------------------------------------*/
+           /*----------------------------*/
+           /*        array node          */
+           /*----------------------------*/
     case '[':
 
       /* determine which is the array & which the index */
@@ -2061,10 +2033,10 @@ decorateType (ast * tree)
       }
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*      struct/union          */
-/*----------------------------*/
+      /*----------------------------*/
     case '.':
       /* if this is not a structure */
       if (!IS_STRUCT (LTYPE (tree)))
@@ -2078,10 +2050,10 @@ decorateType (ast * tree)
       TETYPE (tree) = getSpec (TTYPE (tree));
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*    struct/union pointer    */
-/*----------------------------*/
+      /*----------------------------*/
     case PTR_OP:
       /* if not pointer to a structure */
       if (!IS_PTR (LTYPE (tree)))
@@ -2746,10 +2718,10 @@ decorateType (ast * tree)
        }
       return tree;
 
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
       /*         casting            */
-/*----------------------------*/
+      /*----------------------------*/
     case CAST:                 /* change the type   */
       /* cannot cast to an aggregate type */
       if (IS_AGGREGATE (LTYPE (tree)))
@@ -2761,23 +2733,51 @@ decorateType (ast * tree)
       /* make sure the type is complete and sane */
       checkTypeSanity(LETYPE(tree), "(cast)");
 
+#if 1
       /* if the right is a literal replace the tree */
-      if (IS_LITERAL (RETYPE (tree)) && !IS_PTR (LTYPE (tree)))
-       {
-         tree->type = EX_VALUE;
-         tree->opval.val =
-           valCastLiteral (LTYPE (tree),
-                           floatFromVal (valFromType (RETYPE (tree))));
-         tree->left = NULL;
-         tree->right = NULL;
-         TTYPE (tree) = tree->opval.val->type;
-         tree->values.literalFromCast = 1;
-       }
-      else
-       {
-         TTYPE (tree) = LTYPE (tree);
-         LRVAL (tree) = 1;
-       }
+      if (IS_LITERAL (RETYPE (tree))) {
+             if (!IS_PTR (LTYPE (tree))) {
+                     tree->type = EX_VALUE;
+                     tree->opval.val =
+                             valCastLiteral (LTYPE (tree),
+                                             floatFromVal (valFromType (RETYPE (tree))));
+                     tree->left = NULL;
+                     tree->right = NULL;
+                     TTYPE (tree) = tree->opval.val->type;
+                     tree->values.literalFromCast = 1;
+             } 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);                      
+                     TTYPE(tree) = newLink();
+                     DCL_TYPE(TTYPE(tree)) = FPOINTER;
+                     TTYPE(tree)->next = rest;
+                     tree->left->opval.lnk = TTYPE(tree);
+                     LRVAL (tree) = 1;
+             } else {
+                     TTYPE (tree) = LTYPE (tree);
+                     LRVAL (tree) = 1;
+             }
+      } else {
+             TTYPE (tree) = LTYPE (tree);
+             LRVAL (tree) = 1;
+      }
+#else
+      /* if the right is a literal replace the tree */
+      if (IS_LITERAL (RETYPE (tree)) && !IS_PTR (LTYPE (tree))) {
+       tree->type = EX_VALUE;
+       tree->opval.val =
+         valCastLiteral (LTYPE (tree),
+                         floatFromVal (valFromType (RETYPE (tree))));
+       tree->left = NULL;
+       tree->right = NULL;
+       TTYPE (tree) = tree->opval.val->type;
+       tree->values.literalFromCast = 1;
+      } else {
+       TTYPE (tree) = LTYPE (tree);
+       LRVAL (tree) = 1;
+      }
+#endif
 
       TETYPE (tree) = getSpec (TTYPE (tree));