From 53638777280c2f658894958794c3e7886a4294b5 Mon Sep 17 00:00:00 2001 From: epetrich Date: Wed, 31 Dec 2003 23:12:39 +0000 Subject: [PATCH] * src/SDCC.y (struct_or_union_specifier), * support/Util/SDCCerr.c, * support/Util/SDCCerr.h: verify that struct & union tags are used as declared. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3070 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 7 +++++++ src/SDCC.y | 31 +++++++++++++++++++++++++++---- support/Util/SDCCerr.c | 2 ++ support/Util/SDCCerr.h | 1 + 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3fa04f34..9f7ff2d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-12-31 Erik Petrich + + * src/SDCC.y (struct_or_union_specifier), + * support/Util/SDCCerr.c, + * support/Util/SDCCerr.h: verify that struct & union tags are used + as declared. + 2003-12-29 Erik Petrich * src/SDCCglobl.h: missing from yesterday's commits diff --git a/src/SDCC.y b/src/SDCC.y index fd2659a5..9c9eee76 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -727,13 +727,26 @@ sfr_attributes ; struct_or_union_specifier - : struct_or_union opt_stag '{' struct_declaration_list '}' + : struct_or_union opt_stag + { + if (!$2->type) + { + $2->type = $1; + } + else + { + if ($2->type != $1) + werror(E_BAD_TAG, $2->tag, $1==STRUCT ? "struct" : "union"); + } + + } + '{' struct_declaration_list '}' { structdef *sdef ; symbol *sym, *dsym; // check for errors in structure members - for (sym=$4; sym; sym=sym->next) { + for (sym=$5; sym; sym=sym->next) { if (IS_ABSOLUTE(sym->etype)) { werrorfl(filename, sym->lineDef, E_NOT_ALLOWED, "'at'"); SPEC_ABSA(sym->etype) = 0; @@ -752,7 +765,7 @@ struct_or_union_specifier /* Create a structdef */ sdef = $2 ; - sdef->fields = reverseSyms($4) ; /* link the fields */ + sdef->fields = reverseSyms($5) ; /* link the fields */ sdef->size = compStructSize($1,sdef); /* update size of */ /* Create the specifier */ @@ -764,7 +777,17 @@ struct_or_union_specifier { $$ = newLink(SPECIFIER) ; SPEC_NOUN($$) = V_STRUCT; - SPEC_STRUCT($$) = $2 ; + SPEC_STRUCT($$) = $2; + + if (!$2->type) + { + $2->type = $1; + } + else + { + if ($2->type != $1) + werror(E_BAD_TAG, $2->tag, $1==STRUCT ? "struct" : "union"); + } } ; diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 9720ce57..e3f59815 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -401,6 +401,8 @@ struct "not allowed in a critical section" }, { E_NOT_ALLOWED, ERROR_LEVEL_ERROR, "%s not allowed here" }, +{ E_BAD_TAG, ERROR_LEVEL_ERROR, + "'%s' is not a %s tag" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index aaafb642..dca6e2ab 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -188,6 +188,7 @@ SDCCERR - SDCC Standard error handler #define W_SAVE_RESTORE 170 /* unmatched #pragma SAVE and #pragma RESTORE */ #define E_INVALID_CRITICAL 171 /* operation invalid in critical sequence */ #define E_NOT_ALLOWED 172 /* %s not allowed here */ +#define E_BAD_TAG 173 /* '%s' is not a %s tag */ /** Describes the maximum error level that will be logged. Any level * includes all of the levels listed after it. -- 2.30.2