a fix for the initialized structs and some others, see
[fw/sdcc] / src / SDCCsymt.c
index 34fe08a3fd65e5471b60814d8cc7cc0661d46887..51e3e844520b5e26d682207021777512c12076e7 100644 (file)
@@ -412,7 +412,7 @@ addDecl (symbol * sym, int type, sym_link * p)
     {
       if (IS_SPEC (sym->etype) && IS_SPEC (head) && head == tail)
        {
-         sym->etype = mergeSpec (sym->etype, head);
+         sym->etype = mergeSpec (sym->etype, head, sym->name);
        }
       else
        {
@@ -525,9 +525,13 @@ void checkTypeSanity(sym_link *etype, char *name) {
 /* mergeSpec - merges two specifiers and returns the new one        */
 /*------------------------------------------------------------------*/
 sym_link *
-mergeSpec (sym_link * dest, sym_link * src)
+mergeSpec (sym_link * dest, sym_link * src, char *name)
 {
 
+  if (getenv("DEBUG_mergeSpec")) {
+    fprintf (stderr, "mergeSpec: \"%s\"\n", name);
+  }
+
   if (SPEC_NOUN(src)) {
     if (!SPEC_NOUN(dest)) {
       SPEC_NOUN(dest)=SPEC_NOUN(src);
@@ -536,7 +540,7 @@ mergeSpec (sym_link * dest, sym_link * src)
       if (getenv("DEBUG_SANITY")) {
        fprintf (stderr, "mergeSpec: ");
       }
-      werror(E_TWO_OR_MORE_DATA_TYPES, yylval.yychar);
+      werror(E_TWO_OR_MORE_DATA_TYPES, name);
     }
   }
   
@@ -548,7 +552,7 @@ mergeSpec (sym_link * dest, sym_link * src)
       if (getenv("DEBUG_SANITY")) {
        fprintf (stderr, "mergeSpec: ");
       }
-      werror(E_TWO_OR_MORE_STORAGE_CLASSES, yylval.yychar);
+      werror(E_TWO_OR_MORE_STORAGE_CLASSES, name);
     }
   }
 
@@ -931,7 +935,7 @@ addSymChain (symbol * symHead)
          if (IS_EXTERN (csym->etype))
            {
              /* do types match ? */
-             if (checkType (csym->type, sym->type) != 1)
+             if (compareType (csym->type, sym->type) != 1)
                /* no then error */
                werror (E_DUPLICATE, csym->name);
 
@@ -952,7 +956,7 @@ addSymChain (symbol * symHead)
          /* then check the type with the current one         */
          if (IS_EXTERN (csym->etype))
            {
-             if (checkType (csym->type, sym->type) <= 0)
+             if (compareType (csym->type, sym->type) <= 0)
                werror (W_EXTERN_MISMATCH, csym->name);
            }
        }
@@ -1108,11 +1112,18 @@ compStructSize (int su, structdef * sdef)
 static void 
 checkSClass (symbol * sym)
 {
+  if (getenv("DEBUG_SANITY")) {
+    fprintf (stderr, "checkSClass: %s \n", sym->name);
+  }
+  if (strcmp(sym->name, "_testsGlobal")==0) {
+    printf ("oach\n");
+  }
+  
   /* type is literal can happen foe enums change
      to auto */
   if (SPEC_SCLS (sym->etype) == S_LITERAL && !SPEC_ENUM (sym->etype))
     SPEC_SCLS (sym->etype) = S_AUTO;
-
+  
   /* if sfr or sbit then must also be */
   /* volatile the initial value will be xlated */
   /* to an absolute address */
@@ -1129,26 +1140,24 @@ checkSClass (symbol * sym)
          sym->ival = NULL;
        }
     }
-
+  
   /* if absolute address given then it mark it as
      volatile */
   if (IS_ABSOLUTE (sym->etype))
     SPEC_VOLATILE (sym->etype) = 1;
-
+  
   /* global variables declared const put into code */
   if (sym->level == 0 &&
-      SPEC_SCLS (sym->etype) == S_CONSTANT)
-    {
-      SPEC_SCLS (sym->etype) = S_CODE;
-      SPEC_CONST (sym->etype) = 1;
-    }
-
+      SPEC_CONST (sym->etype)) {
+    SPEC_SCLS (sym->etype) = S_CODE;
+  }
+  
   /* global variable in code space is a constant */
   if (sym->level == 0 &&
       SPEC_SCLS (sym->etype) == S_CODE &&
       port->mem.code_ro)
     SPEC_CONST (sym->etype) = 1;
-
+  
 
   /* if bit variable then no storage class can be */
   /* specified since bit is already a storage */
@@ -1169,6 +1178,7 @@ checkSClass (symbol * sym)
       sym->ival = NULL;
     }
 
+#if 0
   /* if this is an automatic symbol then */
   /* storage class will be ignored and   */
   /* symbol will be allocated on stack/  */
@@ -1179,13 +1189,29 @@ checkSClass (symbol * sym)
        SPEC_SCLS (sym->etype) != S_FIXED &&
        SPEC_SCLS (sym->etype) != S_REGISTER &&
        SPEC_SCLS (sym->etype) != S_STACK &&
-       SPEC_SCLS (sym->etype) != S_XSTACK &&
-       SPEC_SCLS (sym->etype) != S_CONSTANT))
+       SPEC_SCLS (sym->etype) != S_XSTACK))
     {
       werror (E_AUTO_ASSUMED, sym->name);
       SPEC_SCLS (sym->etype) = S_AUTO;
     }
-
+#else
+  /* if this is an atomatic symbol */
+  if (sym->level && (options.stackAuto || reentrant)) {
+    if ((SPEC_SCLS (sym->etype) == S_AUTO ||
+        SPEC_SCLS (sym->etype) == S_FIXED ||
+        SPEC_SCLS (sym->etype) == S_REGISTER ||
+        SPEC_SCLS (sym->etype) == S_STACK ||
+        SPEC_SCLS (sym->etype) == S_XSTACK)) {
+      SPEC_SCLS (sym->etype) = S_AUTO;
+    } else {
+      /* storage class may only be specified for statics */
+      if (!IS_STATIC(sym->etype)) {
+       werror (E_AUTO_ASSUMED, sym->name);
+      }
+    }
+  }
+#endif
+  
   /* automatic symbols cannot be given   */
   /* an absolute address ignore it      */
   if (sym->level &&
@@ -1402,10 +1428,10 @@ computeType (sym_link * type1, sym_link * type2)
 }
 
 /*------------------------------------------------------------------*/
-/* checkType - will do type check return 1 if match                 */
+/* compareType - will do type check return 1 if match                 */
 /*------------------------------------------------------------------*/
 int 
-checkType (sym_link * dest, sym_link * src)
+compareType (sym_link * dest, sym_link * src)
 {
   if (!dest && !src)
     return 1;
@@ -1422,13 +1448,13 @@ checkType (sym_link * dest, sym_link * src)
       if (IS_DECL (src))
        {
          if (DCL_TYPE (src) == DCL_TYPE (dest))
-           return checkType (dest->next, src->next);
+           return compareType (dest->next, src->next);
          else if (IS_PTR (src) && IS_PTR (dest))
            return -1;
          else if (IS_PTR (dest) && IS_ARRAY (src))
            return -1;
          else if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
-           return -1 * checkType (dest->next, src);
+           return -1 * compareType (dest->next, src);
          else
            return 0;
        }
@@ -1634,7 +1660,7 @@ checkFunction (symbol * sym)
     }
 
   /* check the return value type   */
-  if (checkType (csym->type, sym->type) <= 0)
+  if (compareType (csym->type, sym->type) <= 0)
     {
       werror (E_PREV_DEF_CONFLICT, csym->name, "type");
       werror (E_CONTINUE, "previous definition type ");
@@ -1690,7 +1716,7 @@ checkFunction (symbol * sym)
          checkValue = acargs;
        }
 
-      if (checkType (exargs->type, checkValue->type) <= 0)
+      if (compareType (exargs->type, checkValue->type) <= 0)
        {
          werror (E_ARG_TYPE, argCnt);
          return 0;