mirror of
https://github.com/cc65/cc65.git
synced 2025-01-26 17:36:57 +00:00
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
This commit is contained in:
parent
841ea0e686
commit
24c6e1ce5b
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user