]> git.gag.com Git - fw/sdcc/commitdiff
the next step in advanced type checking
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 12 Jun 2001 14:23:12 +0000 (14:23 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 12 Jun 2001 14:23:12 +0000 (14:23 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@880 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/lib/printfl.c
src/SDCC.y
src/SDCCast.c
src/SDCCsymt.c
src/SDCCsymt.h
support/Util/SDCCerr.c

index ba5a3fa6f67c0cd391e844501bc3772daef81615..ec3b4523a20a2b66893a577eaa123c4d76c4c282 100644 (file)
 */
 
 #include <stdarg.h>
-#include <reg51.h>
 #include <stdio.h>
+#ifndef __ds390
+#include <reg51.h> // for the SP
+#endif
 
 static data volatile char ch;
 static data char radix ;
index 51a853f5da9be3c9ef85dffad9180907acb5c311..afb2e5a9232caded83d00de708aeacac31bf783e 100644 (file)
@@ -565,7 +565,6 @@ type_specifier2
    | SHORT  {
                $$=newLink();
                $$->class = SPECIFIER   ;
-               SPEC_NOUN($$) = V_INT   ;
               SPEC_SHORT($$) = 1      ;
             }
    | INT    {
@@ -576,7 +575,6 @@ type_specifier2
    | LONG   {
                $$=newLink();
                $$->class = SPECIFIER   ;
-               SPEC_NOUN($$) = V_INT   ;
               SPEC_LONG($$) = 1       ;
             }
    | SIGNED {
@@ -658,7 +656,6 @@ type_specifier2
          {
             symbol *sym;
             sym_link   *p  ;
-
             sym = findSym(TypedefTab,NULL,$1) ;
             $$ = p = copyLinkChain(sym->type);
            SPEC_TYPEDEF(getSpec(p)) = 0;
@@ -756,10 +753,11 @@ struct_declaration
               if (!sym->type) {
                   sym->type = copyLinkChain($1);
                   sym->etype = getSpec(sym->type);
+                  /* make sure the type is complete and sane */
+                  checkTypeSanity(sym->etype, sym->name);
               }
               else
                   addDecl (sym,0,cloneSpec($1));              
-              
           }
            $$ = $2;
        }
index 4abbdc67309066ffabae0b332e8899e16e49ed04..9c62ab82694c47225b089e27c8fe25a73db1d472 100644 (file)
@@ -2633,6 +2633,9 @@ decorateType (ast * tree)
          werror (E_CAST_ILLEGAL);
          goto errorTreeReturn;
        }
+      
+      /* make sure the type is complete and sane */
+      checkTypeSanity(LETYPE(tree), "(cast)");
 
       /* if the right is a literal replace the tree */
       if (IS_LITERAL (RETYPE (tree)) && !IS_PTR (LTYPE (tree)))
@@ -3167,6 +3170,9 @@ sizeofOp (sym_link * type)
 {
   char buff[10];
 
+  /* make sure the type is complete and sane */
+  checkTypeSanity(type, "(sizeof)");
+
   /* get the size and convert it to character  */
   sprintf (buff, "%d", getSize (type));
 
index 01364f37d5498164df2a94c733f0b4006fb88c22..bf7a5809103e09b0d31a8218d12a69830267e5aa 100644 (file)
@@ -104,10 +104,13 @@ addSym (bucket ** stab,
   bucket *bp;                  /* temp bucket    *         */
 
   if (getenv("DEBUG_SANITY")) {
-    fprintf (stderr, "addSym: %s\n", sname);
+    fprintf (stderr, "addSym: %s ", sname);
   }
   /* Make sure sym is a symbol and not a structdef */
-  if (StructTab!=stab) checkTypeSanity((symbol *)sym);
+  if (1 || StructTab!=stab) {
+    /* make sure the type is complete and sane */
+    checkTypeSanity(((symbol *)sym)->etype, ((symbol *)sym)->name);
+  }
 
   /* the symbols are always added at the head of the list  */
   i = hashKey (sname);
@@ -455,14 +458,19 @@ addDecl (symbol * sym, int type, sym_link * p)
   checkTypeSanity: prevent the user from doing e.g.:
   unsigned float uf;
   ------------------------------------------------------------------*/
-void checkTypeSanity(symbol *sym) {
+void checkTypeSanity(sym_link *etype, char *name) {
   char *noun;
-  sym_link *etype=sym->etype;
-  char *name=sym->name;
 
   if (!etype) {
     if (getenv("DEBUG_SANITY")) {
-      printf ("sanity check skipped for %s\n", name);
+      fprintf (stderr, "sanity check skipped for %s (etype==0)\n", name);
+    }
+    return;
+  }
+
+  if (!IS_SPEC(etype)) {
+    if (getenv("DEBUG_SANITY")) {
+      fprintf (stderr, "sanity check skipped for %s (!IS_SPEC)\n", name);
     }
     return;
   }
@@ -470,7 +478,7 @@ void checkTypeSanity(symbol *sym) {
   noun=nounName(etype);
 
   if (getenv("DEBUG_SANITY")) {
-    printf ("checking sanity for %s\n", name);
+    fprintf (stderr, "checking sanity for %s\n", name);
   }
 
   if ((SPEC_NOUN(etype)==V_CHAR || 
@@ -489,14 +497,21 @@ void checkTypeSanity(symbol *sym) {
     werror (E_SIGNED_OR_UNSIGNED_INVALID, noun, name);
   }
 
-  // special case for "signed" and "unsigned"
-  if (!SPEC_NOUN(etype) && (SPEC_SIGNED(etype) || SPEC_USIGN(etype))) {
+  if (!SPEC_NOUN(etype)) {
+    // special case for just "signed" or "unsigned" or "long"
+    if (SPEC_SIGNED(etype) || SPEC_USIGN(etype) || SPEC_LONG(etype)) {
       SPEC_NOUN(etype)=V_INT;
     }
+    // special case for just "short"
+    if (SPEC_SHORT(etype)) {
+      SPEC_NOUN(etype)=V_CHAR; // or maybe V_INT
+      SPEC_SHORT(etype)=0;
+    }
+  }
 
-  // special case for const globals
-  if (!SPEC_SCLS(etype) && SPEC_CONST(etype) && sym->level==0) {
-    SPEC_SCLS(etype)=S_CODE;
+  // if still no noun (e.g. "const a;" or "data b;") assume an int
+  if (!SPEC_NOUN(etype)) {
+    SPEC_NOUN(etype)=V_INT;
   }
 
   if (SPEC_SIGNED(etype) && SPEC_USIGN(etype)) {
@@ -917,7 +932,7 @@ addSymChain (symbol * symHead)
        {
 
          /* previous definition extern ? */
-         if (1 || IS_EXTERN (csym->etype))
+         if (IS_EXTERN (csym->etype))
            {
              /* do types match ? */
              if (checkType (csym->type, sym->type) != 1)
@@ -1584,6 +1599,13 @@ checkFunction (symbol * sym)
   value *exargs, *acargs;
   int argCnt = 0;
 
+  if (getenv("DEBUG_SANITY")) {
+    fprintf (stderr, "checkFunction: %s ", sym->name);
+  }
+
+  /* make sure the type is complete and sane */
+  checkTypeSanity(((symbol *)sym)->etype, ((symbol *)sym)->name);
+
   /* if not type then some kind of error */
   if (!sym->type)
     return 0;
index a6f938bab867760701fd05fd036e658996c21680..65270620a5b35c8728bf6c6372e7f2a51924fa36 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(symbol * sym);
+void checkTypeSanity(sym_link *etype, char *name);
 /* noun strings */
 extern char *nounName(sym_link *);
 
index 08f03e42d3d535e1d02f8b84260fc252a819389b..af3a6a9b4046467064bbdb2a60ec59bd4f5cbf97 100644 (file)
@@ -350,6 +350,7 @@ struct
 { W_EXESS_ARRAY_INITIALIZERS, ERROR_LEVEL_WARNING,
     "excess elements in array initializer after `%s' at line %d" },
 };
+
 /*
 -------------------------------------------------------------------------------
 SetErrorOut - Set the error output file