From 896f463a23e2a58695e23562b7c6f3a46489c9b2 Mon Sep 17 00:00:00 2001 From: acqn <acqn163@outlook.com> Date: Tue, 30 Mar 2021 16:47:52 +0800 Subject: [PATCH] Used more specific pointers instead of the "arbitary attribute pointer" used in type strings. --- src/cc65/codeinfo.c | 1 + src/cc65/compile.c | 1 + src/cc65/datatype.c | 26 +++++++++++++------------- src/cc65/datatype.h | 16 ++++++++++++---- src/cc65/declare.c | 2 +- src/cc65/pragma.c | 1 + src/cc65/symentry.c | 2 +- src/cc65/typecmp.c | 1 + src/cc65/typeconv.c | 1 + 9 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index d81f46001..46a7d76c6 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -46,6 +46,7 @@ #include "codeseg.h" #include "datatype.h" #include "error.h" +#include "funcdesc.h" #include "global.h" #include "reginfo.h" #include "symtab.h" diff --git a/src/cc65/compile.c b/src/cc65/compile.c index d93de96b4..f970edef7 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -53,6 +53,7 @@ #include "declare.h" #include "error.h" #include "expr.h" +#include "funcdesc.h" #include "function.h" #include "global.h" #include "input.h" diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index d29a0d807..901e2ce13 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -468,7 +468,7 @@ Type* GetImplicitFuncType (void) /* Fill the type string */ T[0].C = T_FUNC | CodeAddrSizeQualifier (); - T[0].A.P = F; + T[0].A.F = F; T[1].C = T_INT; T[2].C = T_END; @@ -685,13 +685,13 @@ const Type* GetUnderlyingType (const Type* Type) return IS_Get (&SignedChars) ? type_schar : type_uchar; } else if (IsTypeEnum (Type)) { /* This should not happen, but just in case */ - if (Type->A.P == 0) { + if (Type->A.S == 0) { Internal ("Enum tag type error in GetUnderlyingTypeCode"); } /* If incomplete enum type is used, just return its raw type */ - if (((SymEntry*)Type->A.P)->V.E.Type != 0) { - return ((SymEntry*)Type->A.P)->V.E.Type; + if (Type->A.S->V.E.Type != 0) { + return Type->A.S->V.E.Type; } } @@ -715,16 +715,16 @@ TypeCode GetUnderlyingTypeCode (const Type* Type) } else if (IsTypeEnum (Type)) { /* This should not happen, but just in case */ - if (Type->A.P == 0) { + if (Type->A.S == 0) { Internal ("Enum tag type error in GetUnderlyingTypeCode"); } /* Inspect the underlying type of the enum */ - if (((SymEntry*)Type->A.P)->V.E.Type == 0) { + if (Type->A.S->V.E.Type == 0) { /* Incomplete enum type is used */ return Underlying; } - TCode = UnqualifiedType (((SymEntry*)Type->A.P)->V.E.Type->C); + TCode = UnqualifiedType (Type->A.S->V.E.Type->C); /* Replace the type code with integer */ Underlying = (TCode & ~T_MASK_TYPE); @@ -792,7 +792,7 @@ unsigned SizeOf (const Type* T) case T_STRUCT: case T_UNION: - return ((SymEntry*) T->A.P)->V.S.Size; + return T->A.S->V.S.Size; case T_ARRAY: if (T->A.L == UNSPECIFIED) { @@ -925,7 +925,7 @@ unsigned FuncTypeOf (const Type* T) /* Get the code generator flag for calling the function */ { if (GetUnderlyingTypeCode (T) == T_FUNC) { - return (((FuncDesc*) T->A.P)->Flags & FD_VARIADIC) ? 0 : CF_FIXARGC; + return (T->A.F->Flags & FD_VARIADIC) ? 0 : CF_FIXARGC; } else { Error ("Illegal function type %04lX", T->C); return 0; @@ -1121,7 +1121,7 @@ FuncDesc* GetFuncDesc (const Type* T) CHECK (IsClassFunc (T)); /* Get the function descriptor from the type attributes */ - return T->A.P; + return T->A.F; } @@ -1138,7 +1138,7 @@ void SetFuncDesc (Type* T, FuncDesc* F) CHECK (IsClassFunc (T)); /* Set the function descriptor */ - T->A.P = F; + T->A.F = F; } @@ -1226,7 +1226,7 @@ SymEntry* GetESUSymEntry (const Type* T) CHECK (IsClassStruct (T) || IsTypeEnum (T)); /* Return the attribute */ - return T->A.P; + return T->A.S; } @@ -1238,7 +1238,7 @@ void SetESUSymEntry (Type* T, SymEntry* S) CHECK (IsClassStruct (T) || IsTypeEnum (T)); /* Set the attribute */ - T->A.P = S; + T->A.S = S; } diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index e6ff9b7ce..77dad47ac 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -45,8 +45,16 @@ #include "inline.h" #include "mmodel.h" -/* cc65 */ -#include "funcdesc.h" + + +/*****************************************************************************/ +/* Forward declarations */ +/*****************************************************************************/ + + + +typedef struct FuncDesc FuncDesc; +typedef struct SymEntry SymEntry; @@ -56,7 +64,6 @@ - /* Basic data types */ enum { T_END = 0x000000, @@ -153,7 +160,8 @@ typedef struct Type Type; struct Type { TypeCode C; /* Code for this entry */ union { - void* P; /* Arbitrary attribute pointer */ + FuncDesc* F; /* Function description pointer */ + SymEntry* S; /* Enum/struct/union tag symbol entry pointer */ long L; /* Numeric attribute value */ unsigned long U; /* Dito, unsigned */ } A; /* Type attribute if necessary */ diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 0c00f56d4..e15c59d40 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1891,7 +1891,7 @@ static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode) /* Add the function type. Be sure to bounds check the type buffer */ NeedTypeSpace (D, 1); D->Type[D->Index].C = T_FUNC | Qualifiers; - D->Type[D->Index].A.P = F; + D->Type[D->Index].A.F = F; ++D->Index; /* Qualifiers now used */ diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index 2dd923cf1..f0f7ed36f 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -46,6 +46,7 @@ #include "codegen.h" #include "error.h" #include "expr.h" +#include "funcdesc.h" #include "global.h" #include "litpool.h" #include "scanner.h" diff --git a/src/cc65/symentry.c b/src/cc65/symentry.c index ea08a860c..5bce488c5 100644 --- a/src/cc65/symentry.c +++ b/src/cc65/symentry.c @@ -284,7 +284,7 @@ SymEntry* GetSymType (const Type* T) */ { if ((IsClassStruct (T) || IsTypeEnum (T))) { - return T->A.P; + return T->A.S; } return 0; } diff --git a/src/cc65/typecmp.c b/src/cc65/typecmp.c index 58f41d3ca..f0958d7e0 100644 --- a/src/cc65/typecmp.c +++ b/src/cc65/typecmp.c @@ -37,6 +37,7 @@ /* cc65 */ #include "error.h" +#include "funcdesc.h" #include "global.h" #include "symtab.h" #include "typecmp.h" diff --git a/src/cc65/typeconv.c b/src/cc65/typeconv.c index 8bdef8d03..210f02565 100644 --- a/src/cc65/typeconv.c +++ b/src/cc65/typeconv.c @@ -42,6 +42,7 @@ #include "declare.h" #include "error.h" #include "expr.h" +#include "funcdesc.h" #include "loadexpr.h" #include "typecmp.h" #include "typeconv.h"