* src/SDCCast.c (processParams): added new type flow and restructured
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 31 Jan 2004 21:47:47 +0000 (21:47 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 31 Jan 2004 21:47:47 +0000 (21:47 +0000)
(gatherAutoInit): added new type flow
(addCast): cosmetic changes
(getLeftResultType): added new type flow for array indices, patch provided by Stas, see FR #877103
(decorateType): SDCC_NEWTYPEFLOW removed, new type flow is now standard; array index patch by Stas
* src/SDCCast.h: added prototype getResultTypeFromType()
* src/SDCCval.h,
* src/SDCCval.c (resolveIvalSym) (resolveIvalSym),
* src/pic/glue.c (pic14emitStaticSeg),
* src/pic16/glue.c (pic16emitStaticSeg),
* src/SDCCglue.c (emitRegularMap) (emitStaticSeg): added new type flow for initialization of symbols
* src/SDCCicode.c (geniCodeArray): removed warning W_ARRAY_BOUND
* support/Util/SDCCerr.h:
* support/Util/SDCCerr.c: replaced W_ARRAY_BOUND by W_IDX_OUT_OF_BOUNDS
* .version: bumped version number to 2.3.8

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3163 4a8a32a2-be11-0410-ad9d-d568d2c75423

12 files changed:
.version
ChangeLog
src/SDCCast.c
src/SDCCast.h
src/SDCCglue.c
src/SDCCicode.c
src/SDCCval.c
src/SDCCval.h
src/pic/glue.c
src/pic16/glue.c
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 00355e29d11ac4a7ee62410face3b0adb50201ac..bc4abe86dedf538f8c5783cf2cb2b7dcb5188deb 100644 (file)
--- a/.version
+++ b/.version
@@ -1 +1 @@
-2.3.7
+2.3.8
index 78338aa80bb90588bd8986a2f7ff20810fd5fa0e..2ed080b762ceedffc9a36313e9c000a5e706c3eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2004-01-31 Bernhard Held <bernhard AT bernhardheld.de>
+
+       * src/SDCCast.c (processParams): added new type flow and restructured
+       (gatherAutoInit): added new type flow
+       (addCast): cosmetic changes
+       (getLeftResultType): added new type flow for array indices, patch
+       provided by Stas, see FR #877103
+       (decorateType): SDCC_NEWTYPEFLOW removed, new type flow is now standard;
+       array index patch by Stas
+       * src/SDCCast.h: added prototype getResultTypeFromType()
+       * src/SDCCval.h,
+       * src/SDCCval.c (resolveIvalSym) (resolveIvalSym),
+       * src/pic/glue.c (pic14emitStaticSeg),
+       * src/pic16/glue.c (pic16emitStaticSeg),
+       * src/SDCCglue.c (emitRegularMap) (emitStaticSeg): added new type flow
+       for initialization of symbols
+       * src/SDCCicode.c (geniCodeArray): removed warning W_ARRAY_BOUND
+       * support/Util/SDCCerr.h:
+       * support/Util/SDCCerr.c: replaced W_ARRAY_BOUND by W_IDX_OUT_OF_BOUNDS
+       * .version: bumped version number to 2.3.8
+
 2004-01-30 Bernhard Held <bernhard AT bernhardheld.de>
 
        * support/regression/tests/libmullong.c: fixed for 64 bit hosts
index 55cfd9d29e298353f3a53d569b866726f7a282e2..559e82d5f3ae7785e75314bec407cbf2e4637b21 100644 (file)
@@ -644,24 +644,28 @@ reverseParms (ast * ptree)
 /* processParms  - makes sure the parameters are okay and do some  */
 /*                 processing with them                            */
 /*-----------------------------------------------------------------*/
-int 
-processParms (ast * func,
+static int
+processParms (ast *func,
              value *defParm,
-             ast * actParm,
-             int *parmNumber, // unused, although updated
+             ast *actParm,
+             int *parmNumber, /* unused, although updated */
              bool rightmost)
 {
+  RESULT_TYPE resultType;
+  
   /* if none of them exist */
   if (!defParm && !actParm)
     return 0;
 
-  if (defParm) {
-    if (getenv("DEBUG_SANITY")) {
-      fprintf (stderr, "processParms: %s ", defParm->name);
+  if (defParm)
+    {
+      if (getenv("DEBUG_SANITY"))
+        {
+          fprintf (stderr, "processParms: %s ", defParm->name);
+        }
+      /* make sure the type is complete and sane */
+      checkTypeSanity(defParm->etype, defParm->name);
     }
-    /* make sure the type is complete and sane */
-    checkTypeSanity(defParm->etype, defParm->name);
-  }
 
   /* if the function is being called via a pointer &   */
   /* it has not been defined a reentrant then we cannot */
@@ -676,8 +680,8 @@ processParms (ast * func,
   /* exist and this is not defined as a variable arg   */
   if (!defParm && actParm && !IFFUNC_HASVARARGS(func->ftype))
     {
-      //if (func->type==EX_VALUE && func->opval.val->sym->undefined)
-      //  return 1; /* Already gave them an undefined function error */
+      /* if (func->type==EX_VALUE && func->opval.val->sym->undefined) */
+      /*  return 1; *//* Already gave them an undefined function error */
       werror (E_TOO_MANY_PARMS);
       return 1;
     }
@@ -689,10 +693,40 @@ processParms (ast * func,
       return 1;
     }
 
-  if (IS_VOID(actParm->ftype)) {
-    werror (E_VOID_VALUE_USED);
-    return 1;
-  }
+  /* if this is a PARAM node then match left & right */
+  if (actParm->type == EX_OP && actParm->opval.op == PARAM)
+    {
+      actParm->decorated = 1;
+      return (processParms (func, defParm,
+                           actParm->left,  parmNumber, FALSE) ||
+             processParms (func, defParm ? defParm->next : NULL,
+                           actParm->right, parmNumber, rightmost));
+    }
+  else if (defParm) /* not vararg */
+    {
+      /* If we have found a value node by following only right-hand links,
+       * then we know that there are no more values after us.
+       *
+       * Therefore, if there are more defined parameters, the caller didn't
+       * supply enough.
+       */
+      if (rightmost && defParm->next)
+       {
+         werror (E_TOO_FEW_PARMS);
+         return 1;
+       }
+    }
+
+  /* decorate parameter */
+  resultType = defParm ? getResultTypeFromType (defParm->etype) :
+                         RESULT_TYPE_NONE;
+  actParm = decorateType (actParm, resultType);
+
+  if (IS_VOID(actParm->ftype))
+    {
+      werror (E_VOID_VALUE_USED);
+      return 1;
+    }
 
   /* If this is a varargs function... */
   if (!defParm && actParm && IFFUNC_HASVARARGS(func->ftype))
@@ -708,25 +742,12 @@ processParms (ast * func,
        }
 
       ftype = actParm->ftype;
-          
-      /* If it's a small integer, upcast to int. */
+
+      /* If it's a char, upcast to int. */
       if (IS_INTEGRAL (ftype)
          && (getSize (ftype) < (unsigned) INTSIZE))
        {
-         if (IS_AST_OP(actParm) &&
-             (actParm->opval.op == LEFT_OP ||
-              actParm->opval.op == '*' ||
-              actParm->opval.op == '+' ||
-              actParm->opval.op == '-') &&
-             actParm->right) {
-           // we should cast an operand instead of the result
-           actParm->decorated = 0;
-           actParm->left = newNode( CAST, newAst_LINK(newIntLink()),
-                                        actParm->left);
-           actParm = decorateType(actParm, RESULT_CHECK);
-         } else {
-           newType = newAst_LINK(INTTYPE);
-         }
+         newType = newAst_LINK(INTTYPE);  
        }
 
       if (IS_PTR(ftype) && !IS_GENPTR(ftype))
@@ -740,24 +761,21 @@ processParms (ast * func,
          newType = newAst_LINK (copyLinkChain (ftype));
          DCL_TYPE (newType->opval.lnk) = port->unqualified_pointer;
        }
+      
       if (newType)
        {
          /* cast required; change this op to a cast. */
-         ast *parmCopy = decorateType(resolveSymbols (copyAst (actParm)), RESULT_CHECK);
+         ast *parmCopy = resolveSymbols (copyAst (actParm));
 
          actParm->type = EX_OP;
          actParm->opval.op = CAST;
          actParm->left = newType;
          actParm->right = parmCopy;
-         decorateType (actParm, RESULT_CHECK);
-       }
-      else if (actParm->type == EX_OP && actParm->opval.op == PARAM)
-       {
-         return (processParms (func, NULL, actParm->left, parmNumber, FALSE) ||
-         processParms (func, NULL, actParm->right, parmNumber, rightmost));
+         actParm->decorated = 0; /* force typechecking */
+         decorateType (actParm, RESULT_TYPE_NONE);
        }
       return 0;
-    }
+    } /* vararg */
 
   /* if defined parameters ended but actual has not & */
   /* reentrant */
@@ -766,48 +784,30 @@ processParms (ast * func,
     return 0;
 
   resolveSymbols (actParm);
-  /* if this is a PARAM node then match left & right */
-  if (actParm->type == EX_OP && actParm->opval.op == PARAM)
-    {
-      return (processParms (func, defParm, actParm->left, parmNumber, FALSE) ||
-             processParms (func, defParm->next, actParm->right, parmNumber, rightmost));
-    }
-  else
+  
+  /* the parameter type must be at least castable */
+  if (compareType (defParm->type, actParm->ftype) == 0)
     {
-      /* If we have found a value node by following only right-hand links,
-       * then we know that there are no more values after us.
-       *
-       * Therefore, if there are more defined parameters, the caller didn't
-       * supply enough.
-       */
-      if (rightmost && defParm->next)
-       {
-         werror (E_TOO_FEW_PARMS);
-         return 1;
-       }
+      werror (E_INCOMPAT_TYPES);
+      printFromToType (actParm->ftype, defParm->type);
+      return 1;
     }
 
-  /* the parameter type must be at least castable */
-  if (compareType (defParm->type, actParm->ftype) == 0) {
-    werror (E_INCOMPAT_TYPES);
-    printFromToType (actParm->ftype, defParm->type);
-    return 1;
-  }
-
   /* if the parameter is castable then add the cast */
   if (compareType (defParm->type, actParm->ftype) < 0)
     {
-      ast *pTree = decorateType(resolveSymbols (copyAst (actParm)), RESULT_CHECK);
+      ast *pTree;
 
+      resultType = getResultTypeFromType (defParm->etype);
+      pTree = resolveSymbols (copyAst (actParm));
+      
       /* now change the current one to a cast */
       actParm->type = EX_OP;
       actParm->opval.op = CAST;
       actParm->left = newAst_LINK (defParm->type);
       actParm->right = pTree;
-      actParm->etype = defParm->etype;
-      actParm->ftype = defParm->type;
-      actParm->decorated=0; /* force typechecking */
-      decorateType (actParm, RESULT_CHECK);
+      actParm->decorated = 0; /* force typechecking */
+      decorateType (actParm, resultType);
     }
 
   /* make a copy and change the regparm type to the defined parm */
@@ -817,6 +817,7 @@ processParms (ast * func,
   (*parmNumber)++;
   return 0;
 }
+
 /*-----------------------------------------------------------------*/
 /* createIvalType - generates ival for basic types                 */
 /*-----------------------------------------------------------------*/
@@ -1105,7 +1106,7 @@ gatherAutoInit (symbol * autoChain)
 
       /* resolve the symbols in the ival */
       if (sym->ival)
-       resolveIvalSym (sym->ival);
+       resolveIvalSym (sym->ival, sym->type);
 
       /* if this is a static variable & has an */
       /* initial value the code needs to be lifted */
@@ -2007,7 +2008,7 @@ searchLitOp (ast *tree, ast **parent, const char *ops)
 /*-----------------------------------------------------------------*/
 /* getResultFromType                                               */
 /*-----------------------------------------------------------------*/
-static RESULT_TYPE
+RESULT_TYPE
 getResultTypeFromType (sym_link *type)
 {
   /* type = getSpec (type); */
@@ -2026,8 +2027,8 @@ getResultTypeFromType (sym_link *type)
 /*-----------------------------------------------------------------*/
 /* addCast - adds casts to a type specified by RESULT_TYPE         */
 /*-----------------------------------------------------------------*/
-static void
-addCast (ast **tree, RESULT_TYPE resultType, bool upcast)
+static ast *
+addCast (ast *tree, RESULT_TYPE resultType, bool upcast)
 {
   sym_link *newLink;
   bool upCasted = FALSE;
@@ -2037,19 +2038,19 @@ addCast (ast **tree, RESULT_TYPE resultType, bool upcast)
       case RESULT_TYPE_NONE:
        /* char: promote to int */
        if (!upcast ||
-           getSize ((*tree)->etype) >= INTSIZE)
-         return;
+           getSize (tree->etype) >= INTSIZE)
+         return tree;
        newLink = newIntLink();
        upCasted = TRUE;
        break;
       case RESULT_TYPE_CHAR:
-       if (getSize ((*tree)->etype) <= 1)
-         return;
+       if (getSize (tree->etype) <= 1)
+         return tree;
        newLink = newCharLink();
        break;
       case RESULT_TYPE_INT:
 #if 0
-       if (getSize ((*tree)->etype) > INTSIZE)
+       if (getSize (tree->etype) > INTSIZE)
           {
             /* warn ("Loosing significant digits"); */
            return;
@@ -2057,30 +2058,30 @@ addCast (ast **tree, RESULT_TYPE resultType, bool upcast)
 #endif
        /* char: promote to int */
        if (!upcast ||
-           getSize ((*tree)->etype) >= INTSIZE)
-         return;
+           getSize (tree->etype) >= INTSIZE)
+         return tree;
        newLink = newIntLink();
        upCasted = TRUE;
        break;
       case RESULT_TYPE_OTHER:
        if (!upcast)
-         return;
+         return tree;
         /* return type is long, float: promote char to int */
-       if (getSize ((*tree)->etype) >= INTSIZE)
-         return;
+       if (getSize (tree->etype) >= INTSIZE)
+         return tree;
        newLink = newIntLink();
        upCasted = TRUE;
        break;
       default:
-       return;
+       return tree;
     }
-  (*tree)->decorated = 0;
-  *tree = newNode (CAST, newAst_LINK (newLink), *tree);
+  tree->decorated = 0;
+  tree = newNode (CAST, newAst_LINK (newLink), tree);
   /* keep unsigned type during cast to smaller type,
      but not when promoting from char to int */
   if (!upCasted)
-    SPEC_USIGN ((*tree)->left->opval.lnk) = IS_UNSIGNED ((*tree)->right->etype) ? 1 : 0;
-  *tree = decorateType (*tree, resultType);
+    SPEC_USIGN (tree->left->opval.lnk) = IS_UNSIGNED (tree->right->etype) ? 1 : 0;
+  return decorateType (tree, resultType);
 }
 
 /*-----------------------------------------------------------------*/
@@ -2118,15 +2119,21 @@ getLeftResultType (ast *tree, RESULT_TYPE resultType)
     {
       case '=':
       case CAST:
-       if (IS_PTR (tree->left->ftype))
+       if (IS_PTR (LTYPE (tree)))
          return RESULT_TYPE_NONE;
        else
-         return getResultTypeFromType (tree->left->etype);
+         return getResultTypeFromType (LETYPE (tree));
       case RETURN:
        if (IS_PTR (currFunc->type->next))
          return RESULT_TYPE_NONE;
        else
          return getResultTypeFromType (currFunc->type->next);
+      case '[':
+       if (!IS_ARRAY (LTYPE (tree)))
+         return resultType;
+       if (DCL_ELEM (LTYPE (tree)) > 0 && DCL_ELEM (LTYPE (tree)) <= 256)
+         return RESULT_TYPE_CHAR;
+       return resultType;
       default:
        return resultType;
     }
@@ -2264,23 +2271,44 @@ decorateType (ast * tree, RESULT_TYPE resultType)
 
     /* Before decorating the left branch we've to decide in dependence
        upon tree->opval.op, if resultType can be propagated */
-    if (getenv ("SDCC_NEWTYPEFLOW"))
-      resultTypeProp = resultTypePropagate (tree, resultType);
-    else
-      resultTypeProp = RESULT_TYPE_NONE; /* provide initialization */
+    resultTypeProp = resultTypePropagate (tree, resultType);
 
     dtl = decorateType (tree->left, resultTypeProp);
 
+    /* if an array node, we may need to swap branches */
+    if (tree->opval.op == '[')
+      {
+        /* determine which is the array & which the index */
+        if ((IS_ARRAY (RTYPE (tree)) || IS_PTR (RTYPE (tree))) &&
+           IS_INTEGRAL (LTYPE (tree)))
+         {
+           ast *tempTree = tree->left;
+           tree->left = tree->right;
+           tree->right = tempTree;
+         }
+      }
+
     /* After decorating the left branch there's type information available
        in tree->left->?type. If the op is e.g. '=' we extract the type
        information from there and propagate it to the right branch. */
-    if (getenv ("SDCC_NEWTYPEFLOW"))
-      resultTypeProp = getLeftResultType (tree, resultTypeProp);
+    resultTypeProp = getLeftResultType (tree, resultTypeProp);
     
-    /* delay right side for '?' operator since conditional macro expansions
-       might rely on this */
-    dtr = tree->opval.op == '?' ? tree->right :
-                                  decorateType (tree->right, resultTypeProp);
+    switch (tree->opval.op)
+      {
+        case '?':
+         /* delay right side for '?' operator since conditional macro
+            expansions might rely on this */
+         dtr = tree->right;
+         break;
+       case CALL: 
+         /* decorate right side for CALL (parameter list) in processParms();
+            there is resultType available */
+         dtr = tree->right;
+         break;
+       default:     
+         dtr = decorateType (tree->right, resultTypeProp);
+         break;
+      }
 
     /* this is to take care of situations
        when the tree gets rewritten */
@@ -2290,29 +2318,6 @@ decorateType (ast * tree, RESULT_TYPE resultType)
       tree->right = dtr;
     if ((dtl && dtl->isError) || (dtr && dtr->isError))
       return tree;
-
-    if (!getenv ("SDCC_NEWTYPEFLOW"))
-      {
-        if (IS_AST_OP(tree) &&
-           (tree->opval.op == CAST || tree->opval.op == '=') &&
-           (getSize(LTYPE(tree)) > getSize(RTYPE(tree))) &&
-           (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) &&
-             (tree->right->opval.op == LEFT_OP ||
-              tree->right->opval.op == '*' ||
-              tree->right->opval.op == '+' ||
-              tree->right->opval.op == '-') &&
-              tree->right->right) {
-           /* we should cast an operand instead of the result */
-           tree->right->decorated = 0;
-           tree->right->left = newNode( CAST, newAst_LINK(newIntLink()),
-                                        tree->right->left);
-           tree->right = decorateType(tree->right, RESULT_CHECK);
-          }
-        }
-      }
   }
 
   /* depending on type of operator do */
@@ -2325,15 +2330,6 @@ decorateType (ast * tree, RESULT_TYPE resultType)
        /*----------------------------*/
     case '[':
 
-      /* determine which is the array & which the index */
-      if ((IS_ARRAY (RTYPE (tree)) || IS_PTR (RTYPE (tree))) && IS_INTEGRAL (LTYPE (tree)))
-       {
-
-         ast *tempTree = tree->left;
-         tree->left = tree->right;
-         tree->right = tempTree;
-       }
-
       /* first check if this is a array or a pointer */
       if ((!IS_ARRAY (LTYPE (tree))) && (!IS_PTR (LTYPE (tree))))
        {
@@ -2354,6 +2350,17 @@ decorateType (ast * tree, RESULT_TYPE resultType)
          werror (E_LVALUE_REQUIRED, "array access");
          goto errorTreeReturn;
        }
+
+      if (IS_LITERAL (RTYPE (tree)))
+       {
+         int arrayIndex = (int) floatFromVal (valFromType (RETYPE (tree)));
+         int arraySize = DCL_ELEM (LTYPE (tree));
+         if (arraySize && arrayIndex >= arraySize)
+           {
+             werror (W_IDX_OUT_OF_BOUNDS, arrayIndex, arraySize);
+           }
+       }
+
       RRVAL (tree) = 1;
       COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree)->next);
       return tree;
@@ -2530,11 +2537,8 @@ decorateType (ast * tree, RESULT_TYPE resultType)
              return decorateType (otree, RESULT_CHECK);
          }
 
-         if (getenv ("SDCC_NEWTYPEFLOW"))
-           {
-             addCast (&tree->left,  resultType, FALSE);
-             addCast (&tree->right, resultType, FALSE);
-           }
+         tree->left  = addCast (tree->left,  resultType, FALSE);
+         tree->right = addCast (tree->right, resultType, FALSE);
          TTYPE (tree) = computeType (LTYPE (tree), RTYPE (tree), FALSE);
          TETYPE (tree) = getSpec (TTYPE (tree));
 
@@ -2748,11 +2752,8 @@ decorateType (ast * tree, RESULT_TYPE resultType)
         }
 
       LRVAL (tree) = RRVAL (tree) = 1;
-      if (getenv ("SDCC_NEWTYPEFLOW"))
-        {
-          addCast (&tree->left,  resultType, FALSE);
-          addCast (&tree->right, resultType, FALSE);
-        }
+      tree->left  = addCast (tree->left,  resultType, FALSE);
+      tree->right = addCast (tree->right, resultType, FALSE);
       TETYPE (tree) = getSpec (TTYPE (tree) =
                               computeType (LTYPE (tree),
                                            RTYPE (tree),
@@ -2963,20 +2964,12 @@ decorateType (ast * tree, RESULT_TYPE resultType)
         }
 
       LRVAL (tree) = RRVAL (tree) = 1;
-      if (!getenv ("SDCC_NEWTYPEFLOW"))
-        TETYPE (tree) = getSpec (TTYPE (tree) =
-                                computeType (LTYPE (tree),
-                                             RTYPE (tree),
-                                             TRUE));
-      else
-       {
-          addCast (&tree->left,  resultType, FALSE);
-          addCast (&tree->right, resultType, FALSE);
-         TETYPE (tree) = getSpec (TTYPE (tree) =
+      tree->left  = addCast (tree->left,  resultType, FALSE);
+      tree->right = addCast (tree->right, resultType, FALSE);
+      TETYPE (tree) = getSpec (TTYPE (tree) =
                                   computeType (LTYPE (tree),
                                                RTYPE (tree),
                               resultType == RESULT_TYPE_CHAR ? FALSE : TRUE));
-       }
       
       return tree;
 
@@ -3105,20 +3098,14 @@ decorateType (ast * tree, RESULT_TYPE resultType)
        TETYPE (tree) = getSpec (TTYPE (tree) =
                                 LTYPE (tree));
       else
-        if (!getenv ("SDCC_NEWTYPEFLOW"))
+       {
+         tree->left  = addCast (tree->left,  resultType, TRUE);
+          tree->right = addCast (tree->right, resultType, TRUE);
           TETYPE (tree) = getSpec (TTYPE (tree) =
-                                  computeType (LTYPE (tree),
-                                               RTYPE (tree),
-                                               FALSE));
-       else
-          {
-           addCast (&tree->left,  resultType, TRUE);
-            addCast (&tree->right, resultType, TRUE);
-            TETYPE (tree) = getSpec (TTYPE (tree) =
                                     computeType (LTYPE (tree),
                                                  RTYPE (tree),
                               resultType == RESULT_TYPE_CHAR ? FALSE : TRUE));
-          }
+       }
        
       return tree;
 
@@ -3216,20 +3203,14 @@ decorateType (ast * tree, RESULT_TYPE resultType)
        TETYPE (tree) = getSpec (TTYPE (tree) =
                                 LTYPE (tree));
       else
-        if (!getenv ("SDCC_NEWTYPEFLOW"))
-          TETYPE (tree) = getSpec (TTYPE (tree) =
-                                  computeType (LTYPE (tree),
-                                               RTYPE (tree),
-                                               FALSE));
-       else
-         {
-           addCast (&tree->left,  resultType, TRUE);
-           addCast (&tree->right, resultType, TRUE);
-           TETYPE (tree) = getSpec (TTYPE (tree) =
+       {
+         tree->left  = addCast (tree->left,  resultType, TRUE);
+         tree->right = addCast (tree->right, resultType, TRUE);
+         TETYPE (tree) = getSpec (TTYPE (tree) =
                                     computeType (LTYPE (tree),
                                                  RTYPE (tree),
                               resultType == RESULT_TYPE_CHAR ? FALSE : TRUE));
-         }
+       }
 
       LRVAL (tree) = RRVAL (tree) = 1;
 
@@ -3372,20 +3353,11 @@ decorateType (ast * tree, RESULT_TYPE resultType)
       LRVAL (tree) = RRVAL (tree) = 1;
       if (tree->opval.op == LEFT_OP)
        {
-         if (!getenv ("SDCC_NEWTYPEFLOW"))
-           /* promote char to int */
-           TETYPE (tree) = getSpec (TTYPE (tree) =
-                                    computeType (LTYPE (tree),
-                                                 LTYPE (tree), /* no, not RTYPE! */
-                                                 TRUE));
-         else
-           {
-             addCast (&tree->left,  resultType, TRUE);
-             TETYPE (tree) = getSpec (TTYPE (tree) =
+         tree->left = addCast (tree->left, resultType, TRUE);
+         TETYPE (tree) = getSpec (TTYPE (tree) =
                                       computeType (LTYPE (tree),
                                                    RTYPE (tree),
                               resultType == RESULT_TYPE_CHAR ? FALSE : TRUE));
-           }
        }
       else /* RIGHT_OP */
        {
@@ -4179,6 +4151,11 @@ decorateType (ast * tree, RESULT_TYPE resultType)
                                          AST_FOR (tree, loopExpr),
                                          tree->left), RESULT_CHECK);
       }
+    case PARAM:
+      werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+             "node PARAM shouldn't be processed here");
+             /* but in processParams() */
+      return tree;
     default:
       TTYPE (tree) = TETYPE (tree) = NULL;
       return tree;
index 5546f10702ddc8d77e2d479d2d4b6f76dde50020..be782aae94fea11adf39bc1646cbe23f351394e3 100644 (file)
@@ -223,6 +223,7 @@ void addSymToBlock (symbol *, ast *);
 void freeStringSymbol(symbol *);
 DEFSETFUNC(resetParmKey);
 int astErrors(ast *);
+RESULT_TYPE getResultTypeFromType (sym_link *);
 
 // exported variables 
 extern set *operKeyReset;
index fbf94e769ef963840aa333b199078c7000c011be..1a4913767ad331b6a58c8b801cf55487f272b63d 100644 (file)
@@ -294,7 +294,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
           else
             DCL_PTR_CONST (newSym->type) = 1;
          SPEC_STAT(newSym->etype)=1;
-         resolveIvalSym(newSym->ival);
+         resolveIvalSym(newSym->ival, newSym->type);
 
          // add it to the "XINIT (CODE)" segment
          addSet(&xinit->syms, newSym);
@@ -1243,7 +1243,7 @@ emitStaticSeg (memmap * map, FILE * out)
            {
              fprintf (out, "%s:\n", sym->rname);
              noAlloc++;
-             resolveIvalSym (sym->ival);
+             resolveIvalSym (sym->ival, sym->type);
              printIval (sym, sym->type, sym->ival, out);
              noAlloc--;
              /* if sym is a simple string and sym->ival is a string, 
index 82aa2cff3a7238d6ffb73ed4d5bba20e4decf576..d9ee9aa45660858d8a200aa156750203f92c28e9 100644 (file)
@@ -47,8 +47,8 @@ symbol *entryLabel;           /* function entry  label */
 /* forward definition of some functions */
 operand *geniCodeDivision (operand *, operand *);
 operand *geniCodeAssign (operand *, operand *, int);
-operand *geniCodeArray (operand *, operand *,int);
-operand *geniCodeArray2Ptr (operand *);
+static operand *geniCodeArray (operand *, operand *,int);
+static operand *geniCodeArray2Ptr (operand *);
 operand *geniCodeRValue (operand *, bool);
 operand *geniCodeDerefPtr (operand *,int);
 int isLvaluereq(int lvl);
@@ -2292,7 +2292,7 @@ aggrToPtr (sym_link * type, bool force)
 /*-----------------------------------------------------------------*/
 /* geniCodeArray2Ptr - array to pointer                            */
 /*-----------------------------------------------------------------*/
-operand *
+static operand *
 geniCodeArray2Ptr (operand * op)
 {
   sym_link *optype = operandType (op);
@@ -2309,8 +2309,8 @@ geniCodeArray2Ptr (operand * op)
 /*-----------------------------------------------------------------*/
 /* geniCodeArray - array access                                    */
 /*-----------------------------------------------------------------*/
-operand *
-geniCodeArray (operand * left, operand * right,int lvl)
+static operand *
+geniCodeArray (operand * left, operand * right, int lvl)
 {
   iCode *ic;
   operand *size;
@@ -2335,14 +2335,17 @@ geniCodeArray (operand * left, operand * right,int lvl)
   if (indexUnsigned)
     SPEC_USIGN (getSpec (operandType (right))) = 1;
   /* we can check for limits here */
+  /* already done in SDCCast.c
   if (isOperandLiteral (right) &&
       IS_ARRAY (ltype) &&
       DCL_ELEM (ltype) &&
       (operandLitValue (right) / getSize (ltype->next)) >= DCL_ELEM (ltype))
     {
-      werror (E_ARRAY_BOUND);
-      right = operandFromLit (0);
+      werror (W_IDX_OUT_OF_BOUNDS,
+             (int) operandLitValue (right) / getSize (ltype->next),
+             DCL_ELEM (ltype));
     }
+  */
 
   ic = newiCode ('+', left, right);
 
@@ -3517,7 +3520,7 @@ geniCodeInline (ast * tree)
 /*-----------------------------------------------------------------*/
 /* geniCodeArrayInit - intermediate code for array initializer     */
 /*-----------------------------------------------------------------*/
-static void 
+static void
 geniCodeArrayInit (ast * tree, operand *array)
 {
   iCode *ic;
index 0020b56c5723debdcffa2476c430a7500b5c22bb..a0d5e15c31b90aebdb88f2112aaf271fa3f8812e 100644 (file)
@@ -269,18 +269,27 @@ list2expr (initList * ilist)
 /* resolveIvalSym - resolve symbols in initial values               */
 /*------------------------------------------------------------------*/
 void
-resolveIvalSym (initList * ilist)
+resolveIvalSym (initList * ilist, sym_link * type)
 {
+  RESULT_TYPE resultType;
+
   if (!ilist)
     return;
 
   if (ilist->type == INIT_NODE)
-    ilist->init.node = decorateType (resolveSymbols (ilist->init.node), RESULT_CHECK);
+    {
+      if (IS_PTR (type))
+        resultType = RESULT_TYPE_NONE;
+      else
+        resultType = getResultTypeFromType (getSpec (type));
+      ilist->init.node = decorateType (resolveSymbols (ilist->init.node),
+                                      resultType);
+    }
 
   if (ilist->type == INIT_DEEP)
-    resolveIvalSym (ilist->init.deep);
+    resolveIvalSym (ilist->init.deep, type);
 
-  resolveIvalSym (ilist->next);
+  resolveIvalSym (ilist->next, type);
 }
 
 /*-----------------------------------------------------------------*/
index b783970805403048de1ca9dffd49ff010fca5337..92e622fbb4972d45629129e034b214d640f3d936 100644 (file)
@@ -104,7 +104,7 @@ initList *copyIlist (initList *);
 double list2int (initList *);
 value *list2val (initList *);
 struct ast *list2expr (initList *);
-void resolveIvalSym (initList *);
+void resolveIvalSym (initList *, sym_link *);
 value *valFromType (sym_link *);
 value *constFloatVal (char *);
 int getNelements (sym_link *, initList *);
index dbedaff604f21969879ccaa68e478114cfef8f44..d1f271717f98e2d94880c1402f19de6fbb689ba0 100644 (file)
@@ -500,7 +500,7 @@ pic14emitStaticSeg (memmap * map)
 
              fprintf (code->oFile, "%s:\n", sym->rname);
              noAlloc++;
-             resolveIvalSym (sym->ival);
+             resolveIvalSym (sym->ival, sym->type);
              //printIval (sym, sym->type, sym->ival, code->oFile);
              pb = newpCodeChain(NULL, 'P',newpCodeCharP("; Starting pCode block for Ival"));
              addpBlock(pb);
index 1a6cf051223cd879c004e9c1481f910d6a380294..8e071761f6abada623d58065a346366780488d22 100644 (file)
@@ -542,7 +542,7 @@ pic16emitStaticSeg (memmap * map)
 
              fprintf (code->oFile, "%s:\n", sym->rname);
              noAlloc++;
-             resolveIvalSym (sym->ival);
+             resolveIvalSym (sym->ival, sym->type);
              //printIval (sym, sym->type, sym->ival, code->oFile);
              pb = pic16_newpCodeChain(NULL, 'P',pic16_newpCodeCharP("; Starting pCode block for Ival"));
              pic16_addpBlock(pb);
index c78c672f722a4611601ca6948048914896ffa5d6..e54434c05e10e8de6c194c0057ac3094c89789e4 100644 (file)
@@ -100,8 +100,8 @@ struct
    "Array or pointer required for '%s' operation " },
 { E_IDX_NOT_INT, ERROR_LEVEL_ERROR,
    "Array index not an integer" },
-{ E_ARRAY_BOUND, ERROR_LEVEL_ERROR,
-   "Array bound Exceeded, assuming zero" },
+{ W_IDX_OUT_OF_BOUNDS, ERROR_LEVEL_WARNING,
+   "index %i is outside of the array bounds (array size is %i)" },
 { E_STRUCT_UNION, ERROR_LEVEL_ERROR,
    "Structure/Union expected left of '.%s'" },
 { E_NOT_MEMBER, ERROR_LEVEL_ERROR,
index 9f542db2af18d57fd2a11678b19c5c5a90cb3f89..a675d2457a652bf59d6028011416e640c6d49359 100644 (file)
@@ -39,7 +39,7 @@ SDCCERR - SDCC Standard error handler
 #define W_STACK_OVERFLOW  21        /* stack overflow       */
 #define E_NEED_ARRAY_PTR  22        /* array or pointer reqd*/
 #define E_IDX_NOT_INT     23        /* index not an integer */
-#define E_ARRAY_BOUND     24        /* array limit exceeded */
+#define W_IDX_OUT_OF_BOUNDS 24      /* array index out of bounds */
 #define E_STRUCT_UNION    25        /* struct,union expected*/
 #define E_NOT_MEMBER      26        /* !struct/union member */
 #define E_PTR_REQD        27        /* pointer required     */