From: uz Date: Sun, 3 Aug 2008 18:00:05 +0000 (+0000) Subject: Transfer the storage class flags from struct DeclSpec into struct Declaration. X-Git-Tag: V2.13.0rc1~389 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=841ea0e686241ea77236305aece09c775ef10245;p=cc65 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 --- diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 24ef4aa70..28f3e4969 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -138,8 +138,6 @@ static void Parse (void) comma = 0; while (1) { - unsigned SymFlags; - /* Read the next declaration */ ParseDecl (&Spec, &Decl, DM_NEED_IDENT); if (Decl.Ident[0] == '\0') { @@ -148,24 +146,23 @@ static void Parse (void) } /* Get the symbol flags */ - SymFlags = Spec.StorageClass; if (IsTypeFunc (Decl.Type)) { - SymFlags |= SC_FUNC; - } else if ((SymFlags & SC_TYPEDEF) == 0) { + Decl.StorageClass |= SC_FUNC; + } else if ((Decl.StorageClass & SC_TYPEDEF) == 0) { if ((Spec.Flags & DS_DEF_TYPE) != 0 && IS_Get (&Standard) >= STD_C99) { Warning ("Implicit `int' is an obsolete feature"); } if (NeedStorage) { /* 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 */ - Entry = AddGlobalSym (Decl.Ident, Decl.Type, SymFlags); + Entry = AddGlobalSym (Decl.Ident, Decl.Type, Decl.StorageClass); /* Reserve storage for the variable if we need to */ - if (SymFlags & SC_STORAGE) { + if (Decl.StorageClass & SC_STORAGE) { /* Get the size of the variable */ unsigned Size = SizeOf (Decl.Type); @@ -252,7 +249,7 @@ static void Parse (void) NextToken (); } else { - FuncDesc* D; + FuncDesc* D; /* Function body. Check for duplicate function definitions */ if (SymIsDef (Entry)) { diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 2b4a09a42..441ce8f98 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -820,14 +820,14 @@ static void ParseAnsiParamList (FuncDesc* F) F->Flags |= FD_UNNAMED_PARAMS; /* Clear defined bit on nonames */ - Spec.StorageClass &= ~SC_DEF; + Decl.StorageClass &= ~SC_DEF; } /* Parse an attribute ### */ ParseAttribute (&Decl, &Attr); /* 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 */ ++F->ParamCount; @@ -1154,6 +1154,9 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode) NeedTypeSpace (D, TypeLen (Spec->Type) + 1); /* Bounds check */ 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 */ FixArrayQualifiers (D->Type); diff --git a/src/cc65/declare.h b/src/cc65/declare.h index 606ca36d4..fb510ef30 100644 --- a/src/cc65/declare.h +++ b/src/cc65/declare.h @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 1998-2006 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ +/* (C) 1998-2008 Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -66,8 +66,9 @@ struct DeclSpec { /* Result of ParseDecl */ typedef struct Declaration Declaration; struct Declaration { - ident Ident; /* The identifier if any, else empty */ + unsigned StorageClass; /* A set of SC_xxx flags */ Type Type[MAXTYPELEN]; /* The type */ + ident Ident; /* The identifier if any, else empty */ /* Working variables */ unsigned Index; /* Used to build Type */ @@ -104,7 +105,7 @@ void CheckEmptyDecl (const DeclSpec* D); unsigned ParseInit (Type* T); /* Parse initialization of variables. Return the number of initialized data * bytes. - */ + */ diff --git a/src/cc65/locals.c b/src/cc65/locals.c index af2c5a28b..543c9e7f8 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -380,24 +380,20 @@ static unsigned ParseStaticDecl (Declaration* Decl, unsigned* SC) static void ParseOneDecl (const DeclSpec* Spec) /* Parse one variable declaration */ { - unsigned SC; /* Storage class for symbol */ unsigned SymData = 0; /* Symbol data (offset, label name, ...) */ Declaration Decl; /* Declaration data structure */ - /* Remember the storage class for the new symbol */ - SC = Spec->StorageClass; - /* Read the declaration */ ParseDecl (Spec, &Decl, DM_NEED_IDENT); /* Set the correct storage class for functions */ if (IsTypeFunc (Decl.Type)) { /* Function prototypes are always external */ - if ((SC & SC_EXTERN) == 0) { + if ((Decl.StorageClass & SC_EXTERN) == 0) { 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) */ - 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 * convert the declaration to "auto" if this is not possible. */ 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 */ - SC = (SC & ~SC_REGISTER) | SC_AUTO; + Decl.StorageClass = (Decl.StorageClass & ~SC_REGISTER) | SC_AUTO; } /* Check the variable type */ - if ((SC & SC_REGISTER) == SC_REGISTER) { + if ((Decl.StorageClass & SC_REGISTER) == SC_REGISTER) { /* Register variable */ - SymData = ParseRegisterDecl (&Decl, &SC, Reg); - } else if ((SC & SC_AUTO) == SC_AUTO) { + SymData = ParseRegisterDecl (&Decl, &Decl.StorageClass, Reg); + } else if ((Decl.StorageClass & SC_AUTO) == SC_AUTO) { /* Auto variable */ - SymData = ParseAutoDecl (&Decl, &SC); - } else if ((SC & SC_EXTERN) == SC_EXTERN) { + SymData = ParseAutoDecl (&Decl, &Decl.StorageClass); + } else if ((Decl.StorageClass & SC_EXTERN) == SC_EXTERN) { /* External identifier - may not get initialized */ if (CurTok.Tok == TOK_ASSIGN) { Error ("Cannot initialize externals"); } SymData = 0; - } else if ((SC & SC_STATIC) == SC_STATIC) { + } else if ((Decl.StorageClass & SC_STATIC) == SC_STATIC) { /* Static variable */ - SymData = ParseStaticDecl (&Decl, &SC); + SymData = ParseStaticDecl (&Decl, &Decl.StorageClass); } 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 @@ -449,15 +447,15 @@ static void ParseOneDecl (const DeclSpec* Spec) } /* If the symbol is not marked as external, it will be defined now */ - if ((SC & SC_EXTERN) == 0) { - SC |= SC_DEF; + if ((Decl.StorageClass & SC_EXTERN) == 0) { + Decl.StorageClass |= SC_DEF; } /* Add the symbol to the symbol table */ - AddLocalSym (Decl.Ident, Decl.Type, SC, SymData); + AddLocalSym (Decl.Ident, Decl.Type, Decl.StorageClass, SymData); } - + void DeclareLocals (void) /* Declare local variables and types. */