mirror of
https://github.com/cc65/cc65.git
synced 2024-06-29 10:29:30 +00:00
Transfer the storage class flags from struct DeclSpec into struct Declaration.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3866 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
c76a8657b3
commit
841ea0e686
|
@ -138,8 +138,6 @@ static void Parse (void)
|
||||||
comma = 0;
|
comma = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
unsigned SymFlags;
|
|
||||||
|
|
||||||
/* Read the next declaration */
|
/* Read the next declaration */
|
||||||
ParseDecl (&Spec, &Decl, DM_NEED_IDENT);
|
ParseDecl (&Spec, &Decl, DM_NEED_IDENT);
|
||||||
if (Decl.Ident[0] == '\0') {
|
if (Decl.Ident[0] == '\0') {
|
||||||
|
@ -148,24 +146,23 @@ static void Parse (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the symbol flags */
|
/* Get the symbol flags */
|
||||||
SymFlags = Spec.StorageClass;
|
|
||||||
if (IsTypeFunc (Decl.Type)) {
|
if (IsTypeFunc (Decl.Type)) {
|
||||||
SymFlags |= SC_FUNC;
|
Decl.StorageClass |= SC_FUNC;
|
||||||
} else if ((SymFlags & SC_TYPEDEF) == 0) {
|
} else if ((Decl.StorageClass & SC_TYPEDEF) == 0) {
|
||||||
if ((Spec.Flags & DS_DEF_TYPE) != 0 && IS_Get (&Standard) >= STD_C99) {
|
if ((Spec.Flags & DS_DEF_TYPE) != 0 && IS_Get (&Standard) >= STD_C99) {
|
||||||
Warning ("Implicit `int' is an obsolete feature");
|
Warning ("Implicit `int' is an obsolete feature");
|
||||||
}
|
}
|
||||||
if (NeedStorage) {
|
if (NeedStorage) {
|
||||||
/* We will allocate storage, variable is defined */
|
/* We will allocate storage, variable is defined */
|
||||||
SymFlags |= SC_STORAGE | SC_DEF;
|
Decl.StorageClass |= SC_STORAGE | SC_DEF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add an entry to the symbol table */
|
/* Add an entry to the symbol table */
|
||||||
Entry = AddGlobalSym (Decl.Ident, Decl.Type, SymFlags);
|
Entry = AddGlobalSym (Decl.Ident, Decl.Type, Decl.StorageClass);
|
||||||
|
|
||||||
/* Reserve storage for the variable if we need to */
|
/* Reserve storage for the variable if we need to */
|
||||||
if (SymFlags & SC_STORAGE) {
|
if (Decl.StorageClass & SC_STORAGE) {
|
||||||
|
|
||||||
/* Get the size of the variable */
|
/* Get the size of the variable */
|
||||||
unsigned Size = SizeOf (Decl.Type);
|
unsigned Size = SizeOf (Decl.Type);
|
||||||
|
|
|
@ -820,14 +820,14 @@ static void ParseAnsiParamList (FuncDesc* F)
|
||||||
F->Flags |= FD_UNNAMED_PARAMS;
|
F->Flags |= FD_UNNAMED_PARAMS;
|
||||||
|
|
||||||
/* Clear defined bit on nonames */
|
/* Clear defined bit on nonames */
|
||||||
Spec.StorageClass &= ~SC_DEF;
|
Decl.StorageClass &= ~SC_DEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse an attribute ### */
|
/* Parse an attribute ### */
|
||||||
ParseAttribute (&Decl, &Attr);
|
ParseAttribute (&Decl, &Attr);
|
||||||
|
|
||||||
/* Create a symbol table entry */
|
/* Create a symbol table entry */
|
||||||
AddLocalSym (Decl.Ident, ParamTypeCvt (Decl.Type), Spec.StorageClass, 0);
|
AddLocalSym (Decl.Ident, ParamTypeCvt (Decl.Type), Decl.StorageClass, 0);
|
||||||
|
|
||||||
/* Count arguments */
|
/* Count arguments */
|
||||||
++F->ParamCount;
|
++F->ParamCount;
|
||||||
|
@ -1154,6 +1154,9 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
||||||
NeedTypeSpace (D, TypeLen (Spec->Type) + 1); /* Bounds check */
|
NeedTypeSpace (D, TypeLen (Spec->Type) + 1); /* Bounds check */
|
||||||
TypeCpy (D->Type + D->Index, Spec->Type);
|
TypeCpy (D->Type + D->Index, Spec->Type);
|
||||||
|
|
||||||
|
/* Use the storage class from the declspec */
|
||||||
|
D->StorageClass = Spec->StorageClass;
|
||||||
|
|
||||||
/* Fix any type qualifiers attached to an array type */
|
/* Fix any type qualifiers attached to an array type */
|
||||||
FixArrayQualifiers (D->Type);
|
FixArrayQualifiers (D->Type);
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2006 Ullrich von Bassewitz */
|
/* (C) 1998-2008 Ullrich von Bassewitz */
|
||||||
/* Römerstrasse 52 */
|
/* Roemerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
|
@ -66,8 +66,9 @@ struct DeclSpec {
|
||||||
/* Result of ParseDecl */
|
/* Result of ParseDecl */
|
||||||
typedef struct Declaration Declaration;
|
typedef struct Declaration Declaration;
|
||||||
struct Declaration {
|
struct Declaration {
|
||||||
ident Ident; /* The identifier if any, else empty */
|
unsigned StorageClass; /* A set of SC_xxx flags */
|
||||||
Type Type[MAXTYPELEN]; /* The type */
|
Type Type[MAXTYPELEN]; /* The type */
|
||||||
|
ident Ident; /* The identifier if any, else empty */
|
||||||
|
|
||||||
/* Working variables */
|
/* Working variables */
|
||||||
unsigned Index; /* Used to build Type */
|
unsigned Index; /* Used to build Type */
|
||||||
|
|
|
@ -380,24 +380,20 @@ static unsigned ParseStaticDecl (Declaration* Decl, unsigned* SC)
|
||||||
static void ParseOneDecl (const DeclSpec* Spec)
|
static void ParseOneDecl (const DeclSpec* Spec)
|
||||||
/* Parse one variable declaration */
|
/* Parse one variable declaration */
|
||||||
{
|
{
|
||||||
unsigned SC; /* Storage class for symbol */
|
|
||||||
unsigned SymData = 0; /* Symbol data (offset, label name, ...) */
|
unsigned SymData = 0; /* Symbol data (offset, label name, ...) */
|
||||||
Declaration Decl; /* Declaration data structure */
|
Declaration Decl; /* Declaration data structure */
|
||||||
|
|
||||||
|
|
||||||
/* Remember the storage class for the new symbol */
|
|
||||||
SC = Spec->StorageClass;
|
|
||||||
|
|
||||||
/* Read the declaration */
|
/* Read the declaration */
|
||||||
ParseDecl (Spec, &Decl, DM_NEED_IDENT);
|
ParseDecl (Spec, &Decl, DM_NEED_IDENT);
|
||||||
|
|
||||||
/* Set the correct storage class for functions */
|
/* Set the correct storage class for functions */
|
||||||
if (IsTypeFunc (Decl.Type)) {
|
if (IsTypeFunc (Decl.Type)) {
|
||||||
/* Function prototypes are always external */
|
/* Function prototypes are always external */
|
||||||
if ((SC & SC_EXTERN) == 0) {
|
if ((Decl.StorageClass & SC_EXTERN) == 0) {
|
||||||
Warning ("Function must be extern");
|
Warning ("Function must be extern");
|
||||||
}
|
}
|
||||||
SC |= SC_FUNC | SC_EXTERN;
|
Decl.StorageClass |= SC_FUNC | SC_EXTERN;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,35 +405,37 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle anything that needs storage (no functions, no typdefs) */
|
/* Handle anything that needs storage (no functions, no typdefs) */
|
||||||
if ((SC & SC_FUNC) != SC_FUNC && (SC & SC_TYPEDEF) != SC_TYPEDEF) {
|
if ((Decl.StorageClass & SC_FUNC) != SC_FUNC &&
|
||||||
|
(Decl.StorageClass & SC_TYPEDEF) != SC_TYPEDEF) {
|
||||||
|
|
||||||
/* If we have a register variable, try to allocate a register and
|
/* If we have a register variable, try to allocate a register and
|
||||||
* convert the declaration to "auto" if this is not possible.
|
* convert the declaration to "auto" if this is not possible.
|
||||||
*/
|
*/
|
||||||
int Reg = 0; /* Initialize to avoid gcc complains */
|
int Reg = 0; /* Initialize to avoid gcc complains */
|
||||||
if ((SC & SC_REGISTER) != 0 && (Reg = F_AllocRegVar (CurrentFunc, Decl.Type)) < 0) {
|
if ((Decl.StorageClass & SC_REGISTER) != 0 &&
|
||||||
|
(Reg = F_AllocRegVar (CurrentFunc, Decl.Type)) < 0) {
|
||||||
/* No space for this register variable, convert to auto */
|
/* No space for this register variable, convert to auto */
|
||||||
SC = (SC & ~SC_REGISTER) | SC_AUTO;
|
Decl.StorageClass = (Decl.StorageClass & ~SC_REGISTER) | SC_AUTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check the variable type */
|
/* Check the variable type */
|
||||||
if ((SC & SC_REGISTER) == SC_REGISTER) {
|
if ((Decl.StorageClass & SC_REGISTER) == SC_REGISTER) {
|
||||||
/* Register variable */
|
/* Register variable */
|
||||||
SymData = ParseRegisterDecl (&Decl, &SC, Reg);
|
SymData = ParseRegisterDecl (&Decl, &Decl.StorageClass, Reg);
|
||||||
} else if ((SC & SC_AUTO) == SC_AUTO) {
|
} else if ((Decl.StorageClass & SC_AUTO) == SC_AUTO) {
|
||||||
/* Auto variable */
|
/* Auto variable */
|
||||||
SymData = ParseAutoDecl (&Decl, &SC);
|
SymData = ParseAutoDecl (&Decl, &Decl.StorageClass);
|
||||||
} else if ((SC & SC_EXTERN) == SC_EXTERN) {
|
} else if ((Decl.StorageClass & SC_EXTERN) == SC_EXTERN) {
|
||||||
/* External identifier - may not get initialized */
|
/* External identifier - may not get initialized */
|
||||||
if (CurTok.Tok == TOK_ASSIGN) {
|
if (CurTok.Tok == TOK_ASSIGN) {
|
||||||
Error ("Cannot initialize externals");
|
Error ("Cannot initialize externals");
|
||||||
}
|
}
|
||||||
SymData = 0;
|
SymData = 0;
|
||||||
} else if ((SC & SC_STATIC) == SC_STATIC) {
|
} else if ((Decl.StorageClass & SC_STATIC) == SC_STATIC) {
|
||||||
/* Static variable */
|
/* Static variable */
|
||||||
SymData = ParseStaticDecl (&Decl, &SC);
|
SymData = ParseStaticDecl (&Decl, &Decl.StorageClass);
|
||||||
} else {
|
} else {
|
||||||
Internal ("Invalid storage class in ParseOneDecl: %04X", SC);
|
Internal ("Invalid storage class in ParseOneDecl: %04X", Decl.StorageClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the standard was not set explicitly to C89, print a warning
|
/* If the standard was not set explicitly to C89, print a warning
|
||||||
|
@ -449,12 +447,12 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the symbol is not marked as external, it will be defined now */
|
/* If the symbol is not marked as external, it will be defined now */
|
||||||
if ((SC & SC_EXTERN) == 0) {
|
if ((Decl.StorageClass & SC_EXTERN) == 0) {
|
||||||
SC |= SC_DEF;
|
Decl.StorageClass |= SC_DEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the symbol to the symbol table */
|
/* Add the symbol to the symbol table */
|
||||||
AddLocalSym (Decl.Ident, Decl.Type, SC, SymData);
|
AddLocalSym (Decl.Ident, Decl.Type, Decl.StorageClass, SymData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user