mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
No storage for unsuccessfully parsed variables.
This commit is contained in:
parent
fdef067629
commit
8cdffc1944
@ -148,6 +148,11 @@ static void Parse (void)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((Decl.StorageClass & SC_ALIAS) == SC_ALIAS) {
|
||||
/* Failed parsing */
|
||||
goto SkipOneDecl;
|
||||
}
|
||||
|
||||
/* Check if we must reserve storage for the variable. We do this,
|
||||
**
|
||||
** - if it is not a typedef or function,
|
||||
@ -276,6 +281,7 @@ static void Parse (void)
|
||||
|
||||
}
|
||||
|
||||
SkipOneDecl:
|
||||
/* Check for end of declaration list */
|
||||
if (CurTok.Tok == TOK_COMMA) {
|
||||
NextToken ();
|
||||
|
@ -1814,6 +1814,9 @@ Type* ParseType (Type* T)
|
||||
void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode)
|
||||
/* Parse a variable, type or function declaration */
|
||||
{
|
||||
/* Used to check if we have any errors during parsing this */
|
||||
unsigned PrevErrorCount = ErrorCount;
|
||||
|
||||
/* Initialize the Declaration struct */
|
||||
InitDeclaration (D);
|
||||
|
||||
@ -1891,8 +1894,8 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode)
|
||||
}
|
||||
}
|
||||
|
||||
/* Check the size of the generated type */
|
||||
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
|
||||
/* Check the size of the generated type */
|
||||
unsigned Size = SizeOf (D->Type);
|
||||
if (Size >= 0x10000) {
|
||||
if (D->Ident[0] != '\0') {
|
||||
@ -1901,8 +1904,12 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode)
|
||||
Error ("Invalid size in declaration (0x%06X)", Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PrevErrorCount != ErrorCount) {
|
||||
/* Don't give storage if the declaration is not parsed correctly */
|
||||
D->StorageClass |= SC_DECL | SC_ALIAS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -443,13 +443,14 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
||||
}
|
||||
|
||||
/* If the symbol is not marked as external, it will be defined now */
|
||||
if ((Decl.StorageClass & SC_EXTERN) == 0) {
|
||||
if ((Decl.StorageClass & SC_ALIAS) == 0 &&
|
||||
(Decl.StorageClass & SC_EXTERN) == 0) {
|
||||
Decl.StorageClass |= SC_DEF;
|
||||
}
|
||||
|
||||
/* Handle anything that needs storage (no functions, no typdefs) */
|
||||
if ((Decl.StorageClass & SC_FUNC) != SC_FUNC &&
|
||||
(Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF) {
|
||||
if ((Decl.StorageClass & SC_DEF) == SC_DEF &&
|
||||
(Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF) {
|
||||
|
||||
/* If we have a register variable, try to allocate a register and
|
||||
** convert the declaration to "auto" if this is not possible.
|
||||
@ -468,13 +469,6 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
||||
} else if ((Decl.StorageClass & SC_AUTO) == SC_AUTO) {
|
||||
/* Auto variable */
|
||||
ParseAutoDecl (&Decl);
|
||||
} else if ((Decl.StorageClass & SC_EXTERN) == SC_EXTERN) {
|
||||
/* External identifier - may not get initialized */
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
Error ("Cannot initialize externals");
|
||||
}
|
||||
/* Add the external symbol to the symbol table */
|
||||
AddLocalSym (Decl.Ident, Decl.Type, Decl.StorageClass, 0);
|
||||
} else if ((Decl.StorageClass & SC_STATIC) == SC_STATIC) {
|
||||
/* Static variable */
|
||||
ParseStaticDecl (&Decl);
|
||||
@ -484,6 +478,13 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
||||
|
||||
} else {
|
||||
|
||||
if ((Decl.StorageClass & SC_EXTERN) == SC_EXTERN) {
|
||||
/* External identifier - may not get initialized */
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
Error ("Cannot initialize externals");
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the symbol to the symbol table */
|
||||
AddLocalSym (Decl.Ident, Decl.Type, Decl.StorageClass, 0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user