From 24c6e1ce5b77d4b2f881485e6831965ed6465968 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 3 Aug 2008 18:20:12 +0000 Subject: [PATCH] Move some storage class handling and checking for implicit into from locals.c and compile.c into ParseDecl() (declare.c). git-svn-id: svn://svn.cc65.org/cc65/trunk@3867 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/compile.c | 35 +++++++++++++---------------------- src/cc65/declare.c | 18 ++++++++++++++++++ src/cc65/locals.c | 12 ++---------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 28f3e4969..2157a748e 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -83,7 +83,6 @@ static void Parse (void) DeclSpec Spec; Declaration Decl; - int NeedStorage; /* Check for empty statements */ if (CurTok.Tok == TOK_SEMI) { @@ -123,16 +122,6 @@ static void Parse (void) continue; } - /* Check if we must reserve storage for the variable. We do - * this if we don't had a storage class given ("int i") or - * if the storage class is explicitly specified as static. - * This means that "extern int i" will not get storage - * allocated. - */ - NeedStorage = (Spec.StorageClass & SC_TYPEDEF) == 0 && - ((Spec.Flags & DS_DEF_STORAGE) != 0 || - (Spec.StorageClass & (SC_STATIC | SC_EXTERN)) == SC_STATIC); - /* Read declarations for this type */ Entry = 0; comma = 0; @@ -145,17 +134,19 @@ static void Parse (void) break; } - /* Get the symbol flags */ - if (IsTypeFunc (Decl.Type)) { - 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 */ - Decl.StorageClass |= SC_STORAGE | SC_DEF; - } + /* Check if we must reserve storage for the variable. We do this, + * if it is not a typedef or function, if we don't had a storage + * class given ("int i") or if the storage class is explicitly + * specified as static. This means that "extern int i" will not + * get storage allocated. + */ + if ((Decl.StorageClass & SC_FUNC) == 0 && + (Decl.StorageClass & SC_TYPEDEF) == 0 && + ((Spec.Flags & DS_DEF_STORAGE) != 0 || + (Decl.StorageClass & (SC_STATIC | SC_EXTERN)) == SC_STATIC)) { + + /* We will allocate storage */ + Decl.StorageClass |= SC_STORAGE | SC_DEF; } /* Add an entry to the symbol table */ diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 441ce8f98..6cb45dada 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1160,6 +1160,11 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode) /* Fix any type qualifiers attached to an array type */ FixArrayQualifiers (D->Type); + /* If we have a function, add a special storage class */ + if (IsTypeFunc (D->Type)) { + D->StorageClass |= SC_FUNC; + } + /* Check several things for function or function pointer types */ if (IsTypeFunc (D->Type) || IsTypeFuncPtr (D->Type)) { @@ -1200,6 +1205,19 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode) } + /* For anthing that is not a function or typedef, check for an implicit + * int declaration. + */ + if ((D->StorageClass & SC_FUNC) != SC_FUNC && + (D->StorageClass & SC_TYPEDEF) != SC_TYPEDEF) { + /* If the standard was not set explicitly to C89, print a warning + * for variables with implicit int type. + */ + if ((Spec->Flags & DS_DEF_TYPE) != 0 && IS_Get (&Standard) >= STD_C99) { + Warning ("Implicit `int' is an obsolete feature"); + } + } + /* Check the size of the generated type */ if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) { unsigned Size = SizeOf (D->Type); diff --git a/src/cc65/locals.c b/src/cc65/locals.c index 543c9e7f8..c31832780 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -388,13 +388,12 @@ static void ParseOneDecl (const DeclSpec* Spec) ParseDecl (Spec, &Decl, DM_NEED_IDENT); /* Set the correct storage class for functions */ - if (IsTypeFunc (Decl.Type)) { + if ((Decl.StorageClass & SC_FUNC) == SC_FUNC) { /* Function prototypes are always external */ if ((Decl.StorageClass & SC_EXTERN) == 0) { Warning ("Function must be extern"); } - Decl.StorageClass |= SC_FUNC | SC_EXTERN; - + Decl.StorageClass |= SC_EXTERN; } /* If we don't have a name, this was flagged as an error earlier. @@ -437,13 +436,6 @@ static void ParseOneDecl (const DeclSpec* Spec) } else { Internal ("Invalid storage class in ParseOneDecl: %04X", Decl.StorageClass); } - - /* If the standard was not set explicitly to C89, print a warning - * for variables with implicit int type. - */ - if ((Spec->Flags & DS_DEF_TYPE) != 0 && IS_Get (&Standard) >= STD_C99) { - Warning ("Implicit `int' is an obsolete feature"); - } } /* If the symbol is not marked as external, it will be defined now */ -- 2.39.5