From: johanknol Date: Mon, 11 Jun 2001 12:11:27 +0000 (+0000) Subject: some fixes X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=1abbb6977824a889ca516e4e57f775eeefce3a7f;p=fw%2Fsdcc some fixes git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@878 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCC.y b/src/SDCC.y index 59c7b982..51a853f5 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -597,7 +597,7 @@ type_specifier2 | CONST { $$=newLink(); $$->class = SPECIFIER ; - SPEC_SCLS($$) = S_CONSTANT ; + //SPEC_SCLS($$) = S_CONSTANT ; SPEC_CONST($$) = 1; } | VOLATILE { diff --git a/src/SDCCast.c b/src/SDCCast.c index 9eefea9c..4abbdc67 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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 */ diff --git a/src/SDCCglue.c b/src/SDCCglue.c index b95d90db..a59053eb 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -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 */ diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 6f20b982..01364f37 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -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); diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 648bfdf5..a6f938ba 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(sym_link *, char *); +void checkTypeSanity(symbol * sym); /* noun strings */ extern char *nounName(sym_link *); diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 04ec9060..08f03e42 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -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" }, }; /* ------------------------------------------------------------------------------- diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 4398867a..c70953d0 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -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.