mirror of
https://github.com/cc65/cc65.git
synced 2025-02-06 12:31:12 +00:00
More descriptive names for SymEntry usage.
This commit is contained in:
parent
959be2c98c
commit
2cda47cd36
@ -79,7 +79,7 @@ static void Parse (void)
|
||||
/* Top level parser routine. */
|
||||
{
|
||||
int comma;
|
||||
SymEntry* Entry;
|
||||
SymEntry* Sym;
|
||||
FuncDesc* FuncDef = 0;
|
||||
|
||||
/* Initialization for deferred operations */
|
||||
@ -142,7 +142,7 @@ static void Parse (void)
|
||||
}
|
||||
|
||||
/* Read declarations for this type */
|
||||
Entry = 0;
|
||||
Sym = 0;
|
||||
comma = 0;
|
||||
while (1) {
|
||||
|
||||
@ -196,10 +196,10 @@ static void Parse (void)
|
||||
}
|
||||
|
||||
/* Add an entry to the symbol table */
|
||||
Entry = AddGlobalSym (Decl.Ident, Decl.Type, Decl.StorageClass);
|
||||
Sym = AddGlobalSym (Decl.Ident, Decl.Type, Decl.StorageClass);
|
||||
|
||||
/* Add declaration attributes */
|
||||
SymUseAttr (Entry, &Decl);
|
||||
SymUseAttr (Sym, &Decl);
|
||||
|
||||
/* Reserve storage for the variable if we need to */
|
||||
if (Decl.StorageClass & SC_STORAGE) {
|
||||
@ -211,11 +211,11 @@ static void Parse (void)
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
|
||||
/* This is a definition with storage */
|
||||
if (SymIsDef (Entry)) {
|
||||
if (SymIsDef (Sym)) {
|
||||
Error ("Global variable '%s' has already been defined",
|
||||
Entry->Name);
|
||||
Sym->Name);
|
||||
}
|
||||
Entry->Flags |= SC_DEF;
|
||||
Sym->Flags |= SC_DEF;
|
||||
|
||||
/* We cannot initialize types of unknown size, or
|
||||
** void types in ISO modes.
|
||||
@ -245,21 +245,21 @@ static void Parse (void)
|
||||
}
|
||||
|
||||
/* Define a label */
|
||||
g_defgloblabel (Entry->Name);
|
||||
g_defgloblabel (Sym->Name);
|
||||
|
||||
/* Skip the '=' */
|
||||
NextToken ();
|
||||
|
||||
/* Parse the initialization */
|
||||
ParseInit (Entry->Type);
|
||||
ParseInit (Sym->Type);
|
||||
} else {
|
||||
|
||||
/* This is a declaration */
|
||||
if (IsTypeVoid (Decl.Type)) {
|
||||
/* We cannot declare variables of type void */
|
||||
Error ("Illegal type for variable '%s'", Decl.Ident);
|
||||
Entry->Flags &= ~(SC_STORAGE | SC_DEF);
|
||||
} else if (Size == 0 && SymIsDef (Entry) && !IsEmptiableObjectType (Decl.Type)) {
|
||||
Sym->Flags &= ~(SC_STORAGE | SC_DEF);
|
||||
} else if (Size == 0 && SymIsDef (Sym) && !IsEmptiableObjectType (Decl.Type)) {
|
||||
/* Size is unknown. Is it an array? */
|
||||
if (!IsTypeArray (Decl.Type)) {
|
||||
Error ("Variable '%s' has unknown size", Decl.Ident);
|
||||
@ -286,11 +286,11 @@ static void Parse (void)
|
||||
*/
|
||||
const char* bssName = GetSegName (SEG_BSS);
|
||||
|
||||
if (Entry->V.BssName && strcmp (Entry->V.BssName, bssName) != 0) {
|
||||
if (Sym->V.BssName && strcmp (Sym->V.BssName, bssName) != 0) {
|
||||
Error ("Global variable '%s' already was defined in the '%s' segment.",
|
||||
Entry->Name, Entry->V.BssName);
|
||||
Sym->Name, Sym->V.BssName);
|
||||
}
|
||||
Entry->V.BssName = xstrdup (bssName);
|
||||
Sym->V.BssName = xstrdup (bssName);
|
||||
|
||||
/* This is to make the automatical zeropage setting of the symbol
|
||||
** work right.
|
||||
@ -300,9 +300,9 @@ static void Parse (void)
|
||||
}
|
||||
|
||||
/* Make the symbol zeropage according to the segment address size */
|
||||
if ((Entry->Flags & SC_STATIC) != 0) {
|
||||
if ((Sym->Flags & SC_STATIC) != 0) {
|
||||
if (GetSegAddrSize (GetSegName (CS->CurDSeg)) == ADDR_SIZE_ZP) {
|
||||
Entry->Flags |= SC_ZEROPAGE;
|
||||
Sym->Flags |= SC_ZEROPAGE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ static void Parse (void)
|
||||
}
|
||||
|
||||
/* Function declaration? */
|
||||
if (Entry && IsTypeFunc (Entry->Type)) {
|
||||
if (Sym && IsTypeFunc (Sym->Type)) {
|
||||
|
||||
/* Function */
|
||||
if (!comma) {
|
||||
@ -327,7 +327,7 @@ static void Parse (void)
|
||||
NextToken ();
|
||||
} else {
|
||||
/* Parse the function body */
|
||||
NewFunc (Entry, FuncDef);
|
||||
NewFunc (Sym, FuncDef);
|
||||
|
||||
/* Make sure we aren't omitting any work */
|
||||
CheckDeferredOpAllDone ();
|
||||
@ -478,8 +478,9 @@ void Compile (const char* FileName)
|
||||
for (Entry = GetGlobalSymTab ()->SymHead; Entry; Entry = Entry->NextSym) {
|
||||
if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) {
|
||||
/* Assembly definition of uninitialized global variable */
|
||||
SymEntry* Sym = GetSymType (Entry->Type);
|
||||
SymEntry* TagSym = GetSymType (Entry->Type);
|
||||
unsigned Size = SizeOf (Entry->Type);
|
||||
|
||||
if (Size == 0 && IsTypeArray (Entry->Type)) {
|
||||
if (GetElementCount (Entry->Type) == UNSPECIFIED) {
|
||||
/* Assume array size of 1 */
|
||||
@ -488,11 +489,11 @@ void Compile (const char* FileName)
|
||||
Warning ("Incomplete array '%s[]' assumed to have one element", Entry->Name);
|
||||
}
|
||||
|
||||
Sym = GetSymType (GetElementType (Entry->Type));
|
||||
TagSym = GetSymType (GetElementType (Entry->Type));
|
||||
}
|
||||
|
||||
/* For non-ESU types, Size != 0 */
|
||||
if (Size != 0 || (Sym != 0 && SymIsDef (Sym))) {
|
||||
if (Size != 0 || (TagSym != 0 && SymIsDef (TagSym))) {
|
||||
/* Set the segment name only when it changes */
|
||||
if (strcmp (GetSegName (SEG_BSS), Entry->V.BssName) != 0) {
|
||||
SetSegName (SEG_BSS, Entry->V.BssName);
|
||||
|
@ -1307,9 +1307,9 @@ int IsESUType (const Type* T)
|
||||
int IsIncompleteESUType (const Type* T)
|
||||
/* Return true if this is an incomplete ESU type */
|
||||
{
|
||||
SymEntry* Sym = GetSymType (T);
|
||||
SymEntry* TagSym = GetSymType (T);
|
||||
|
||||
return Sym != 0 && !SymIsDef (Sym);
|
||||
return TagSym != 0 && !SymIsDef (TagSym);
|
||||
}
|
||||
|
||||
|
||||
|
@ -502,18 +502,18 @@ static SymEntry* ESUForwardDecl (const char* Name, unsigned Flags, unsigned* DSF
|
||||
/* Try to find an enum/struct/union with the given name. If there is none,
|
||||
** insert a forward declaration into the current lexical level.
|
||||
*/
|
||||
SymEntry* Entry = FindTagSym (Name);
|
||||
if (Entry == 0) {
|
||||
SymEntry* TagEntry = FindTagSym (Name);
|
||||
if (TagEntry == 0) {
|
||||
if ((Flags & SC_ESUTYPEMASK) != SC_ENUM) {
|
||||
Entry = AddStructSym (Name, Flags, 0, 0, DSFlags);
|
||||
TagEntry = AddStructSym (Name, Flags, 0, 0, DSFlags);
|
||||
} else {
|
||||
Entry = AddEnumSym (Name, Flags, 0, 0, DSFlags);
|
||||
TagEntry = AddEnumSym (Name, Flags, 0, 0, DSFlags);
|
||||
}
|
||||
} else if ((Entry->Flags & SC_TYPEMASK) != (Flags & SC_ESUTYPEMASK)) {
|
||||
} else if ((TagEntry->Flags & SC_TYPEMASK) != (Flags & SC_ESUTYPEMASK)) {
|
||||
/* Already defined, but not the same type class */
|
||||
Error ("Symbol '%s' is already different kind", Name);
|
||||
}
|
||||
return Entry;
|
||||
return TagEntry;
|
||||
}
|
||||
|
||||
|
||||
@ -809,15 +809,13 @@ static unsigned AliasAnonStructFields (const Declaration* D, SymEntry* Anon)
|
||||
*/
|
||||
{
|
||||
unsigned Count = 0;
|
||||
SymEntry* Field;
|
||||
SymEntry* Alias;
|
||||
|
||||
/* Get the pointer to the symbol table entry of the anon struct */
|
||||
SymEntry* Entry = GetESUSymEntry (D->Type);
|
||||
|
||||
/* Get the symbol table containing the fields. If it is empty, there has
|
||||
** been an error before, so bail out.
|
||||
*/
|
||||
SymTable* Tab = Entry->V.S.SymTab;
|
||||
SymTable* Tab = GetESUSymEntry (D->Type)->V.S.SymTab;
|
||||
if (Tab == 0) {
|
||||
/* Incomplete definition - has been flagged before */
|
||||
return 0;
|
||||
@ -826,24 +824,24 @@ static unsigned AliasAnonStructFields (const Declaration* D, SymEntry* Anon)
|
||||
/* Get a pointer to the list of symbols. Then walk the list adding copies
|
||||
** of the embedded struct to the current level.
|
||||
*/
|
||||
Entry = Tab->SymHead;
|
||||
while (Entry) {
|
||||
Field = Tab->SymHead;
|
||||
while (Field) {
|
||||
|
||||
/* Enter an alias of this symbol */
|
||||
if (!IsAnonName (Entry->Name)) {
|
||||
Alias = AddLocalSym (Entry->Name, Entry->Type, SC_STRUCTFIELD|SC_ALIAS, 0);
|
||||
Alias->V.A.Field = Entry;
|
||||
Alias->V.A.Offs = Anon->V.Offs + Entry->V.Offs;
|
||||
if (!IsAnonName (Field->Name)) {
|
||||
Alias = AddLocalSym (Field->Name, Field->Type, SC_STRUCTFIELD|SC_ALIAS, 0);
|
||||
Alias->V.A.Field = Field;
|
||||
Alias->V.A.Offs = Anon->V.Offs + Field->V.Offs;
|
||||
++Count;
|
||||
}
|
||||
|
||||
/* Currently, there can not be any attributes, but if there will be
|
||||
** some in the future, we want to know this.
|
||||
*/
|
||||
CHECK (Entry->Attr == 0);
|
||||
CHECK (Field->Attr == 0);
|
||||
|
||||
/* Next entry */
|
||||
Entry = Entry->NextSym;
|
||||
Field = Field->NextSym;
|
||||
}
|
||||
|
||||
/* Return the count of created aliases */
|
||||
@ -861,7 +859,7 @@ static SymEntry* ParseUnionDecl (const char* Name, unsigned* DSFlags)
|
||||
int FieldWidth; /* Width in bits, -1 if not a bit-field */
|
||||
SymTable* FieldTab;
|
||||
SymEntry* UnionTagEntry;
|
||||
SymEntry* Entry;
|
||||
SymEntry* Field;
|
||||
unsigned Flags = 0;
|
||||
unsigned PrevErrorCount = ErrorCount;
|
||||
|
||||
@ -945,17 +943,17 @@ static SymEntry* ParseUnionDecl (const char* Name, unsigned* DSFlags)
|
||||
AddBitField (Decl.Ident, Decl.Type, 0, 0, FieldWidth,
|
||||
SignednessSpecified);
|
||||
} else if (Decl.Ident[0] != '\0') {
|
||||
Entry = AddLocalSym (Decl.Ident, Decl.Type, SC_STRUCTFIELD, 0);
|
||||
Field = AddLocalSym (Decl.Ident, Decl.Type, SC_STRUCTFIELD, 0);
|
||||
if (IsAnonName (Decl.Ident)) {
|
||||
Entry->V.A.ANumber = UnionTagEntry->V.S.ACount++;
|
||||
AliasAnonStructFields (&Decl, Entry);
|
||||
Field->V.A.ANumber = UnionTagEntry->V.S.ACount++;
|
||||
AliasAnonStructFields (&Decl, Field);
|
||||
}
|
||||
|
||||
/* Check if the field itself has a flexible array member */
|
||||
if (IsClassStruct (Decl.Type)) {
|
||||
SymEntry* Sym = GetSymType (Decl.Type);
|
||||
if (Sym && SymHasFlexibleArrayMember (Sym)) {
|
||||
Entry->Flags |= SC_HAVEFAM;
|
||||
SymEntry* TagEntry = GetSymType (Decl.Type);
|
||||
if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) {
|
||||
Field->Flags |= SC_HAVEFAM;
|
||||
Flags |= SC_HAVEFAM;
|
||||
}
|
||||
}
|
||||
@ -1002,7 +1000,7 @@ static SymEntry* ParseStructDecl (const char* Name, unsigned* DSFlags)
|
||||
int FieldWidth; /* Width in bits, -1 if not a bit-field */
|
||||
SymTable* FieldTab;
|
||||
SymEntry* StructTagEntry;
|
||||
SymEntry* Entry;
|
||||
SymEntry* Field;
|
||||
unsigned Flags = 0;
|
||||
unsigned PrevErrorCount = ErrorCount;
|
||||
|
||||
@ -1147,17 +1145,17 @@ static SymEntry* ParseStructDecl (const char* Name, unsigned* DSFlags)
|
||||
StructSize += BitOffs / CHAR_BITS;
|
||||
BitOffs %= CHAR_BITS;
|
||||
} else if (Decl.Ident[0] != '\0') {
|
||||
Entry = AddLocalSym (Decl.Ident, Decl.Type, SC_STRUCTFIELD, StructSize);
|
||||
Field = AddLocalSym (Decl.Ident, Decl.Type, SC_STRUCTFIELD, StructSize);
|
||||
if (IsAnonName (Decl.Ident)) {
|
||||
Entry->V.A.ANumber = StructTagEntry->V.S.ACount++;
|
||||
AliasAnonStructFields (&Decl, Entry);
|
||||
Field->V.A.ANumber = StructTagEntry->V.S.ACount++;
|
||||
AliasAnonStructFields (&Decl, Field);
|
||||
}
|
||||
|
||||
/* Check if the field itself has a flexible array member */
|
||||
if (IsClassStruct (Decl.Type)) {
|
||||
SymEntry* Sym = GetSymType (Decl.Type);
|
||||
if (Sym && SymHasFlexibleArrayMember (Sym)) {
|
||||
Entry->Flags |= SC_HAVEFAM;
|
||||
SymEntry* TagEntry = GetSymType (Decl.Type);
|
||||
if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) {
|
||||
Field->Flags |= SC_HAVEFAM;
|
||||
Flags |= SC_HAVEFAM;
|
||||
}
|
||||
}
|
||||
@ -1214,7 +1212,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
|
||||
*/
|
||||
{
|
||||
ident Ident;
|
||||
SymEntry* Entry;
|
||||
SymEntry* TagEntry;
|
||||
|
||||
if (SignednessSpecified != NULL) {
|
||||
*SignednessSpecified = 0;
|
||||
@ -1384,10 +1382,10 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
|
||||
/* Remember we have an extra type decl */
|
||||
D->Flags |= DS_EXTRA_TYPE;
|
||||
/* Declare the union in the current scope */
|
||||
Entry = ParseUnionDecl (Ident, &D->Flags);
|
||||
TagEntry = ParseUnionDecl (Ident, &D->Flags);
|
||||
/* Encode the union entry into the type */
|
||||
D->Type[0].C = T_UNION;
|
||||
SetESUSymEntry (D->Type, Entry);
|
||||
SetESUSymEntry (D->Type, TagEntry);
|
||||
D->Type[1].C = T_END;
|
||||
break;
|
||||
|
||||
@ -1403,10 +1401,10 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
|
||||
/* Remember we have an extra type decl */
|
||||
D->Flags |= DS_EXTRA_TYPE;
|
||||
/* Declare the struct in the current scope */
|
||||
Entry = ParseStructDecl (Ident, &D->Flags);
|
||||
TagEntry = ParseStructDecl (Ident, &D->Flags);
|
||||
/* Encode the struct entry into the type */
|
||||
D->Type[0].C = T_STRUCT;
|
||||
SetESUSymEntry (D->Type, Entry);
|
||||
SetESUSymEntry (D->Type, TagEntry);
|
||||
D->Type[1].C = T_END;
|
||||
break;
|
||||
|
||||
@ -1426,10 +1424,10 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
|
||||
/* Remember we have an extra type decl */
|
||||
D->Flags |= DS_EXTRA_TYPE;
|
||||
/* Parse the enum decl */
|
||||
Entry = ParseEnumDecl (Ident, &D->Flags);
|
||||
TagEntry = ParseEnumDecl (Ident, &D->Flags);
|
||||
/* Encode the enum entry into the type */
|
||||
D->Type[0].C |= T_ENUM;
|
||||
SetESUSymEntry (D->Type, Entry);
|
||||
SetESUSymEntry (D->Type, TagEntry);
|
||||
D->Type[1].C = T_END;
|
||||
/* The signedness of enums is determined by the type, so say this is specified to avoid
|
||||
** the int -> unsigned int handling for plain int bit-fields in AddBitField.
|
||||
@ -1442,11 +1440,11 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
|
||||
case TOK_IDENT:
|
||||
/* This could be a label */
|
||||
if (NextTok.Tok != TOK_COLON || GetLexicalLevel () == LEX_LEVEL_STRUCT) {
|
||||
Entry = FindSym (CurTok.Ident);
|
||||
if (Entry && SymIsTypeDef (Entry)) {
|
||||
TagEntry = FindSym (CurTok.Ident);
|
||||
if (TagEntry && SymIsTypeDef (TagEntry)) {
|
||||
/* It's a typedef */
|
||||
NextToken ();
|
||||
TypeCopy (D->Type, Entry->Type);
|
||||
TypeCopy (D->Type, TagEntry->Type);
|
||||
/* If it's a typedef, we should actually use whether the signedness was
|
||||
** specified on the typedef, but that information has been lost. Treat the
|
||||
** signedness as being specified to work around the ICE in #1267.
|
||||
@ -1591,19 +1589,19 @@ static void ParseOldStyleParamList (FuncDesc* F)
|
||||
if (Decl.Ident[0] != '\0') {
|
||||
|
||||
/* We have a name given. Search for the symbol */
|
||||
SymEntry* Sym = FindLocalSym (Decl.Ident);
|
||||
if (Sym) {
|
||||
SymEntry* Param = FindLocalSym (Decl.Ident);
|
||||
if (Param) {
|
||||
/* Check if we already changed the type for this
|
||||
** parameter
|
||||
*/
|
||||
if (Sym->Flags & SC_DEFTYPE) {
|
||||
if (Param->Flags & SC_DEFTYPE) {
|
||||
/* Found it, change the default type to the one given */
|
||||
ChangeSymType (Sym, ParamTypeCvt (Decl.Type));
|
||||
ChangeSymType (Param, ParamTypeCvt (Decl.Type));
|
||||
/* Reset the "default type" flag */
|
||||
Sym->Flags &= ~SC_DEFTYPE;
|
||||
Param->Flags &= ~SC_DEFTYPE;
|
||||
} else {
|
||||
/* Type has already been changed */
|
||||
Error ("Redefinition for parameter '%s'", Sym->Name);
|
||||
Error ("Redefinition for parameter '%s'", Param->Name);
|
||||
}
|
||||
} else {
|
||||
Error ("Unknown identifier: '%s'", Decl.Ident);
|
||||
@ -1633,7 +1631,7 @@ static void ParseAnsiParamList (FuncDesc* F)
|
||||
|
||||
DeclSpec Spec;
|
||||
Declaration Decl;
|
||||
SymEntry* Sym;
|
||||
SymEntry* Param;
|
||||
|
||||
/* Allow an ellipsis as last parameter */
|
||||
if (CurTok.Tok == TOK_ELLIPSIS) {
|
||||
@ -1681,10 +1679,10 @@ static void ParseAnsiParamList (FuncDesc* F)
|
||||
ParseAttribute (&Decl);
|
||||
|
||||
/* Create a symbol table entry */
|
||||
Sym = AddLocalSym (Decl.Ident, ParamTypeCvt (Decl.Type), Decl.StorageClass, 0);
|
||||
Param = AddLocalSym (Decl.Ident, ParamTypeCvt (Decl.Type), Decl.StorageClass, 0);
|
||||
|
||||
/* Add attributes if we have any */
|
||||
SymUseAttr (Sym, &Decl);
|
||||
SymUseAttr (Param, &Decl);
|
||||
|
||||
/* If the parameter is a struct or union, emit a warning */
|
||||
if (IsClassStruct (Decl.Type)) {
|
||||
|
@ -280,11 +280,10 @@ static unsigned ExprCheckedSizeOf (const Type* T)
|
||||
/* Specially checked SizeOf() used in 'sizeof' expressions */
|
||||
{
|
||||
unsigned Size = SizeOf (T);
|
||||
SymEntry* Sym;
|
||||
|
||||
if (Size == 0) {
|
||||
Sym = GetSymType (T);
|
||||
if (Sym == 0 || !SymIsDef (Sym)) {
|
||||
SymEntry* TagSym = GetSymType (T);
|
||||
if (TagSym == 0 || !SymIsDef (TagSym)) {
|
||||
Error ("Cannot apply 'sizeof' to incomplete type '%s'", GetFullTypeName (T));
|
||||
}
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
/* Parse initialization of a struct or union. Return the number of data bytes. */
|
||||
{
|
||||
SymEntry* Sym;
|
||||
SymEntry* TagSym;
|
||||
SymTable* Tab;
|
||||
StructInitData SI;
|
||||
int HasCurly = 0;
|
||||
@ -452,15 +452,15 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
}
|
||||
|
||||
/* Get a pointer to the struct entry from the type */
|
||||
Sym = GetESUSymEntry (T);
|
||||
TagSym = GetESUSymEntry (T);
|
||||
|
||||
/* Get the size of the struct from the symbol table entry */
|
||||
SI.Size = Sym->V.S.Size;
|
||||
SI.Size = TagSym->V.S.Size;
|
||||
|
||||
/* Check if this struct definition has a field table. If it doesn't, it
|
||||
** is an incomplete definition.
|
||||
*/
|
||||
Tab = Sym->V.S.SymTab;
|
||||
Tab = TagSym->V.S.SymTab;
|
||||
if (Tab == 0) {
|
||||
Error ("Cannot initialize variables with incomplete type");
|
||||
/* Try error recovery */
|
||||
@ -470,7 +470,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
}
|
||||
|
||||
/* Get a pointer to the list of symbols */
|
||||
Sym = Tab->SymHead;
|
||||
TagSym = Tab->SymHead;
|
||||
|
||||
/* Initialize fields */
|
||||
SI.Offs = 0;
|
||||
@ -479,7 +479,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
while (CurTok.Tok != TOK_RCURLY) {
|
||||
|
||||
/* Check for excess elements */
|
||||
if (Sym == 0) {
|
||||
if (TagSym == 0) {
|
||||
/* Is there just one trailing comma before a closing curly? */
|
||||
if (NextTok.Tok == TOK_RCURLY && CurTok.Tok == TOK_COMMA) {
|
||||
/* Skip comma and exit scope */
|
||||
@ -495,7 +495,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
}
|
||||
|
||||
/* Check for special members that don't consume the initializer */
|
||||
if ((Sym->Flags & SC_ALIAS) == SC_ALIAS) {
|
||||
if ((TagSym->Flags & SC_ALIAS) == SC_ALIAS) {
|
||||
/* Just skip */
|
||||
goto NextMember;
|
||||
}
|
||||
@ -503,13 +503,13 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
/* This may be an anonymous bit-field, in which case it doesn't
|
||||
** have an initializer.
|
||||
*/
|
||||
if (SymIsBitField (Sym) && (IsAnonName (Sym->Name))) {
|
||||
if (SymIsBitField (TagSym) && (IsAnonName (TagSym->Name))) {
|
||||
/* Account for the data and output it if we have at least a full
|
||||
** byte. We may have more if there was storage unit overlap, for
|
||||
** example two consecutive 7 bit fields. Those would be packed
|
||||
** into 2 bytes.
|
||||
*/
|
||||
SI.ValBits += Sym->Type->A.B.Width;
|
||||
SI.ValBits += TagSym->Type->A.B.Width;
|
||||
CHECK (SI.ValBits <= CHAR_BIT * sizeof(SI.BitVal));
|
||||
/* TODO: Generalize this so any type can be used. */
|
||||
CHECK (SI.ValBits <= LONG_BITS);
|
||||
@ -526,7 +526,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
SkipComma = 0;
|
||||
}
|
||||
|
||||
if (SymIsBitField (Sym)) {
|
||||
if (SymIsBitField (TagSym)) {
|
||||
|
||||
/* Parse initialization of one field. Bit-fields need a special
|
||||
** handling.
|
||||
@ -537,14 +537,14 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
unsigned Shift;
|
||||
|
||||
/* Calculate the bitmask from the bit-field data */
|
||||
unsigned long Mask = shl_l (1UL, Sym->Type->A.B.Width) - 1UL;
|
||||
unsigned long Mask = shl_l (1UL, TagSym->Type->A.B.Width) - 1UL;
|
||||
|
||||
/* Safety ... */
|
||||
CHECK (Sym->V.Offs * CHAR_BITS + Sym->Type->A.B.Offs ==
|
||||
CHECK (TagSym->V.Offs * CHAR_BITS + TagSym->Type->A.B.Offs ==
|
||||
SI.Offs * CHAR_BITS + SI.ValBits);
|
||||
|
||||
/* Read the data, check for a constant integer, do a range check */
|
||||
Field = ParseScalarInitInternal (IntPromotion (Sym->Type));
|
||||
Field = ParseScalarInitInternal (IntPromotion (TagSym->Type));
|
||||
if (!ED_IsConstAbsInt (&Field)) {
|
||||
Error ("Constant initializer expected");
|
||||
ED_MakeConstAbsInt (&Field, 1);
|
||||
@ -554,19 +554,19 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
** any useful bits.
|
||||
*/
|
||||
Val = (unsigned long) Field.IVal & Mask;
|
||||
if (IsSignUnsigned (Sym->Type)) {
|
||||
if (IsSignUnsigned (TagSym->Type)) {
|
||||
if (Field.IVal < 0 || (unsigned long) Field.IVal != Val) {
|
||||
Warning (IsSignUnsigned (Field.Type) ?
|
||||
"Implicit truncation from '%s' to '%s : %u' in bit-field initializer"
|
||||
" changes value from %lu to %lu" :
|
||||
"Implicit truncation from '%s' to '%s : %u' in bit-field initializer"
|
||||
" changes value from %ld to %lu",
|
||||
GetFullTypeName (Field.Type), GetFullTypeName (Sym->Type),
|
||||
Sym->Type->A.B.Width, Field.IVal, Val);
|
||||
GetFullTypeName (Field.Type), GetFullTypeName (TagSym->Type),
|
||||
TagSym->Type->A.B.Width, Field.IVal, Val);
|
||||
}
|
||||
} else {
|
||||
/* Sign extend back to full width of host long. */
|
||||
unsigned ShiftBits = sizeof (long) * CHAR_BIT - Sym->Type->A.B.Width;
|
||||
unsigned ShiftBits = sizeof (long) * CHAR_BIT - TagSym->Type->A.B.Width;
|
||||
long RestoredVal = asr_l (asl_l (Val, ShiftBits), ShiftBits);
|
||||
if (Field.IVal != RestoredVal) {
|
||||
Warning (IsSignUnsigned (Field.Type) ?
|
||||
@ -574,17 +574,17 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
" changes value from %lu to %ld" :
|
||||
"Implicit truncation from '%s' to '%s : %u' in bit-field initializer"
|
||||
" changes value from %ld to %ld",
|
||||
GetFullTypeName (Field.Type), GetFullTypeName (Sym->Type),
|
||||
Sym->Type->A.B.Width, Field.IVal, RestoredVal);
|
||||
GetFullTypeName (Field.Type), GetFullTypeName (TagSym->Type),
|
||||
TagSym->Type->A.B.Width, Field.IVal, RestoredVal);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the value to the currently stored bit-field value */
|
||||
Shift = (Sym->V.Offs - SI.Offs) * CHAR_BITS + Sym->Type->A.B.Offs;
|
||||
Shift = (TagSym->V.Offs - SI.Offs) * CHAR_BITS + TagSym->Type->A.B.Offs;
|
||||
SI.BitVal |= (Val << Shift);
|
||||
|
||||
/* Account for the data and output any full bytes we have. */
|
||||
SI.ValBits += Sym->Type->A.B.Width;
|
||||
SI.ValBits += TagSym->Type->A.B.Width;
|
||||
/* Make sure unsigned is big enough to hold the value, 32 bits.
|
||||
** This cannot be more than 32 bits because a 16-bit or 32-bit
|
||||
** bit-field will always be byte-aligned with padding before it
|
||||
@ -609,7 +609,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
/* Flexible array members may only be initialized if they are
|
||||
** the last field (or part of the last struct field).
|
||||
*/
|
||||
SI.Offs += ParseInitInternal (Sym->Type, Braces, AllowFlexibleMembers && Sym->NextSym == 0);
|
||||
SI.Offs += ParseInitInternal (TagSym->Type, Braces, AllowFlexibleMembers && TagSym->NextSym == 0);
|
||||
}
|
||||
|
||||
/* More initializers? */
|
||||
@ -624,10 +624,10 @@ NextMember:
|
||||
/* Next member. For unions, only the first one can be initialized */
|
||||
if (IsTypeUnion (T)) {
|
||||
/* Union */
|
||||
Sym = 0;
|
||||
TagSym = 0;
|
||||
} else {
|
||||
/* Struct */
|
||||
Sym = Sym->NextSym;
|
||||
TagSym = TagSym->NextSym;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -625,8 +625,8 @@ SymEntry FindStructField (const Type* T, const char* Name)
|
||||
** value, or an empty entry struct if the field is not found.
|
||||
*/
|
||||
{
|
||||
SymEntry* Entry = 0;
|
||||
SymEntry Field;
|
||||
SymEntry* Field = 0;
|
||||
SymEntry Res;
|
||||
int Offs = 0;
|
||||
|
||||
/* The given type may actually be a pointer to struct/union */
|
||||
@ -637,35 +637,35 @@ SymEntry FindStructField (const Type* T, const char* Name)
|
||||
/* Only structs/unions have struct/union fields... */
|
||||
if (IsClassStruct (T)) {
|
||||
|
||||
/* Get a pointer to the struct/union type */
|
||||
const SymEntry* Struct = GetESUSymEntry (T);
|
||||
CHECK (Struct != 0);
|
||||
/* Get a pointer to the struct/union tag */
|
||||
const SymEntry* TagSym = GetESUSymEntry (T);
|
||||
CHECK (TagSym != 0);
|
||||
|
||||
/* Now search in the struct/union symbol table. Beware: The table may
|
||||
** not exist.
|
||||
*/
|
||||
if (Struct->V.S.SymTab) {
|
||||
Entry = FindSymInTable (Struct->V.S.SymTab, Name, HashStr (Name));
|
||||
if (TagSym->V.S.SymTab) {
|
||||
Field = FindSymInTable (TagSym->V.S.SymTab, Name, HashStr (Name));
|
||||
|
||||
if (Entry != 0) {
|
||||
Offs = Entry->V.Offs;
|
||||
if (Field != 0) {
|
||||
Offs = Field->V.Offs;
|
||||
}
|
||||
|
||||
while (Entry != 0 && (Entry->Flags & SC_ALIAS) == SC_ALIAS) {
|
||||
while (Field != 0 && (Field->Flags & SC_ALIAS) == SC_ALIAS) {
|
||||
/* Get the real field */
|
||||
Entry = Entry->V.A.Field;
|
||||
Field = Field->V.A.Field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Entry != 0) {
|
||||
Field = *Entry;
|
||||
Field.V.Offs = Offs;
|
||||
if (Field != 0) {
|
||||
Res = *Field;
|
||||
Res.V.Offs = Offs;
|
||||
} else {
|
||||
memset (&Field, 0, sizeof(SymEntry));
|
||||
memset (&Res, 0, sizeof(SymEntry));
|
||||
}
|
||||
|
||||
return Field;
|
||||
return Res;
|
||||
}
|
||||
|
||||
|
||||
@ -689,15 +689,15 @@ static int IsDistinctRedef (const Type* lhst, const Type* rhst, typecmpcode_t Co
|
||||
}
|
||||
|
||||
|
||||
static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags)
|
||||
static int HandleSymRedefinition (SymEntry* Sym, const Type* T, unsigned Flags)
|
||||
/* Check and handle redefinition of existing symbols.
|
||||
** Complete array sizes and function descriptors as well.
|
||||
** Return true if there *is* an error.
|
||||
*/
|
||||
{
|
||||
/* Get the type info of the existing symbol */
|
||||
Type* E_Type = Entry->Type;
|
||||
unsigned E_SCType = Entry->Flags & SC_TYPEMASK;
|
||||
Type* E_Type = Sym->Type;
|
||||
unsigned E_SCType = Sym->Flags & SC_TYPEMASK;
|
||||
unsigned SCType = Flags & SC_TYPEMASK;
|
||||
|
||||
/* Some symbols may be redeclared if certain requirements are met */
|
||||
@ -706,16 +706,16 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags
|
||||
/* Existing typedefs cannot be redeclared as anything different */
|
||||
if (SCType == SC_TYPEDEF) {
|
||||
if (IsDistinctRedef (E_Type, T, TC_IDENTICAL, TCF_MASK_QUAL)) {
|
||||
Error ("Conflicting types for typedef '%s'", Entry->Name);
|
||||
Error ("Conflicting types for typedef '%s'", Sym->Name);
|
||||
Note ("'%s' vs '%s'", GetFullTypeName (T), GetFullTypeName (E_Type));
|
||||
Entry = 0;
|
||||
Sym = 0;
|
||||
}
|
||||
} else {
|
||||
Error ("Redefinition of typedef '%s' as different kind of symbol", Entry->Name);
|
||||
Entry = 0;
|
||||
Error ("Redefinition of typedef '%s' as different kind of symbol", Sym->Name);
|
||||
Sym = 0;
|
||||
}
|
||||
|
||||
} else if ((Entry->Flags & SC_FUNC) == SC_FUNC) {
|
||||
} else if ((Sym->Flags & SC_FUNC) == SC_FUNC) {
|
||||
|
||||
/* In case of a function, use the new type descriptor, since it
|
||||
** contains pointers to the new symbol tables that are needed if
|
||||
@ -726,27 +726,27 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags
|
||||
if (IsTypeFunc (T)) {
|
||||
|
||||
/* Check for duplicate function definitions */
|
||||
if (SymIsDef (Entry) && (Flags & SC_DEF) == SC_DEF) {
|
||||
if (SymIsDef (Sym) && (Flags & SC_DEF) == SC_DEF) {
|
||||
Error ("Body for function '%s' has already been defined",
|
||||
Entry->Name);
|
||||
Entry = 0;
|
||||
Sym->Name);
|
||||
Sym = 0;
|
||||
} else {
|
||||
/* New type must be compatible with the composite prototype */
|
||||
if (IsDistinctRedef (E_Type, T, TC_EQUAL, TCF_MASK_QUAL)) {
|
||||
Error ("Conflicting function types for '%s'", Entry->Name);
|
||||
Error ("Conflicting function types for '%s'", Sym->Name);
|
||||
Note ("'%s' vs '%s'", GetFullTypeName (T), GetFullTypeName (E_Type));
|
||||
Entry = 0;
|
||||
Sym = 0;
|
||||
} else {
|
||||
/* Refine the existing composite prototype with this new
|
||||
** one.
|
||||
*/
|
||||
RefineFuncDesc (Entry->Type, T);
|
||||
RefineFuncDesc (Sym->Type, T);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Error ("Redefinition of function '%s' as different kind of symbol", Entry->Name);
|
||||
Entry = 0;
|
||||
Error ("Redefinition of function '%s' as different kind of symbol", Sym->Name);
|
||||
Sym = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -765,9 +765,9 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags
|
||||
if ((Size != UNSPECIFIED && ESize != UNSPECIFIED && Size != ESize) ||
|
||||
IsDistinctRedef (E_Type + 1, T + 1, TC_IDENTICAL, TCF_MASK_QUAL)) {
|
||||
/* Conflicting element types */
|
||||
Error ("Conflicting array types for '%s[]'", Entry->Name);
|
||||
Error ("Conflicting array types for '%s[]'", Sym->Name);
|
||||
Note ("'%s' vs '%s'", GetFullTypeName (T), GetFullTypeName (E_Type));
|
||||
Entry = 0;
|
||||
Sym = 0;
|
||||
} else {
|
||||
/* Check if we have a size in the existing definition */
|
||||
if (ESize == UNSPECIFIED) {
|
||||
@ -780,25 +780,25 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags
|
||||
|
||||
/* New type must be equivalent */
|
||||
if (SCType != E_SCType) {
|
||||
Error ("Redefinition of '%s' as different kind of symbol", Entry->Name);
|
||||
Entry = 0;
|
||||
Error ("Redefinition of '%s' as different kind of symbol", Sym->Name);
|
||||
Sym = 0;
|
||||
} else if (IsDistinctRedef (E_Type, T, TC_EQUAL, TCF_MASK_QUAL)) {
|
||||
Error ("Conflicting types for '%s'", Entry->Name);
|
||||
Error ("Conflicting types for '%s'", Sym->Name);
|
||||
Note ("'%s' vs '%s'", GetFullTypeName (T), GetFullTypeName (E_Type));
|
||||
Entry = 0;
|
||||
Sym = 0;
|
||||
} else if (E_SCType == SC_ENUMERATOR) {
|
||||
/* Enumerators aren't allowed to be redeclared at all, even if
|
||||
** all occurences are identical. The current code logic won't
|
||||
** get here, but let's just do it.
|
||||
*/
|
||||
Error ("Redeclaration of enumerator constant '%s'", Entry->Name);
|
||||
Entry = 0;
|
||||
Error ("Redeclaration of enumerator constant '%s'", Sym->Name);
|
||||
Sym = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return if there are any errors */
|
||||
return Entry == 0;
|
||||
return Sym == 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user