1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-12 17:30:50 +00:00

More consistent names for SymEntry functions.

This commit is contained in:
acqn 2022-10-12 13:10:17 +08:00
parent 2cda47cd36
commit a2dfa7c721
12 changed files with 175 additions and 194 deletions

View File

@ -478,7 +478,7 @@ void Compile (const char* FileName)
for (Entry = GetGlobalSymTab ()->SymHead; Entry; Entry = Entry->NextSym) { for (Entry = GetGlobalSymTab ()->SymHead; Entry; Entry = Entry->NextSym) {
if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) { if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) {
/* Assembly definition of uninitialized global variable */ /* Assembly definition of uninitialized global variable */
SymEntry* TagSym = GetSymType (Entry->Type); SymEntry* TagSym = GetESUTagSym (Entry->Type);
unsigned Size = SizeOf (Entry->Type); unsigned Size = SizeOf (Entry->Type);
if (Size == 0 && IsTypeArray (Entry->Type)) { if (Size == 0 && IsTypeArray (Entry->Type)) {
@ -489,7 +489,7 @@ void Compile (const char* FileName)
Warning ("Incomplete array '%s[]' assumed to have one element", Entry->Name); Warning ("Incomplete array '%s[]' assumed to have one element", Entry->Name);
} }
TagSym = GetSymType (GetElementType (Entry->Type)); TagSym = GetESUTagSym (GetElementType (Entry->Type));
} }
/* For non-ESU types, Size != 0 */ /* For non-ESU types, Size != 0 */

View File

@ -48,6 +48,7 @@
#include "fp.h" #include "fp.h"
#include "funcdesc.h" #include "funcdesc.h"
#include "global.h" #include "global.h"
#include "ident.h"
#include "symtab.h" #include "symtab.h"
@ -86,6 +87,83 @@ const Type type_c_void_p[] = { TYPE(T_PTR), TYPE(T_C_VOID), TYPE(T_END) };
const char* GetBasicTypeName (const Type* T)
/* Return a const name string of the basic type.
** Return "type" for unknown basic types.
*/
{
switch (GetRawType (T)) {
case T_TYPE_ENUM: return "enum";
case T_TYPE_BITFIELD: return "bit-field";
case T_TYPE_FLOAT: return "float";
case T_TYPE_DOUBLE: return "double";
case T_TYPE_VOID: return "void";
case T_TYPE_STRUCT: return "struct";
case T_TYPE_UNION: return "union";
case T_TYPE_ARRAY: return "array";
case T_TYPE_PTR: return "pointer";
case T_TYPE_FUNC: return "function";
case T_TYPE_NONE: /* FALLTHROUGH */
default: break;
}
if (IsClassInt (T)) {
if (IsRawSignSigned (T)) {
switch (GetRawType (T)) {
case T_TYPE_CHAR: return "signed char";
case T_TYPE_SHORT: return "short";
case T_TYPE_INT: return "int";
case T_TYPE_LONG: return "long";
case T_TYPE_LONGLONG: return "long long";
default:
return "signed integer";
}
} else if (IsRawSignUnsigned (T)) {
switch (GetRawType (T)) {
case T_TYPE_CHAR: return "unsigned char";
case T_TYPE_SHORT: return "unsigned short";
case T_TYPE_INT: return "unsigned int";
case T_TYPE_LONG: return "unsigned long";
case T_TYPE_LONGLONG: return "unsigned long long";
default:
return "unsigned integer";
}
} else {
switch (GetRawType (T)) {
case T_TYPE_CHAR: return "char";
case T_TYPE_SHORT: return "short";
case T_TYPE_INT: return "int";
case T_TYPE_LONG: return "long";
case T_TYPE_LONGLONG: return "long long";
default:
return "integer";
}
}
}
return "type";
}
static const char* GetTagSymName (const Type* T)
/* Return a name string of the type or the symbol name if it is an ESU type.
** Note: This may use a static buffer that could be overwritten by other calls.
*/
{
static char TypeName [IDENTSIZE + 16];
SymEntry* TagSym;
TagSym = GetESUTagSym (T);
if (TagSym == 0) {
return GetBasicTypeName (T);
}
sprintf (TypeName, "%s %s", GetBasicTypeName (T),
TagSym->Name[0] != '\0' ? TagSym->Name : "<unknown>");
return TypeName;
}
static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBuf* East, const Type* T) static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBuf* East, const Type* T)
/* Return the name string of the given type split into a western part and an /* Return the name string of the given type split into a western part and an
** eastern part. ** eastern part.
@ -208,7 +286,7 @@ static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBu
} }
if (!IsTypeBitField (T)) { if (!IsTypeBitField (T)) {
SB_AppendStr (&Buf, GetSymTypeName (T)); SB_AppendStr (&Buf, GetTagSymName (T));
} else { } else {
SB_AppendStr (&Buf, GetBasicTypeName (T + 1)); SB_AppendStr (&Buf, GetBasicTypeName (T + 1));
} }
@ -228,63 +306,6 @@ static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBu
const char* GetBasicTypeName (const Type* T)
/* Return a const name string of the basic type.
** Return "type" for unknown basic types.
*/
{
switch (GetRawType (T)) {
case T_TYPE_ENUM: return "enum";
case T_TYPE_BITFIELD: return "bit-field";
case T_TYPE_FLOAT: return "float";
case T_TYPE_DOUBLE: return "double";
case T_TYPE_VOID: return "void";
case T_TYPE_STRUCT: return "struct";
case T_TYPE_UNION: return "union";
case T_TYPE_ARRAY: return "array";
case T_TYPE_PTR: return "pointer";
case T_TYPE_FUNC: return "function";
case T_TYPE_NONE: /* FALLTHROUGH */
default: break;
}
if (IsClassInt (T)) {
if (IsRawSignSigned (T)) {
switch (GetRawType (T)) {
case T_TYPE_CHAR: return "signed char";
case T_TYPE_SHORT: return "short";
case T_TYPE_INT: return "int";
case T_TYPE_LONG: return "long";
case T_TYPE_LONGLONG: return "long long";
default:
return "signed integer";
}
} else if (IsRawSignUnsigned (T)) {
switch (GetRawType (T)) {
case T_TYPE_CHAR: return "unsigned char";
case T_TYPE_SHORT: return "unsigned short";
case T_TYPE_INT: return "unsigned int";
case T_TYPE_LONG: return "unsigned long";
case T_TYPE_LONGLONG: return "unsigned long long";
default:
return "unsigned integer";
}
} else {
switch (GetRawType (T)) {
case T_TYPE_CHAR: return "char";
case T_TYPE_SHORT: return "short";
case T_TYPE_INT: return "int";
case T_TYPE_LONG: return "long";
case T_TYPE_LONGLONG: return "long long";
default:
return "integer";
}
}
}
return "type";
}
const char* GetFullTypeName (const Type* T) const char* GetFullTypeName (const Type* T)
/* Return the full name string of the given type */ /* Return the full name string of the given type */
{ {
@ -1307,7 +1328,7 @@ int IsESUType (const Type* T)
int IsIncompleteESUType (const Type* T) int IsIncompleteESUType (const Type* T)
/* Return true if this is an incomplete ESU type */ /* Return true if this is an incomplete ESU type */
{ {
SymEntry* TagSym = GetSymType (T); SymEntry* TagSym = GetESUTagSym (T);
return TagSym != 0 && !SymIsDef (TagSym); return TagSym != 0 && !SymIsDef (TagSym);
} }
@ -1486,20 +1507,21 @@ const Type* GetBaseElementType (const Type* T)
struct SymEntry* GetESUSymEntry (const Type* T) struct SymEntry* GetESUTagSym (const Type* T)
/* Return a SymEntry pointer from an enum/struct/union type */ /* Get the tag symbol entry of the enum/struct/union type.
** Return 0 if it is not an enum/struct/union.
*/
{ {
/* Only enums, structs or unions have a SymEntry attribute */ if ((IsClassStruct (T) || IsTypeEnum (T))) {
CHECK (IsClassStruct (T) || IsTypeEnum (T)); return T->A.S;
}
/* Return the attribute */ return 0;
return T->A.S;
} }
void SetESUSymEntry (Type* T, struct SymEntry* S) void SetESUTagSym (Type* T, struct SymEntry* S)
/* Set the SymEntry pointer for an enum/struct/union type */ /* Set the tag symbol entry of the enum/struct/union type */
{ {
/* Only enums, structs or unions have a SymEntry attribute */ /* Only enums, structs or unions have a SymEntry attribute */
CHECK (IsClassStruct (T) || IsTypeEnum (T)); CHECK (IsClassStruct (T) || IsTypeEnum (T));
@ -1570,7 +1592,7 @@ void PrintFuncSig (FILE* F, const char* Name, const Type* T)
if (SymIsRegVar (Param)) { if (SymIsRegVar (Param)) {
SB_AppendStr (&ParamList, "register "); SB_AppendStr (&ParamList, "register ");
} }
if (!HasAnonName (Param)) { if (!SymHasAnonName (Param)) {
SB_AppendStr (&Buf, Param->Name); SB_AppendStr (&Buf, Param->Name);
} }
SB_AppendStr (&ParamList, SB_GetConstBuf (GetFullTypeNameBuf (&Buf, Param->Type))); SB_AppendStr (&ParamList, SB_GetConstBuf (GetFullTypeNameBuf (&Buf, Param->Type)));

View File

@ -943,11 +943,13 @@ const Type* GetBaseElementType (const Type* T);
** the element type that is not an array. ** the element type that is not an array.
*/ */
struct SymEntry* GetESUSymEntry (const Type* T) attribute ((const)); struct SymEntry* GetESUTagSym (const Type* T) attribute ((const));
/* Return a SymEntry pointer from an enum/struct/union type */ /* Get the tag symbol entry of the enum/struct/union type.
** Return 0 if it is not an enum/struct/union.
*/
void SetESUSymEntry (Type* T, struct SymEntry* S); void SetESUTagSym (Type* T, struct SymEntry* S);
/* Set the SymEntry pointer for an enum/struct/union type */ /* Set the tag symbol entry of the enum/struct/union type */
TypeCode AddrSizeQualifier (unsigned AddrSize); TypeCode AddrSizeQualifier (unsigned AddrSize);
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */ /* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */

View File

@ -815,7 +815,7 @@ static unsigned AliasAnonStructFields (const Declaration* D, SymEntry* Anon)
/* Get the symbol table containing the fields. If it is empty, there has /* Get the symbol table containing the fields. If it is empty, there has
** been an error before, so bail out. ** been an error before, so bail out.
*/ */
SymTable* Tab = GetESUSymEntry (D->Type)->V.S.SymTab; SymTable* Tab = GetESUTagSym (D->Type)->V.S.SymTab;
if (Tab == 0) { if (Tab == 0) {
/* Incomplete definition - has been flagged before */ /* Incomplete definition - has been flagged before */
return 0; return 0;
@ -951,7 +951,7 @@ static SymEntry* ParseUnionDecl (const char* Name, unsigned* DSFlags)
/* Check if the field itself has a flexible array member */ /* Check if the field itself has a flexible array member */
if (IsClassStruct (Decl.Type)) { if (IsClassStruct (Decl.Type)) {
SymEntry* TagEntry = GetSymType (Decl.Type); SymEntry* TagEntry = GetESUTagSym (Decl.Type);
if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) { if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) {
Field->Flags |= SC_HAVEFAM; Field->Flags |= SC_HAVEFAM;
Flags |= SC_HAVEFAM; Flags |= SC_HAVEFAM;
@ -1153,7 +1153,7 @@ static SymEntry* ParseStructDecl (const char* Name, unsigned* DSFlags)
/* Check if the field itself has a flexible array member */ /* Check if the field itself has a flexible array member */
if (IsClassStruct (Decl.Type)) { if (IsClassStruct (Decl.Type)) {
SymEntry* TagEntry = GetSymType (Decl.Type); SymEntry* TagEntry = GetESUTagSym (Decl.Type);
if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) { if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) {
Field->Flags |= SC_HAVEFAM; Field->Flags |= SC_HAVEFAM;
Flags |= SC_HAVEFAM; Flags |= SC_HAVEFAM;
@ -1385,7 +1385,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
TagEntry = ParseUnionDecl (Ident, &D->Flags); TagEntry = ParseUnionDecl (Ident, &D->Flags);
/* Encode the union entry into the type */ /* Encode the union entry into the type */
D->Type[0].C = T_UNION; D->Type[0].C = T_UNION;
SetESUSymEntry (D->Type, TagEntry); SetESUTagSym (D->Type, TagEntry);
D->Type[1].C = T_END; D->Type[1].C = T_END;
break; break;
@ -1404,7 +1404,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
TagEntry = ParseStructDecl (Ident, &D->Flags); TagEntry = ParseStructDecl (Ident, &D->Flags);
/* Encode the struct entry into the type */ /* Encode the struct entry into the type */
D->Type[0].C = T_STRUCT; D->Type[0].C = T_STRUCT;
SetESUSymEntry (D->Type, TagEntry); SetESUTagSym (D->Type, TagEntry);
D->Type[1].C = T_END; D->Type[1].C = T_END;
break; break;
@ -1427,7 +1427,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
TagEntry = ParseEnumDecl (Ident, &D->Flags); TagEntry = ParseEnumDecl (Ident, &D->Flags);
/* Encode the enum entry into the type */ /* Encode the enum entry into the type */
D->Type[0].C |= T_ENUM; D->Type[0].C |= T_ENUM;
SetESUSymEntry (D->Type, TagEntry); SetESUTagSym (D->Type, TagEntry);
D->Type[1].C = T_END; D->Type[1].C = T_END;
/* The signedness of enums is determined by the type, so say this is specified to avoid /* 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. ** the int -> unsigned int handling for plain int bit-fields in AddBitField.
@ -1596,7 +1596,7 @@ static void ParseOldStyleParamList (FuncDesc* F)
*/ */
if (Param->Flags & SC_DEFTYPE) { if (Param->Flags & SC_DEFTYPE) {
/* Found it, change the default type to the one given */ /* Found it, change the default type to the one given */
ChangeSymType (Param, ParamTypeCvt (Decl.Type)); SymChangeType (Param, ParamTypeCvt (Decl.Type));
/* Reset the "default type" flag */ /* Reset the "default type" flag */
Param->Flags &= ~SC_DEFTYPE; Param->Flags &= ~SC_DEFTYPE;
} else { } else {

View File

@ -282,7 +282,7 @@ static unsigned ExprCheckedSizeOf (const Type* T)
unsigned Size = SizeOf (T); unsigned Size = SizeOf (T);
if (Size == 0) { if (Size == 0) {
SymEntry* TagSym = GetSymType (T); SymEntry* TagSym = GetESUTagSym (T);
if (TagSym == 0 || !SymIsDef (TagSym)) { if (TagSym == 0 || !SymIsDef (TagSym)) {
Error ("Cannot apply 'sizeof' to incomplete type '%s'", GetFullTypeName (T)); Error ("Cannot apply 'sizeof' to incomplete type '%s'", GetFullTypeName (T));
} }

View File

@ -613,7 +613,7 @@ void NewFunc (SymEntry* Func, FuncDesc* D)
/* Could we allocate a register? */ /* Could we allocate a register? */
if (Reg < 0) { if (Reg < 0) {
/* No register available: Convert parameter to auto */ /* No register available: Convert parameter to auto */
CvtRegVarToAuto (Param); SymCvtRegVarToAuto (Param);
} else { } else {
/* Remember the register offset */ /* Remember the register offset */
Param->V.R.RegOffs = Reg; Param->V.R.RegOffs = Reg;

View File

@ -452,7 +452,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
} }
/* Get a pointer to the struct entry from the type */ /* Get a pointer to the struct entry from the type */
TagSym = GetESUSymEntry (T); TagSym = GetESUTagSym (T);
/* Get the size of the struct from the symbol table entry */ /* Get the size of the struct from the symbol table entry */
SI.Size = TagSym->V.S.Size; SI.Size = TagSym->V.S.Size;

View File

@ -268,7 +268,7 @@ void SymSetAsmName (SymEntry* Sym)
void CvtRegVarToAuto (SymEntry* Sym) void SymCvtRegVarToAuto (SymEntry* Sym)
/* Convert a register variable to an auto variable */ /* Convert a register variable to an auto variable */
{ {
/* Change the storage class */ /* Change the storage class */
@ -280,59 +280,26 @@ void CvtRegVarToAuto (SymEntry* Sym)
SymEntry* GetSymType (const Type* T) void SymChangeType (SymEntry* Sym, const Type* T)
/* Get the symbol entry of the enum/struct/union type
** Return 0 if it is not an enum/struct/union.
*/
{
if ((IsClassStruct (T) || IsTypeEnum (T))) {
return T->A.S;
}
return 0;
}
const char* GetSymTypeName (const Type* T)
/* Return a name string of the type or the symbol name if it is an ESU type.
** Note: This may use a static buffer that could be overwritten by other calls.
*/
{
static char TypeName [IDENTSIZE + 16];
SymEntry* Sym;
Sym = GetSymType (T);
if (Sym == 0) {
return GetBasicTypeName (T);
}
sprintf (TypeName, "%s %s", GetBasicTypeName (T),
Sym->Name[0] != '\0' ? Sym->Name : "<unknown>");
return TypeName;
}
void ChangeSymType (SymEntry* Entry, const Type* T)
/* Change the type of the given symbol */ /* Change the type of the given symbol */
{ {
TypeFree (Entry->Type); TypeFree (Sym->Type);
Entry->Type = TypeDup (T); Sym->Type = TypeDup (T);
} }
void ChangeAsmName (SymEntry* Entry, const char* NewAsmName) void SymChangeAsmName (SymEntry* Sym, const char* NewAsmName)
/* Change the assembler name of the symbol */ /* Change the assembler name of the symbol */
{ {
xfree (Entry->AsmName); xfree (Sym->AsmName);
Entry->AsmName = xstrdup (NewAsmName); Sym->AsmName = xstrdup (NewAsmName);
} }
int HasAnonName (const SymEntry* Entry) int SymHasAnonName (const SymEntry* Sym)
/* Return true if the symbol entry has an anonymous name */ /* Return true if the symbol entry has an anonymous name */
{ {
return IsAnonName (Entry->Name); return IsAnonName (Sym->Name);
} }

View File

@ -306,26 +306,16 @@ void SymSetAsmName (SymEntry* Sym);
** The symbol must have no assembler name set yet. ** The symbol must have no assembler name set yet.
*/ */
void CvtRegVarToAuto (SymEntry* Sym); void SymCvtRegVarToAuto (SymEntry* Sym);
/* Convert a register variable to an auto variable */ /* Convert a register variable to an auto variable */
SymEntry* GetSymType (const Type* T); void SymChangeType (SymEntry* Sym, const Type* T);
/* Get the symbol entry of the enum/struct/union type
** Return 0 if it is not an enum/struct/union.
*/
const char* GetSymTypeName (const Type* T);
/* Return a name string of the type or the symbol name if it is an ESU type.
** Note: This may use a static buffer that could be overwritten by other calls.
*/
void ChangeSymType (SymEntry* Entry, const Type* T);
/* Change the type of the given symbol */ /* Change the type of the given symbol */
void ChangeAsmName (SymEntry* Entry, const char* NewAsmName); void SymChangeAsmName (SymEntry* Sym, const char* NewAsmName);
/* Change the assembler name of the symbol */ /* Change the assembler name of the symbol */
int HasAnonName (const SymEntry* Entry); int SymHasAnonName (const SymEntry* Sym);
/* Return true if the symbol entry has an anonymous name */ /* Return true if the symbol entry has an anonymous name */

View File

@ -638,7 +638,7 @@ SymEntry FindStructField (const Type* T, const char* Name)
if (IsClassStruct (T)) { if (IsClassStruct (T)) {
/* Get a pointer to the struct/union tag */ /* Get a pointer to the struct/union tag */
const SymEntry* TagSym = GetESUSymEntry (T); const SymEntry* TagSym = GetESUTagSym (T);
CHECK (TagSym != 0); CHECK (TagSym != 0);
/* Now search in the struct/union symbol table. Beware: The table may /* Now search in the struct/union symbol table. Beware: The table may
@ -832,38 +832,38 @@ static void AddSymEntry (SymTable* T, SymEntry* S)
SymEntry* AddEnumSym (const char* Name, unsigned Flags, const Type* Type, SymTable* Tab, unsigned* DSFlags) SymEntry* AddEnumSym (const char* Name, unsigned Flags, const Type* Type, SymTable* Tab, unsigned* DSFlags)
/* Add an enum entry and return it */ /* Add an enum tag entry and return it */
{ {
SymTable* CurTagTab = TagTab; SymTable* CurTagTab = TagTab;
SymEntry* Entry; SymEntry* TagEntry;
if ((Flags & SC_FICTITIOUS) == 0) { if ((Flags & SC_FICTITIOUS) == 0) {
/* Do we have an entry with this name already? */ /* Do we have an entry with this name already? */
Entry = FindSymInTable (CurTagTab, Name, HashStr (Name)); TagEntry = FindSymInTable (CurTagTab, Name, HashStr (Name));
} else { } else {
/* Add a fictitious symbol in the fail-safe table */ /* Add a fictitious symbol in the fail-safe table */
Entry = 0; TagEntry = 0;
CurTagTab = FailSafeTab; CurTagTab = FailSafeTab;
} }
if (Entry) { if (TagEntry) {
/* We do have an entry. This may be a forward, so check it. */ /* We do have an entry. This may be a forward, so check it. */
if ((Entry->Flags & SC_TYPEMASK) != SC_ENUM) { if ((TagEntry->Flags & SC_TYPEMASK) != SC_ENUM) {
/* Existing symbol is not an enum */ /* Existing symbol is not an enum */
Error ("Symbol '%s' is already different kind", Name); Error ("Symbol '%s' is already different kind", Name);
Entry = 0; TagEntry = 0;
} else if (Type != 0) { } else if (Type != 0) {
/* Define the struct size if the underlying type is given. */ /* Define the struct size if the underlying type is given. */
if (Entry->V.E.Type != 0) { if (TagEntry->V.E.Type != 0) {
/* Both are definitions. */ /* Both are definitions. */
Error ("Multiple definition for 'enum %s'", Name); Error ("Multiple definition for 'enum %s'", Name);
Entry = 0; TagEntry = 0;
} else { } else {
Entry->V.E.SymTab = Tab; TagEntry->V.E.SymTab = Tab;
Entry->V.E.Type = Type; TagEntry->V.E.Type = Type;
Entry->Flags &= ~SC_DECL; TagEntry->Flags &= ~SC_DECL;
Entry->Flags |= SC_DEF; TagEntry->Flags |= SC_DEF;
/* Remember this is the first definition of this type */ /* Remember this is the first definition of this type */
if (DSFlags != 0) { if (DSFlags != 0) {
@ -872,83 +872,83 @@ SymEntry* AddEnumSym (const char* Name, unsigned Flags, const Type* Type, SymTab
} }
} }
if (Entry == 0) { if (TagEntry == 0) {
/* Use the fail-safe table for fictitious symbols */ /* Use the fail-safe table for fictitious symbols */
CurTagTab = FailSafeTab; CurTagTab = FailSafeTab;
} }
} }
if (Entry == 0) { if (TagEntry == 0) {
/* Create a new entry */ /* Create a new entry */
Entry = NewSymEntry (Name, SC_ENUM); TagEntry = NewSymEntry (Name, SC_ENUM);
/* Set the enum type data */ /* Set the enum type data */
Entry->V.E.SymTab = Tab; TagEntry->V.E.SymTab = Tab;
Entry->V.E.Type = Type; TagEntry->V.E.Type = Type;
if (Type != 0) { if (Type != 0) {
Entry->Flags |= SC_DEF; TagEntry->Flags |= SC_DEF;
} }
/* Remember this is the first definition of this type */ /* Remember this is the first definition of this type */
if (CurTagTab != FailSafeTab && DSFlags != 0) { if (CurTagTab != FailSafeTab && DSFlags != 0) {
if ((Entry->Flags & SC_DEF) != 0) { if ((TagEntry->Flags & SC_DEF) != 0) {
*DSFlags |= DS_NEW_TYPE_DEF; *DSFlags |= DS_NEW_TYPE_DEF;
} }
*DSFlags |= DS_NEW_TYPE_DECL; *DSFlags |= DS_NEW_TYPE_DECL;
} }
/* Add it to the current table */ /* Add it to the current table */
AddSymEntry (CurTagTab, Entry); AddSymEntry (CurTagTab, TagEntry);
} }
/* Return the entry */ /* Return the entry */
return Entry; return TagEntry;
} }
SymEntry* AddStructSym (const char* Name, unsigned Flags, unsigned Size, SymTable* Tab, unsigned* DSFlags) SymEntry* AddStructSym (const char* Name, unsigned Flags, unsigned Size, SymTable* Tab, unsigned* DSFlags)
/* Add a struct/union entry and return it */ /* Add a struct/union tag entry and return it */
{ {
SymTable* CurTagTab = TagTab; SymTable* CurTagTab = TagTab;
SymEntry* Entry; SymEntry* TagEntry;
unsigned Type = (Flags & SC_TYPEMASK); unsigned SCType = (Flags & SC_TYPEMASK);
/* Type must be struct or union */ /* SCType must be struct or union */
PRECONDITION (Type == SC_STRUCT || Type == SC_UNION); PRECONDITION (SCType == SC_STRUCT || SCType == SC_UNION);
if ((Flags & SC_FICTITIOUS) == 0) { if ((Flags & SC_FICTITIOUS) == 0) {
/* Do we have an entry with this name already? */ /* Do we have an entry with this name already? */
Entry = FindSymInTable (CurTagTab, Name, HashStr (Name)); TagEntry = FindSymInTable (CurTagTab, Name, HashStr (Name));
} else { } else {
/* Add a fictitious symbol in the fail-safe table */ /* Add a fictitious symbol in the fail-safe table */
Entry = 0; TagEntry = 0;
CurTagTab = FailSafeTab; CurTagTab = FailSafeTab;
} }
if (Entry) { if (TagEntry) {
/* We do have an entry. This may be a forward, so check it. */ /* We do have an entry. This may be a forward, so check it. */
if ((Entry->Flags & SC_TYPEMASK) != Type) { if ((TagEntry->Flags & SC_TYPEMASK) != SCType) {
/* Existing symbol is not a struct */ /* Existing symbol is not a struct */
Error ("Symbol '%s' is already different kind", Name); Error ("Symbol '%s' is already different kind", Name);
Entry = 0; TagEntry = 0;
} else if ((Entry->Flags & Flags & SC_DEF) == SC_DEF) { } else if ((TagEntry->Flags & Flags & SC_DEF) == SC_DEF) {
/* Both structs are definitions. */ /* Both structs are definitions. */
if (Type == SC_STRUCT) { if (SCType == SC_STRUCT) {
Error ("Multiple definition for 'struct %s'", Name); Error ("Multiple definition for 'struct %s'", Name);
} else { } else {
Error ("Multiple definition for 'union %s'", Name); Error ("Multiple definition for 'union %s'", Name);
} }
Entry = 0; TagEntry = 0;
} else { } else {
/* Define the struct size if it is a definition */ /* Define the struct size if it is a definition */
if ((Flags & SC_DEF) == SC_DEF) { if ((Flags & SC_DEF) == SC_DEF) {
Entry->Flags = Flags; TagEntry->Flags = Flags;
Entry->V.S.SymTab = Tab; TagEntry->V.S.SymTab = Tab;
Entry->V.S.Size = Size; TagEntry->V.S.Size = Size;
/* Remember this is the first definition of this type */ /* Remember this is the first definition of this type */
if (DSFlags != 0) { if (DSFlags != 0) {
@ -957,35 +957,35 @@ SymEntry* AddStructSym (const char* Name, unsigned Flags, unsigned Size, SymTabl
} }
} }
if (Entry == 0) { if (TagEntry == 0) {
/* Use the fail-safe table for fictitious symbols */ /* Use the fail-safe table for fictitious symbols */
CurTagTab = FailSafeTab; CurTagTab = FailSafeTab;
} }
} }
if (Entry == 0) { if (TagEntry == 0) {
/* Create a new entry */ /* Create a new entry */
Entry = NewSymEntry (Name, Flags); TagEntry = NewSymEntry (Name, Flags);
/* Set the struct data */ /* Set the struct data */
Entry->V.S.SymTab = Tab; TagEntry->V.S.SymTab = Tab;
Entry->V.S.Size = Size; TagEntry->V.S.Size = Size;
/* Remember this is the first definition of this type */ /* Remember this is the first definition of this type */
if (CurTagTab != FailSafeTab && DSFlags != 0) { if (CurTagTab != FailSafeTab && DSFlags != 0) {
if ((Entry->Flags & SC_DEF) != 0) { if ((TagEntry->Flags & SC_DEF) != 0) {
*DSFlags |= DS_NEW_TYPE_DEF; *DSFlags |= DS_NEW_TYPE_DEF;
} }
*DSFlags |= DS_NEW_TYPE_DECL; *DSFlags |= DS_NEW_TYPE_DECL;
} }
/* Add it to the current tag table */ /* Add it to the current tag table */
AddSymEntry (CurTagTab, Entry); AddSymEntry (CurTagTab, TagEntry);
} }
/* Return the entry */ /* Return the entry */
return Entry; return TagEntry;
} }

View File

@ -169,10 +169,10 @@ unsigned short FindSPAdjustment (const char* Name);
SymEntry* AddEnumSym (const char* Name, unsigned Flags, const Type* Type, SymTable* Tab, unsigned* DSFlags); SymEntry* AddEnumSym (const char* Name, unsigned Flags, const Type* Type, SymTable* Tab, unsigned* DSFlags);
/* Add an enum entry and return it */ /* Add an enum tag entry and return it */
SymEntry* AddStructSym (const char* Name, unsigned Flags, unsigned Size, SymTable* Tab, unsigned* DSFlags); SymEntry* AddStructSym (const char* Name, unsigned Flags, unsigned Size, SymTable* Tab, unsigned* DSFlags);
/* Add a struct/union entry and return it */ /* Add a struct/union tag entry and return it */
SymEntry* AddBitField (const char* Name, const Type* Type, unsigned Offs, SymEntry* AddBitField (const char* Name, const Type* Type, unsigned Offs,
unsigned BitOffs, unsigned BitWidth, int SignednessSpecified); unsigned BitOffs, unsigned BitWidth, int SignednessSpecified);

View File

@ -303,8 +303,8 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result)
if ((IsTypeEnum (lhs) || IsTypeEnum (rhs))) { if ((IsTypeEnum (lhs) || IsTypeEnum (rhs))) {
/* Compare the tag types */ /* Compare the tag types */
Sym1 = IsTypeEnum (lhs) ? GetESUSymEntry (lhs) : 0; Sym1 = IsTypeEnum (lhs) ? GetESUTagSym (lhs) : 0;
Sym2 = IsTypeEnum (rhs) ? GetESUSymEntry (rhs) : 0; Sym2 = IsTypeEnum (rhs) ? GetESUTagSym (rhs) : 0;
if (Sym1 != Sym2) { if (Sym1 != Sym2) {
if (Sym1 == 0 || Sym2 == 0) { if (Sym1 == 0 || Sym2 == 0) {
@ -420,8 +420,8 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result)
case T_TYPE_STRUCT: case T_TYPE_STRUCT:
case T_TYPE_UNION: case T_TYPE_UNION:
/* Compare the tag types */ /* Compare the tag types */
Sym1 = GetESUSymEntry (lhs); Sym1 = GetESUTagSym (lhs);
Sym2 = GetESUSymEntry (rhs); Sym2 = GetESUTagSym (rhs);
CHECK (Sym1 != 0 || Sym2 != 0); CHECK (Sym1 != 0 || Sym2 != 0);