1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-14 16:33:00 +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

@ -148,6 +148,11 @@ static void Parse (void)
break; break;
} }
if ((Decl.StorageClass & SC_ALIAS) == SC_ALIAS) {
/* Failed parsing */
goto SkipOneDecl;
}
/* Check if we must reserve storage for the variable. We do this, /* Check if we must reserve storage for the variable. We do this,
** **
** - if it is not a typedef or function, ** - if it is not a typedef or function,
@ -276,6 +281,7 @@ static void Parse (void)
} }
SkipOneDecl:
/* Check for end of declaration list */ /* Check for end of declaration list */
if (CurTok.Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextToken (); NextToken ();

@ -1814,6 +1814,9 @@ Type* ParseType (Type* T)
void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode) void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode)
/* Parse a variable, type or function declaration */ /* 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 */ /* Initialize the Declaration struct */
InitDeclaration (D); 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)) { if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
/* Check the size of the generated type */
unsigned Size = SizeOf (D->Type); unsigned Size = SizeOf (D->Type);
if (Size >= 0x10000) { if (Size >= 0x10000) {
if (D->Ident[0] != '\0') { 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); 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 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; Decl.StorageClass |= SC_DEF;
} }
/* Handle anything that needs storage (no functions, no typdefs) */ /* 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) { (Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF) {
/* If we have a register variable, try to allocate a register and /* If we have a register variable, try to allocate a register and
** convert the declaration to "auto" if this is not possible. ** 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) { } else if ((Decl.StorageClass & SC_AUTO) == SC_AUTO) {
/* Auto variable */ /* Auto variable */
ParseAutoDecl (&Decl); 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) { } else if ((Decl.StorageClass & SC_STATIC) == SC_STATIC) {
/* Static variable */ /* Static variable */
ParseStaticDecl (&Decl); ParseStaticDecl (&Decl);
@ -484,6 +478,13 @@ static void ParseOneDecl (const DeclSpec* Spec)
} else { } 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 */ /* Add the symbol to the symbol table */
AddLocalSym (Decl.Ident, Decl.Type, Decl.StorageClass, 0); AddLocalSym (Decl.Ident, Decl.Type, Decl.StorageClass, 0);