+2003-12-31 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+ * 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 <epetrich@ivorytower.norman.ok.us>
* src/SDCCglobl.h: missing from yesterday's commits
;
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;
/* 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 */
{
$$ = 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");
+ }
}
;
"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" },
};
/*
#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.