Fixed error "variable has unknown size" for a local array where the size

was not given (introduced by last change).


git-svn-id: svn://svn.cc65.org/cc65/trunk@1465 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-10-17 21:14:40 +00:00
parent 49fd7134e5
commit 4da19658c2

View file

@ -133,7 +133,7 @@ static int AllocRegVar (const SymEntry* Sym, const type* tarray)
static unsigned ParseAutoDecl (Declaration* Decl, unsigned Size, unsigned* SC) static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
/* Parse the declaration of an auto variable. The function returns the symbol /* Parse the declaration of an auto variable. The function returns the symbol
* data, which is the offset for variables on the stack, and the label for * data, which is the offset for variables on the stack, and the label for
* static variables. * static variables.
@ -146,6 +146,9 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned Size, unsigned* SC)
/* Determine if this is a compound variable */ /* Determine if this is a compound variable */
int IsCompound = IsClassStruct (Decl->Type) || IsTypeArray (Decl->Type); int IsCompound = IsClassStruct (Decl->Type) || IsTypeArray (Decl->Type);
/* Get the size of the variable */
unsigned Size = SizeOf (Decl->Type);
/* Check if this is a variable on the stack or in static memory */ /* Check if this is a variable on the stack or in static memory */
if (StaticLocals == 0) { if (StaticLocals == 0) {
@ -287,19 +290,27 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned Size, unsigned* SC)
} }
} }
/* Cannot allocate a variable of zero size */
if (Size == 0) {
Error ("Variable `%s' has unknown size", Decl->Ident);
}
/* Return the symbol data */ /* Return the symbol data */
return SymData; return SymData;
} }
static unsigned ParseStaticDecl (Declaration* Decl, unsigned Size, unsigned* SC) static unsigned ParseStaticDecl (Declaration* Decl, unsigned* SC)
/* Parse the declaration of a static variable. The function returns the symbol /* Parse the declaration of a static variable. The function returns the symbol
* data, which is the asm label of the variable. * data, which is the asm label of the variable.
*/ */
{ {
unsigned SymData; unsigned SymData;
/* Get the size of the variable */
unsigned Size = SizeOf (Decl->Type);
/* Static data */ /* Static data */
if (CurTok.Tok == TOK_ASSIGN) { if (CurTok.Tok == TOK_ASSIGN) {
@ -342,6 +353,11 @@ static unsigned ParseStaticDecl (Declaration* Decl, unsigned Size, unsigned* SC)
} }
/* Cannot allocate a variable of zero size */
if (Size == 0) {
Error ("Variable `%s' has unknown size", Decl->Ident);
}
/* Return the symbol data */ /* Return the symbol data */
return SymData; return SymData;
} }
@ -352,7 +368,6 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Parse one variable declaration */ /* Parse one variable declaration */
{ {
unsigned SC; /* Storage class for symbol */ unsigned SC; /* Storage class for symbol */
unsigned Size; /* Size of the data object */
unsigned SymData = 0; /* Symbol data (offset, label name, ...) */ unsigned SymData = 0; /* Symbol data (offset, label name, ...) */
Declaration Decl; /* Declaration data structure */ Declaration Decl; /* Declaration data structure */
@ -382,27 +397,18 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Handle anything that needs storage (no functions, no typdefs) */ /* Handle anything that needs storage (no functions, no typdefs) */
if ((SC & SC_FUNC) != SC_FUNC && (SC & SC_TYPEDEF) != SC_TYPEDEF) { if ((SC & SC_FUNC) != SC_FUNC && (SC & SC_TYPEDEF) != SC_TYPEDEF) {
/* Get the size of the variable */
Size = SizeOf (Decl.Type);
/* */ /* */
if (SC & (SC_AUTO | SC_REGISTER)) { if (SC & (SC_AUTO | SC_REGISTER)) {
/* Auto variable */ /* Auto variable */
SymData = ParseAutoDecl (&Decl, Size, &SC); SymData = ParseAutoDecl (&Decl, &SC);
} else if ((SC & SC_STATIC) == SC_STATIC) { } else if ((SC & SC_STATIC) == SC_STATIC) {
/* Static variable */ /* Static variable */
SymData = ParseStaticDecl (&Decl, Size, &SC); SymData = ParseStaticDecl (&Decl, &SC);
} }
/* Cannot allocate a variable of zero size */
if (Size == 0) {
Error ("Variable `%s' has unknown size", Decl.Ident);
return;
}
} }
/* If the symbol is not marked as external, it will be defined */ /* If the symbol is not marked as external, it will be defined */