From bbf0be42537e2cc9acbfcda9ea3f12c9e78c6e89 Mon Sep 17 00:00:00 2001 From: johanknol Date: Tue, 12 Jun 2001 14:23:12 +0000 Subject: [PATCH] the next step in advanced type checking git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@880 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- device/lib/printfl.c | 4 +++- src/SDCC.y | 6 ++---- src/SDCCast.c | 6 ++++++ src/SDCCsymt.c | 48 ++++++++++++++++++++++++++++++------------ src/SDCCsymt.h | 2 +- support/Util/SDCCerr.c | 1 + 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/device/lib/printfl.c b/device/lib/printfl.c index ba5a3fa6..ec3b4523 100644 --- a/device/lib/printfl.c +++ b/device/lib/printfl.c @@ -41,8 +41,10 @@ */ #include -#include #include +#ifndef __ds390 +#include // for the SP +#endif static data volatile char ch; static data char radix ; diff --git a/src/SDCC.y b/src/SDCC.y index 51a853f5..afb2e5a9 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -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; } diff --git a/src/SDCCast.c b/src/SDCCast.c index 4abbdc67..9c62ab82 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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)); diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 01364f37..bf7a5809 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -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; diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index a6f938ba..65270620 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -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 *); diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 08f03e42..af3a6a9b 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -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 -- 2.30.2