1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 19:29:37 +00:00

No storage for unsuccessfully parsed variables.

This commit is contained in:
acqn 2020-08-03 01:36:19 +08:00 committed by Oliver Schmidt
parent fdef067629
commit 8cdffc1944
3 changed files with 26 additions and 12 deletions

View File

@ -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 ();

View File

@ -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;
}
}
}

View File

@ -443,12 +443,13 @@ 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 &&
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
@ -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);