* src/mcs51/peep.c: fixed gcc warning: suggest parentheses around && within ||
[fw/sdcc] / src / SDCCsymt.c
index 205ea31264d1b1d62e30b1d868ec0f77da02f18a..5bb73d5a97a47b4db30d8fc2cdea951f72e3009f 100644 (file)
@@ -1074,11 +1074,19 @@ addSymChain (symbol ** symHead)
 
       if (!sym->level && !(IS_SPEC(sym->etype) && IS_TYPEDEF(sym->etype)))
         checkDecl (sym, 0);
+      else
+        {
+          /* if this is an array without any dimension
+             then update the dimension from the initial value */
+          if (IS_ARRAY (sym->type) && !DCL_ELEM (sym->type))
+            DCL_ELEM (sym->type) = getNelements (sym->type, sym->ival);
+        }
 
       /* if already exists in the symbol table then check if
-         one of them is an extern definition if yes then
-         then check if the type match, if the types match then
-         delete the current entry and add the new entry      */
+           one of them is an extern definition;
+         if yes then then check if the type match;
+         if the types match then delete the current entry and
+           add the new entry */
       if ((csym = findSymWithLevel (SymbolTab, sym)) &&
           csym->level == sym->level)
         {
@@ -1586,7 +1594,7 @@ checkSClass (symbol * sym, int isProto)
 
   /* automatic symbols cannot be given   */
   /* an absolute address ignore it      */
-  if (sym->level &&
+  if (sym->level && !IS_STATIC(sym->etype) &&
       SPEC_ABSA (sym->etype) &&
       (options.stackAuto || reentrant))
     {
@@ -1896,6 +1904,17 @@ computeType (sym_link * type1, sym_link * type2,
 
   switch (resultType)
     {
+      case RESULT_TYPE_IFX:
+        if (TARGET_IS_HC08)
+          break;
+        //fallthrough
+      case RESULT_TYPE_BIT:
+        if (op == ':')
+          {
+            SPEC_NOUN (reType) = V_BIT;
+            return rType;
+          }
+        break;
       case RESULT_TYPE_CHAR:
         if (IS_BITVAR (reType))
           {
@@ -2051,27 +2070,31 @@ compareType (sym_link * dest, sym_link * src)
               return compareType (dest->next, src->next);
             }
 
-          if (DCL_TYPE (src) == DCL_TYPE (dest)) {
-            if (IS_FUNC(src)) {
-              //checkFunction(src,dest);
+          if (DCL_TYPE (src) == DCL_TYPE (dest))
+            {
+              if (IS_FUNC(src))
+                {
+                  //checkFunction(src,dest);
+                }
+              return compareType (dest->next, src->next);
+            }
+          if (IS_PTR (dest) && IS_GENPTR (src) && IS_VOID(src->next))
+            {
+              return -1;
             }
-            return compareType (dest->next, src->next);
-          }
-          if (IS_PTR (dest) && IS_GENPTR (src) && IS_VOID(src->next)) {
-            return -1;
-          }
           if (IS_PTR (src) && 
               (IS_GENPTR (dest) ||
                ((DCL_TYPE(src) == POINTER) && (DCL_TYPE(dest) == IPOINTER))
              ))
             return -1;
-          if (IS_PTR (dest) && IS_ARRAY (src)) {
-            value *val=aggregateToPointer (valFromType(src));
-            int res=compareType (dest, val->type);
-            Safe_free(val->type);
-            Safe_free(val);
-            return res;
-          }
+          if (IS_PTR (dest) && IS_ARRAY (src))
+            {
+              value *val=aggregateToPointer (valFromType(src));
+              int res=compareType (dest, val->type);
+              Safe_free(val->type);
+              Safe_free(val);
+              return res;
+            }
           if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
             return compareType (dest->next, src);
           return 0;
@@ -2113,7 +2136,7 @@ compareType (sym_link * dest, sym_link * src)
              instead of the next two lines, but the regression tests fail with
              them; I guess it's a problem with replaceCheaperOp  */
           getSize (dest) == getSize (src) &&
-          !(!IS_BIT (dest) && IS_BIT (src)))
+          (IS_BIT (dest) == IS_BIT (src)))
         return 1;
       else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src))
         return -1;
@@ -2333,8 +2356,8 @@ inCalleeSaveList(char *s)
 }
 
 /*-----------------------------------------------------------------*/
-/* aggregateToPointer:  change an agggregate type function      */
-/*         argument to a pointer to that type.     */
+/* aggregateToPointer:     change an aggregate type function       */
+/*                         argument to a pointer to that type.     */
 /*-----------------------------------------------------------------*/
 value *
 aggregateToPointer (value * val)
@@ -2463,7 +2486,6 @@ checkFunction (symbol * sym, symbol *csym)
       werror (E_SHADOWREGS_NO_ISR, sym->name);
     }
 
-
   for (argCnt=1, acargs = FUNC_ARGS(sym->type); 
        acargs; 
        acargs=acargs->next, argCnt++) {
@@ -2516,6 +2538,9 @@ checkFunction (symbol * sym, symbol *csym)
       werror (E_PREV_DEF_CONFLICT, csym->name, "using");
     }
 
+  /*JCF: Mark the register bank as used*/
+  RegBankUsed[FUNC_REGBANK (sym->type)] = 1;
+
   if (IFFUNC_ISNAKED (csym->type) != IFFUNC_ISNAKED (sym->type))
     {
       werror (E_PREV_DEF_CONFLICT, csym->name, "_naked");
@@ -3669,10 +3694,10 @@ newEnumType (symbol *enumlist)
       
   /* Determine the range of the enumerated values */
   sym = enumlist;
-  min = max = (int) floatFromVal (valFromType (sym->type));
+  min = max = (int) ulFromVal (valFromType (sym->type));
   for (sym = sym->next; sym; sym = sym->next)
     {
-      v = (int) floatFromVal (valFromType (sym->type));
+      v = (int) ulFromVal (valFromType (sym->type));
       if (v<min)
         min = v;
       if (v>max)