mirror of
https://github.com/cc65/cc65.git
synced 2025-01-03 16:33:19 +00:00
Utility for getting ESU tag type symbols.
This commit is contained in:
parent
c831f40e9b
commit
0df45fe2f2
@ -895,8 +895,8 @@ Type* GetBaseElementType (Type* T)
|
||||
|
||||
|
||||
|
||||
SymEntry* GetSymEntry (const Type* T)
|
||||
/* Return a SymEntry pointer from a type */
|
||||
SymEntry* GetESUSymEntry (const Type* T)
|
||||
/* Return a SymEntry pointer from an enum/struct/union type */
|
||||
{
|
||||
/* Only enums, structs or unions have a SymEntry attribute */
|
||||
CHECK (IsClassStruct (T) || IsTypeEnum (T));
|
||||
@ -907,8 +907,8 @@ SymEntry* GetSymEntry (const Type* T)
|
||||
|
||||
|
||||
|
||||
void SetSymEntry (Type* T, SymEntry* S)
|
||||
/* Set the SymEntry pointer for a type */
|
||||
void SetESUSymEntry (Type* T, SymEntry* S)
|
||||
/* Set the SymEntry pointer for an enum/struct/union type */
|
||||
{
|
||||
/* Only enums, structs or unions have a SymEntry attribute */
|
||||
CHECK (IsClassStruct (T) || IsTypeEnum (T));
|
||||
|
@ -747,11 +747,11 @@ Type* GetBaseElementType (Type* T);
|
||||
** the element type that is not an array.
|
||||
*/
|
||||
|
||||
struct SymEntry* GetSymEntry (const Type* T) attribute ((const));
|
||||
/* Return a SymEntry pointer from a type */
|
||||
struct SymEntry* GetESUSymEntry (const Type* T) attribute ((const));
|
||||
/* Return a SymEntry pointer from an enum/struct/union type */
|
||||
|
||||
void SetSymEntry (Type* T, struct SymEntry* S);
|
||||
/* Set the SymEntry pointer for a type */
|
||||
void SetESUSymEntry (Type* T, struct SymEntry* S);
|
||||
/* Set the SymEntry pointer for an enum/struct/union type */
|
||||
|
||||
Type* IntPromotion (Type* T);
|
||||
/* Apply the integer promotions to T and return the result. The returned type
|
||||
|
@ -766,6 +766,7 @@ static unsigned PadWithBitField (unsigned StructSize, unsigned BitOffs)
|
||||
}
|
||||
|
||||
|
||||
|
||||
static unsigned AliasAnonStructFields (const Declaration* Decl, SymEntry* Anon)
|
||||
/* Create alias fields from an anon union/struct in the current lexical level.
|
||||
** The function returns the count of created aliases.
|
||||
@ -775,7 +776,7 @@ static unsigned AliasAnonStructFields (const Declaration* Decl, SymEntry* Anon)
|
||||
SymEntry* Alias;
|
||||
|
||||
/* Get the pointer to the symbol table entry of the anon struct */
|
||||
SymEntry* Entry = GetSymEntry (Decl->Type);
|
||||
SymEntry* Entry = GetESUSymEntry (Decl->Type);
|
||||
|
||||
/* Get the symbol table containing the fields. If it is empty, there has
|
||||
** been an error before, so bail out.
|
||||
@ -1267,7 +1268,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
||||
Entry = ParseUnionDecl (Ident);
|
||||
/* Encode the union entry into the type */
|
||||
D->Type[0].C = T_UNION;
|
||||
SetSymEntry (D->Type, Entry);
|
||||
SetESUSymEntry (D->Type, Entry);
|
||||
D->Type[1].C = T_END;
|
||||
break;
|
||||
|
||||
@ -1286,7 +1287,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
||||
Entry = ParseStructDecl (Ident);
|
||||
/* Encode the struct entry into the type */
|
||||
D->Type[0].C = T_STRUCT;
|
||||
SetSymEntry (D->Type, Entry);
|
||||
SetESUSymEntry (D->Type, Entry);
|
||||
D->Type[1].C = T_END;
|
||||
break;
|
||||
|
||||
@ -1308,7 +1309,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
||||
/* Parse the enum decl */
|
||||
Entry = ParseEnumDecl (Ident);
|
||||
D->Type[0].C |= T_ENUM;
|
||||
SetSymEntry (D->Type, Entry);
|
||||
SetESUSymEntry (D->Type, Entry);
|
||||
D->Type[1].C = T_END;
|
||||
break;
|
||||
|
||||
@ -2258,7 +2259,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
||||
}
|
||||
|
||||
/* Get a pointer to the struct entry from the type */
|
||||
Entry = GetSymEntry (T);
|
||||
Entry = GetESUSymEntry (T);
|
||||
|
||||
/* Get the size of the struct from the symbol table entry */
|
||||
SI.Size = Entry->V.S.Size;
|
||||
|
@ -278,6 +278,38 @@ void CvtRegVarToAuto (SymEntry* Sym)
|
||||
|
||||
|
||||
|
||||
SymEntry* GetSymType (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.P;
|
||||
}
|
||||
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 ? Sym->Name : "<unknown>");
|
||||
|
||||
return TypeName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ChangeSymType (SymEntry* Entry, Type* T)
|
||||
/* Change the type of the given symbol */
|
||||
{
|
||||
|
@ -304,6 +304,16 @@ void SymSetAsmName (SymEntry* Sym);
|
||||
void CvtRegVarToAuto (SymEntry* Sym);
|
||||
/* Convert a register variable to an auto variable */
|
||||
|
||||
SymEntry* GetSymType (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, Type* T);
|
||||
/* Change the type of the given symbol */
|
||||
|
||||
|
@ -509,7 +509,7 @@ SymEntry FindStructField (const Type* T, const char* Name)
|
||||
if (IsClassStruct (T)) {
|
||||
|
||||
/* Get a pointer to the struct/union type */
|
||||
const SymEntry* Struct = GetSymEntry (T);
|
||||
const SymEntry* Struct = GetESUSymEntry (T);
|
||||
CHECK (Struct != 0);
|
||||
|
||||
/* Now search in the struct/union symbol table. Beware: The table may
|
||||
|
@ -368,8 +368,8 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result)
|
||||
** pointer to the struct definition from the type, and compare
|
||||
** the fields.
|
||||
*/
|
||||
Sym1 = GetSymEntry (lhs);
|
||||
Sym2 = GetSymEntry (rhs);
|
||||
Sym1 = GetESUSymEntry (lhs);
|
||||
Sym2 = GetESUSymEntry (rhs);
|
||||
|
||||
/* If one symbol has a name, the names must be identical */
|
||||
if (!HasAnonName (Sym1) || !HasAnonName (Sym2)) {
|
||||
|
Loading…
Reference in New Issue
Block a user