hack up const and volatile modifiers in type chains a bit
[fw/sdcc] / src / SDCCsymt.c
index 6d5e32436bffa1eea8d6cd9c678694e61b17e892..0dce6fa4a2e08e20d43c8aa840aef4182c3691fa 100644 (file)
@@ -347,8 +347,6 @@ pointerTypes (sym_link * ptr, sym_link * type)
      storage class of the type */
   if (IS_SPEC (type))
     {
-      DCL_PTR_CONST (ptr) = SPEC_CONST (type);
-      DCL_PTR_VOLATILE (ptr) = SPEC_VOLATILE (type);
       switch (SPEC_SCLS (type))
        {
        case S_XDATA:
@@ -364,7 +362,6 @@ pointerTypes (sym_link * ptr, sym_link * type)
          DCL_TYPE (ptr) = POINTER;
          break;
        case S_CODE:
-         DCL_PTR_CONST (ptr) = port->mem.code_ro;
          DCL_TYPE (ptr) = CPOINTER;
          break;
        case S_EEPROM:
@@ -457,22 +454,26 @@ addDecl (symbol * sym, int type, sym_link * p)
     }
 
   /* if the type is an unknown pointer and has
-     a tspec then take the storage class const & volatile
+     a tspec then take the const & volatile
      attribute from the tspec & make it those of this
      symbol */
+
   if (p &&
-      !IS_SPEC (p) &&
-      //DCL_TYPE (p) == UPOINTER &&
+      IS_DECL (p) &&
+      DCL_TYPE (p) == UPOINTER &&
       DCL_TSPEC (p))
     {
+      // only for declarators
+      wassert (IS_DECL(sym->type));
+
       if (!IS_SPEC (sym->etype))
        {
          sym->etype = sym->etype->next = newLink ();
          sym->etype->class = SPECIFIER;
        }
-      SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p));
-      SPEC_CONST (sym->etype) = SPEC_CONST (DCL_TSPEC (p));
-      SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p));
+      
+      DCL_PTR_CONST (sym->type) = SPEC_CONST (DCL_TSPEC (p));
+      DCL_PTR_VOLATILE (sym->type) = SPEC_VOLATILE (DCL_TSPEC (p));
       DCL_TSPEC (p) = NULL;
     }
 
@@ -508,7 +509,7 @@ void checkTypeSanity(sym_link *etype, char *name) {
   noun=nounName(etype);
 
   if (getenv("DEBUG_SANITY")) {
-    fprintf (stderr, "checking sanity for %s %x\n", name, (int)etype);
+    fprintf (stderr, "checking sanity for %s %p\n", name, etype);
   }
 
   if ((SPEC_NOUN(etype)==V_CHAR || 
@@ -645,23 +646,6 @@ mergeSpec (sym_link * dest, sym_link * src, char *name)
   return symlink;
 }
 
-/*------------------------------------------------------------------*/
-/* cloneSpec - copies the entire spec and returns a new spec        */
-/*------------------------------------------------------------------*/
-sym_link *
-cloneSpec (sym_link * src)
-{
-  sym_link *spec;
-
-  /* go thru chain till we find the specifier */
-  while (src && src->class != SPECIFIER)
-    src = src->next;
-
-  spec = newLink ();
-  memcpy (spec, src, sizeof (sym_link));
-  return spec;
-}
-
 /*------------------------------------------------------------------*/
 /* genSymName - generates and returns a name used for anonymous vars */
 /*------------------------------------------------------------------*/
@@ -990,14 +974,16 @@ addSymChain (symbol * symHead)
            werror (E_EXTERN_MISMATCH, csym->name);
            continue;
          }
-         /* delete current entry */
-         deleteSym (SymbolTab, csym, csym->name);
-         deleteFromSeg(csym);
        } else {
          /* not extern */
-         werror (E_DUPLICATE, sym->name);
-         continue;
+         if (compareType (csym->type, sym->type) != 1) {
+           werror (E_DUPLICATE, sym->name);
+           continue;
+         }
        }
+       /* delete current entry */
+       deleteSym (SymbolTab, csym, csym->name);
+       deleteFromSeg(csym);
       }
 
       /* add new entry */
@@ -1481,6 +1467,9 @@ compareType (sym_link * dest, sym_link * src)
            }
            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))
            return -1;
          if (IS_PTR (dest) && IS_ARRAY (src)) {
@@ -1488,7 +1477,6 @@ compareType (sym_link * dest, sym_link * src)
            int res=compareType (dest, val->type);
            Safe_free(val->type);
            Safe_free(val);
-           //return res ? -1 : 0;
            return res;
          }
          if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
@@ -2109,12 +2097,12 @@ printTypeChain (sym_link * start, FILE * of)
              break;
            }
        }
-       /* search entry in list before "type" */
-    for (search = start; search && search->next != type;)
-       search = search->next;
-    type = search;
-    if (type)
-      fputc (' ', of);
+      /* search entry in list before "type" */
+      for (search = start; search && search->next != type;)
+       search = search->next;
+      type = search;
+      if (type)
+       fputc (' ', of);
     }
   if (nlr)
     fprintf (of, "\n");