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:
@@ -83,7 +83,6 @@ static void Parse (void)
|
|||||||
|
|
||||||
DeclSpec Spec;
|
DeclSpec Spec;
|
||||||
Declaration Decl;
|
Declaration Decl;
|
||||||
int NeedStorage;
|
|
||||||
|
|
||||||
/* Check for empty statements */
|
/* Check for empty statements */
|
||||||
if (CurTok.Tok == TOK_SEMI) {
|
if (CurTok.Tok == TOK_SEMI) {
|
||||||
@@ -123,16 +122,6 @@ static void Parse (void)
|
|||||||
continue;
|
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 */
|
/* Read declarations for this type */
|
||||||
Entry = 0;
|
Entry = 0;
|
||||||
comma = 0;
|
comma = 0;
|
||||||
@@ -145,17 +134,19 @@ static void Parse (void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the symbol flags */
|
/* Check if we must reserve storage for the variable. We do this,
|
||||||
if (IsTypeFunc (Decl.Type)) {
|
* if it is not a typedef or function, if we don't had a storage
|
||||||
Decl.StorageClass |= SC_FUNC;
|
* class given ("int i") or if the storage class is explicitly
|
||||||
} else if ((Decl.StorageClass & SC_TYPEDEF) == 0) {
|
* specified as static. This means that "extern int i" will not
|
||||||
if ((Spec.Flags & DS_DEF_TYPE) != 0 && IS_Get (&Standard) >= STD_C99) {
|
* get storage allocated.
|
||||||
Warning ("Implicit `int' is an obsolete feature");
|
*/
|
||||||
}
|
if ((Decl.StorageClass & SC_FUNC) == 0 &&
|
||||||
if (NeedStorage) {
|
(Decl.StorageClass & SC_TYPEDEF) == 0 &&
|
||||||
/* We will allocate storage, variable is defined */
|
((Spec.Flags & DS_DEF_STORAGE) != 0 ||
|
||||||
Decl.StorageClass |= SC_STORAGE | SC_DEF;
|
(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 */
|
/* 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 */
|
/* Fix any type qualifiers attached to an array type */
|
||||||
FixArrayQualifiers (D->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 */
|
/* Check several things for function or function pointer types */
|
||||||
if (IsTypeFunc (D->Type) || IsTypeFuncPtr (D->Type)) {
|
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 */
|
/* Check the size of the generated type */
|
||||||
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
|
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
|
||||||
unsigned Size = SizeOf (D->Type);
|
unsigned Size = SizeOf (D->Type);
|
||||||
|
|||||||
@@ -388,13 +388,12 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
|||||||
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 ((Decl.StorageClass & SC_FUNC) == SC_FUNC) {
|
||||||
/* Function prototypes are always external */
|
/* Function prototypes are always external */
|
||||||
if ((Decl.StorageClass & SC_EXTERN) == 0) {
|
if ((Decl.StorageClass & SC_EXTERN) == 0) {
|
||||||
Warning ("Function must be extern");
|
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.
|
/* 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 {
|
} else {
|
||||||
Internal ("Invalid storage class in ParseOneDecl: %04X", Decl.StorageClass);
|
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 */
|
/* If the symbol is not marked as external, it will be defined now */
|
||||||
|
|||||||
Reference in New Issue
Block a user