From: johanknol Date: Fri, 4 Apr 2003 09:39:06 +0000 (+0000) Subject: fixed bug #702907 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=0f7dd0b394676afa210e8d1a96b12029b190b956;p=fw%2Fsdcc fixed bug #702907 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2477 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index aef72885..f530bf02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-04-04 + + * src/SDCC.y: fixed bug #702907 + 2003-04-03 * device/lib/_mulint.c (_muluint): new #pragma LESS_PEDANTIC diff --git a/src/SDCC.y b/src/SDCC.y index 25ba60f9..644ecc51 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -662,8 +662,19 @@ struct_or_union_specifier : struct_or_union opt_stag '{' struct_declaration_list '}' { structdef *sdef ; + symbol *sym, *dsym; + + // check for duplicate structure members + for (sym=$4; sym; sym=sym->next) { + for (dsym=sym->next; dsym; dsym=dsym->next) { + if (strcmp(sym->name, dsym->name)==0) { + werror(E_DUPLICATE_MEMBER, + $1==STRUCT ? "struct" : "union", sym->name); + } + } + } - /* Create a structdef */ + /* Create a structdef */ sdef = $2 ; sdef->fields = reverseSyms($4) ; /* link the fields */ sdef->size = compStructSize($1,sdef); /* update size of */ @@ -709,11 +720,12 @@ struct_declaration_list : struct_declaration | struct_declaration_list struct_declaration { - symbol *sym = $2; - /* go to the end of the chain */ - while (sym->next) sym = sym->next; + symbol *sym=$2; + /* go to the end of the chain */ + while (sym->next) sym=sym->next; sym->next = $1 ; + $$ = $2; } ; @@ -765,39 +777,55 @@ struct_declarator enum_specifier : ENUM '{' enumerator_list '}' { - //addSymChain ($3); - //allocVariables(reverseSyms($3)) ; - $$ = copyLinkChain(cenum->type); - } + symbol *sym, *dsym; + char _error=0; + + // check for duplicate enums + for (sym=$3; sym; sym=sym->next) { + for (dsym=sym->next; dsym; dsym=dsym->next) { + if (strcmp(sym->name, dsym->name)==0) { + werror(E_DUPLICATE_MEMBER, "enum", sym->name); + _error++; + } + } + } + if (_error==0) { + $$ = copyLinkChain(cenum->type); + } else { + $$ = newIntLink(); + SPEC_NOUN($$)=0; + } + } + | ENUM identifier '{' enumerator_list '}' { - symbol *csym ; - - $2->type = copyLinkChain(cenum->type); - $2->etype = getSpec($2->type); - /* add this to the enumerator table */ - if (!(csym=findSym(enumTab,$2,$2->name)) && - (csym && csym->level == $2->level)) - werror(E_DUPLICATE_TYPEDEF,csym->name); - - addSym ( enumTab,$2,$2->name,$2->level,$2->block, 0); - //addSymChain ($4); - //allocVariables (reverseSyms($4)); - $$ = copyLinkChain(cenum->type); - SPEC_SCLS(getSpec($$)) = 0 ; - } + symbol *csym ; + + $2->type = copyLinkChain(cenum->type); + $2->etype = getSpec($2->type); + /* add this to the enumerator table */ + if (!(csym=findSym(enumTab,$2,$2->name)) && + (csym && csym->level == $2->level)) + werror(E_DUPLICATE_TYPEDEF,csym->name); + + addSym ( enumTab,$2,$2->name,$2->level,$2->block, 0); + //addSymChain ($4); + //allocVariables (reverseSyms($4)); + $$ = copyLinkChain(cenum->type); + SPEC_SCLS(getSpec($$)) = 0 ; + } | ENUM identifier { - symbol *csym ; - - /* check the enumerator table */ - if ((csym = findSym(enumTab,$2,$2->name))) - $$ = copyLinkChain(csym->type); - else { - $$ = newLink(SPECIFIER) ; - SPEC_NOUN($$) = V_INT ; - } - - SPEC_SCLS(getSpec($$)) = 0 ; - } + symbol *csym ; + + /* check the enumerator table */ + if ((csym = findSym(enumTab,$2,$2->name))) + $$ = copyLinkChain(csym->type); + else { + $$ = newLink(SPECIFIER) ; + SPEC_NOUN($$) = V_INT ; + } + + SPEC_SCLS(getSpec($$)) = 0 ; + } ; enumerator_list diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 1bc00c11..817c493f 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -380,6 +380,8 @@ struct "must specify assembler file name with -o in c1 mode" }, { W_ILLEGAL_OPT_COMBINATION, ERROR_LEVEL_WARNING, "illegal combination of options (--c1mode, -E, -S -c)" }, +{ E_DUPLICATE_MEMBER, ERROR_LEVEL_ERROR, + "duplicate %s member '%s'" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 73987cb0..82f980a4 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -178,6 +178,7 @@ SDCCERR - SDCC Standard error handler #define W_NO_FILE_ARG_IN_C1 160 #define E_NEED_OPT_O_IN_C1 161 #define W_ILLEGAL_OPT_COMBINATION 162 +#define E_DUPLICATE_MEMBER 163 /** Describes the maximum error level that will be logged. Any level * includes all of the levels listed after it.