]> git.gag.com Git - fw/sdcc/commitdiff
some fixes
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 11 Jun 2001 12:11:27 +0000 (12:11 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 11 Jun 2001 12:11:27 +0000 (12:11 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@878 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCC.y
src/SDCCast.c
src/SDCCglue.c
src/SDCCsymt.c
src/SDCCsymt.h
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 59c7b982685838b7e7c3a3664448225ba2db899b..51a853f5da9be3c9ef85dffad9180907acb5c311 100644 (file)
@@ -597,7 +597,7 @@ type_specifier2
    | CONST  {
                $$=newLink();
               $$->class = SPECIFIER ;
-              SPEC_SCLS($$) = S_CONSTANT ;
+              //SPEC_SCLS($$) = S_CONSTANT ;
               SPEC_CONST($$) = 1;
             }
    | VOLATILE  {
index 9eefea9c6ba0d7da99953ef6b13893f2b3c94396..4abbdc67309066ffabae0b332e8899e16e49ed04 100644 (file)
@@ -864,8 +864,16 @@ createIvalArray (ast * sym, sym_link * type, initList * ilist)
 
       /* no of elements given and we    */
       /* have generated for all of them */
-      if (!--lcnt)
+      if (!--lcnt) {
+       /* if initializers left */
+       if (iloop) {
+         // there has to be a better way
+         char *name=sym->opval.val->sym->name;
+         int lineno=sym->opval.val->sym->lineDef;
+         werror (W_EXESS_ARRAY_INITIALIZERS, name, lineno);
+       }
        break;
+      }
     }
 
   /* if we have not been given a size  */
index b95d90dbc65cf2075b051442c634da0535b3a870..a59053eb336e3515ec50a78945de75317e2bc58e 100644 (file)
@@ -692,8 +692,13 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
 
       /* no of elements given and we    */
       /* have generated for all of them */
-      if (!--lcnt)
+      if (!--lcnt) {
+       /* if initializers left */
+       if (iloop) {
+         werror (W_EXESS_ARRAY_INITIALIZERS, sym->name, sym->lineDef);
+       }
        break;
+      }
     }
 
   /* if we have not been given a size  */
index 6f20b9825bf13e93646e0b470868de4cb5017ea3..01364f37d5498164df2a94c733f0b4006fb88c22 100644 (file)
@@ -107,7 +107,7 @@ addSym (bucket ** stab,
     fprintf (stderr, "addSym: %s\n", sname);
   }
   /* Make sure sym is a symbol and not a structdef */
-  if (StructTab!=stab) checkTypeSanity(((symbol *)sym)->etype, sname);
+  if (StructTab!=stab) checkTypeSanity((symbol *)sym);
 
   /* the symbols are always added at the head of the list  */
   i = hashKey (sname);
@@ -455,49 +455,55 @@ addDecl (symbol * sym, int type, sym_link * p)
   checkTypeSanity: prevent the user from doing e.g.:
   unsigned float uf;
   ------------------------------------------------------------------*/
-void checkTypeSanity(sym_link *dest, char *name) {
+void checkTypeSanity(symbol *sym) {
   char *noun;
+  sym_link *etype=sym->etype;
+  char *name=sym->name;
 
-  if (!dest) {
+  if (!etype) {
     if (getenv("DEBUG_SANITY")) {
       printf ("sanity check skipped for %s\n", name);
     }
     return;
   }
 
-  noun=nounName(dest);
+  noun=nounName(etype);
 
   if (getenv("DEBUG_SANITY")) {
     printf ("checking sanity for %s\n", name);
   }
 
-  if ((SPEC_NOUN(dest)==V_CHAR || 
-       SPEC_NOUN(dest)==V_FLOAT || 
-       SPEC_NOUN(dest)==V_DOUBLE || 
-       SPEC_NOUN(dest)==V_VOID) &&
-      (SPEC_SHORT(dest) || SPEC_LONG(dest))) {
+  if ((SPEC_NOUN(etype)==V_CHAR || 
+       SPEC_NOUN(etype)==V_FLOAT || 
+       SPEC_NOUN(etype)==V_DOUBLE || 
+       SPEC_NOUN(etype)==V_VOID) &&
+      (SPEC_SHORT(etype) || SPEC_LONG(etype))) {
     // long or short for char float double or void
     werror (E_LONG_OR_SHORT_INVALID, noun, name);
   }
-  if ((SPEC_NOUN(dest)==V_FLOAT || 
-       SPEC_NOUN(dest)==V_DOUBLE || 
-       SPEC_NOUN(dest)==V_VOID) && 
-      (SPEC_SIGNED(dest) || SPEC_USIGN(dest))) {
+  if ((SPEC_NOUN(etype)==V_FLOAT || 
+       SPEC_NOUN(etype)==V_DOUBLE || 
+       SPEC_NOUN(etype)==V_VOID) && 
+      (SPEC_SIGNED(etype) || SPEC_USIGN(etype))) {
     // signed or unsigned for float double or void
     werror (E_SIGNED_OR_UNSIGNED_INVALID, noun, name);
   }
 
-  if (!SPEC_NOUN(dest)) {
-    if (SPEC_SIGNED(dest) || SPEC_USIGN(dest)) {
-      SPEC_NOUN(dest)=V_INT;
+  // special case for "signed" and "unsigned"
+  if (!SPEC_NOUN(etype) && (SPEC_SIGNED(etype) || SPEC_USIGN(etype))) {
+      SPEC_NOUN(etype)=V_INT;
     }
+
+  // special case for const globals
+  if (!SPEC_SCLS(etype) && SPEC_CONST(etype) && sym->level==0) {
+    SPEC_SCLS(etype)=S_CODE;
   }
 
-  if (SPEC_SIGNED(dest) && SPEC_USIGN(dest)) {
+  if (SPEC_SIGNED(etype) && SPEC_USIGN(etype)) {
     // signed AND unsigned 
     werror (E_SIGNED_AND_UNSIGNED_INVALID, noun, name);
   }
-  if (SPEC_SHORT(dest) && SPEC_LONG(dest)) {
+  if (SPEC_SHORT(etype) && SPEC_LONG(etype)) {
     // short AND long
     werror (E_LONG_AND_SHORT_INVALID, noun, name);
   }
@@ -511,26 +517,43 @@ sym_link *
 mergeSpec (sym_link * dest, sym_link * src)
 {
 
-  /* we shouldn't redeclare the type */
-  if ((SPEC_NOUN (dest) && SPEC_NOUN (src)) && 
-      (SPEC_NOUN(dest) != SPEC_NOUN(src))) {
-    if (getenv("DEBUG_SANITY")) {
-      fprintf (stderr, "mergeSpec: ");
+  if (SPEC_NOUN(src)) {
+    if (!SPEC_NOUN(dest)) {
+      SPEC_NOUN(dest)=SPEC_NOUN(src);
+    } else {
+      /* we shouldn't redeclare the type */
+      if (getenv("DEBUG_SANITY")) {
+       fprintf (stderr, "mergeSpec: ");
+       werror(E_TWO_OR_MORE_DATA_TYPES, yylval.yychar);
+      }
+    }
+  }
+  
+  if (SPEC_SCLS(src)) {
+    /* if destination has no storage class */
+    if (!SPEC_SCLS (dest) || SPEC_SCLS(dest)==S_REGISTER) {
+      SPEC_SCLS (dest) = SPEC_SCLS (src);
+    } else {
+      if (getenv("DEBUG_SANITY")) {
+       fprintf (stderr, "mergeSpec: ");
+      }
+      werror(E_TWO_OR_MORE_STORAGE_CLASSES, yylval.yychar);
     }
-    werror(E_TWO_OR_MORE_DATA_TYPES, yylval.yychar);
   }
 
-  /* if noun different then src overrides */
-  if (SPEC_NOUN (dest) != SPEC_NOUN (src) && !SPEC_NOUN (dest))
-    SPEC_NOUN (dest) = SPEC_NOUN (src);
-
-  /* if destination has no storage class */
-  if (!SPEC_SCLS (dest) || 
-      ((SPEC_SCLS(dest) == S_CONSTANT || SPEC_SCLS(dest) == S_REGISTER) && 
-       SPEC_SCLS (src)))
-    SPEC_SCLS (dest) = SPEC_SCLS (src);
-  /* special case for const */
   /* copy all the specifications  */
+
+  // we really should do: 
+#if 0
+  if (SPEC_what(src)) {
+    if (SPEC_what(dest)) {
+      werror(W_DUPLICATE_SPEC, "what");
+    }
+    SPEC_what(dst)=SPEC_what(src);
+  }
+#endif
+  // but there are more important thing right now
+  
   SPEC_LONG (dest) |= SPEC_LONG (src);
   SPEC_SHORT (dest) |= SPEC_SHORT (src);
   SPEC_USIGN (dest) |= SPEC_USIGN (src);
index 648bfdf51dd0a5e8709232a6e3a4ec51d18edea5..a6f938bab867760701fd05fd036e658996c21680 100644 (file)
@@ -457,7 +457,7 @@ void *findSym (bucket **, void *, const char *);
 void *findSymWithLevel (bucket **, struct symbol *);
 void *findSymWithBlock (bucket **, struct symbol *, int);
 void changePointer (symbol * sym);
-void checkTypeSanity(sym_link *, char *);
+void checkTypeSanity(symbol * sym);
 /* noun strings */
 extern char *nounName(sym_link *);
 
index 04ec9060aaca38efef6e6383be2a6ebd304b29f8..08f03e42d3d535e1d02f8b84260fc252a819389b 100644 (file)
@@ -345,6 +345,10 @@ struct
     "both long and short specified for %s '%s'" },
 { E_SIGNED_AND_UNSIGNED_INVALID, ERROR_LEVEL_ERROR,
     "both signed and unsigned specified for %s '%s'" },
+{ E_TWO_OR_MORE_STORAGE_CLASSES, ERROR_LEVEL_ERROR,
+    "two or more storage classes in declaration for '%s'" },
+{ W_EXESS_ARRAY_INITIALIZERS, ERROR_LEVEL_WARNING,
+    "excess elements in array initializer after `%s' at line %d" },
 };
 /*
 -------------------------------------------------------------------------------
index 4398867a92a91d172ecbd9671be2c3c5a0293d42..c70953d04aaa50d9df6ed2f10e9640ce2e5a2b76 100644 (file)
@@ -161,6 +161,8 @@ SDCCERR - SDCC Standard error handler
 #define E_SIGNED_OR_UNSIGNED_INVALID 143    /* signed or unsigned invalid for .. */
 #define E_LONG_AND_SHORT_INVALID  144    /* long and short invalid for .. */
 #define E_SIGNED_AND_UNSIGNED_INVALID 145 /* signed and unsigned invalid for .. */
+#define E_TWO_OR_MORE_STORAGE_CLASSES 146
+#define W_EXESS_ARRAY_INITIALIZERS 147 /* too much initializers for array */
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.