The last patch did not work correctly in call cases - fix that

git-svn-id: svn://svn.cc65.org/cc65/trunk@1183 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2002-03-10 14:34:20 +00:00
parent 438444cdd6
commit 9941f3d84a

View File

@@ -171,12 +171,6 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Get the size of the variable */ /* Get the size of the variable */
Size = SizeOf (Decl.Type); Size = SizeOf (Decl.Type);
/* Cannot allocate a variable of zero size */
if (Size == 0) {
Error ("Variable `%s' has unknown size", Decl.Ident);
return;
}
/* */ /* */
if (SC & (SC_AUTO | SC_REGISTER)) { if (SC & (SC_AUTO | SC_REGISTER)) {
@@ -192,82 +186,82 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Allocate previously reserved local space */ /* Allocate previously reserved local space */
AllocLocalSpace (CurrentFunc); AllocLocalSpace (CurrentFunc);
/* Skip the '=' */ /* Skip the '=' */
NextToken (); NextToken ();
/* Setup the type flags for the assignment */ /* Setup the type flags for the assignment */
flags = Size == 1? CF_FORCECHAR : CF_NONE; flags = Size == 1? CF_FORCECHAR : CF_NONE;
/* Get the expression into the primary */ /* Get the expression into the primary */
if (evalexpr (flags, hie1, &lval) == 0) { if (evalexpr (flags, hie1, &lval) == 0) {
/* Constant expression. Adjust the types */ /* Constant expression. Adjust the types */
assignadjust (Decl.Type, &lval); assignadjust (Decl.Type, &lval);
flags |= CF_CONST; flags |= CF_CONST;
} else { } else {
/* Expression is not constant and in the primary */ /* Expression is not constant and in the primary */
assignadjust (Decl.Type, &lval); assignadjust (Decl.Type, &lval);
} }
/* Push the value */ /* Push the value */
g_push (flags | TypeOf (Decl.Type), lval.ConstVal); g_push (flags | TypeOf (Decl.Type), lval.ConstVal);
/* Mark the variable as referenced */ /* Mark the variable as referenced */
SC |= SC_REF; SC |= SC_REF;
/* Variable is located at the current SP */ /* Variable is located at the current SP */
SymData = oursp; SymData = oursp;
} else { } else {
/* Non-initialized local variable. Just keep track of /* Non-initialized local variable. Just keep track of
* the space needed. * the space needed.
*/ */
SymData = ReserveLocalSpace (CurrentFunc, Size); SymData = ReserveLocalSpace (CurrentFunc, Size);
} }
} else { } else {
/* Static local variables. */ /* Static local variables. */
SC = (SC & ~(SC_REGISTER | SC_AUTO)) | SC_STATIC; SC = (SC & ~(SC_REGISTER | SC_AUTO)) | SC_STATIC;
/* Put them into the BSS */ /* Put them into the BSS */
g_usebss (); g_usebss ();
/* Define the variable label */ /* Define the variable label */
SymData = GetLocalLabel (); SymData = GetLocalLabel ();
g_defdatalabel (SymData); g_defdatalabel (SymData);
/* Reserve space for the data */ /* Reserve space for the data */
g_res (Size); g_res (Size);
/* Allow assignments */ /* Allow assignments */
if (CurTok.Tok == TOK_ASSIGN) { if (CurTok.Tok == TOK_ASSIGN) {
ExprDesc lval; ExprDesc lval;
/* Skip the '=' */ /* Skip the '=' */
NextToken (); NextToken ();
/* Setup the type flags for the assignment */ /* Setup the type flags for the assignment */
flags = Size == 1? CF_FORCECHAR : CF_NONE; flags = Size == 1? CF_FORCECHAR : CF_NONE;
/* Get the expression into the primary */ /* Get the expression into the primary */
if (evalexpr (flags, hie1, &lval) == 0) { if (evalexpr (flags, hie1, &lval) == 0) {
/* Constant expression. Adjust the types */ /* Constant expression. Adjust the types */
assignadjust (Decl.Type, &lval); assignadjust (Decl.Type, &lval);
flags |= CF_CONST; flags |= CF_CONST;
/* Load it into the primary */ /* Load it into the primary */
exprhs (flags, 0, &lval); exprhs (flags, 0, &lval);
} else { } else {
/* Expression is not constant and in the primary */ /* Expression is not constant and in the primary */
assignadjust (Decl.Type, &lval); assignadjust (Decl.Type, &lval);
} }
/* Store the value into the variable */ /* Store the value into the variable */
g_putstatic (flags | TypeOf (Decl.Type), SymData, 0); g_putstatic (flags | TypeOf (Decl.Type), SymData, 0);
/* Mark the variable as referenced */ /* Mark the variable as referenced */
SC |= SC_REF; SC |= SC_REF;
} }
} }
} else if ((SC & SC_STATIC) == SC_STATIC) { } else if ((SC & SC_STATIC) == SC_STATIC) {
@@ -276,11 +270,11 @@ static void ParseOneDecl (const DeclSpec* Spec)
if (CurTok.Tok == TOK_ASSIGN) { if (CurTok.Tok == TOK_ASSIGN) {
/* Initialization ahead, switch to data segment */ /* Initialization ahead, switch to data segment */
if (IsQualConst (Decl.Type)) { if (IsQualConst (Decl.Type)) {
g_userodata (); g_userodata ();
} else { } else {
g_usedata (); g_usedata ();
} }
/* Define the variable label */ /* Define the variable label */
SymData = GetLocalLabel (); SymData = GetLocalLabel ();
@@ -292,29 +286,39 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Allow initialization of static vars */ /* Allow initialization of static vars */
ParseInit (Decl.Type); ParseInit (Decl.Type);
/* If the previous size has been unknown, it must be known now */
if (Size == 0) {
Size = SizeOf (Decl.Type);
}
/* Mark the variable as referenced */ /* Mark the variable as referenced */
SC |= SC_REF; SC |= SC_REF;
} else { } else {
/* Uninitialized data, use BSS segment */ /* Uninitialized data, use BSS segment */
g_usebss (); g_usebss ();
/* Define the variable label */ /* Define the variable label */
SymData = GetLocalLabel (); SymData = GetLocalLabel ();
g_defdatalabel (SymData); g_defdatalabel (SymData);
/* Reserve space for the data */ /* Reserve space for the data */
g_res (Size); g_res (Size);
} }
}
/* 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 */
if ((SC & SC_EXTERN) == 0) { if ((SC & SC_EXTERN) == 0) {
SC |= SC_DEF; SC |= SC_DEF;
} }
/* Add the symbol to the symbol table */ /* Add the symbol to the symbol table */
@@ -333,7 +337,7 @@ void DeclareLocals (void)
while (1) { while (1) {
/* Check variable declarations. We need to distinguish between a /* Check variable declarations. We need to distinguish between a
* default int type and the end of variable declarations. So we * default int type and the end of variable declarations. So we
* will do the following: If there is no explicit storage class * will do the following: If there is no explicit storage class
* specifier *and* no explicit type given, it is assume that we * specifier *and* no explicit type given, it is assume that we
* have reached the end of declarations. * have reached the end of declarations.