Fixed bug with braces in initializer lists
git-svn-id: svn://svn.cc65.org/cc65/trunk@3193 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
2414d6cd11
commit
40d01eb4ce
3 changed files with 67 additions and 43 deletions
|
@ -1211,6 +1211,50 @@ static void ClosingCurlyBraces (unsigned BracesExpected)
|
|||
|
||||
|
||||
|
||||
static void DefineData (ExprDesc* Expr)
|
||||
/* Output a data definition for the given expression */
|
||||
{
|
||||
switch (ED_GetLoc (Expr)) {
|
||||
|
||||
case E_LOC_ABS:
|
||||
/* Absolute: numeric address or const */
|
||||
g_defdata (TypeOf (Expr->Type) | CF_CONST, Expr->IVal, 0);
|
||||
break;
|
||||
|
||||
case E_LOC_GLOBAL:
|
||||
/* Global variable */
|
||||
g_defdata (CF_EXTERNAL, Expr->Name, Expr->IVal);
|
||||
break;
|
||||
|
||||
case E_LOC_STATIC:
|
||||
case E_LOC_LITERAL:
|
||||
/* Static variable or literal in the literal pool */
|
||||
g_defdata (CF_STATIC, Expr->Name, Expr->IVal);
|
||||
break;
|
||||
|
||||
case E_LOC_REGISTER:
|
||||
/* Register variable. Taking the address is usually not
|
||||
* allowed.
|
||||
*/
|
||||
if (IS_Get (&AllowRegVarAddr) == 0) {
|
||||
Error ("Cannot take the address of a register variable");
|
||||
}
|
||||
g_defdata (CF_REGVAR, Expr->Name, Expr->IVal);
|
||||
break;
|
||||
|
||||
case E_LOC_STACK:
|
||||
case E_LOC_PRIMARY:
|
||||
case E_LOC_EXPR:
|
||||
Error ("Non constant initializer");
|
||||
break;
|
||||
|
||||
default:
|
||||
Internal ("Unknown constant type: 0x%04X", ED_GetLoc (Expr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static unsigned ParseScalarInit (type* T)
|
||||
/* Parse initializaton for scalar data types. Return the number of data bytes. */
|
||||
{
|
||||
|
@ -1276,10 +1320,24 @@ static unsigned ParseArrayInit (type* T, int AllowFlexibleMembers)
|
|||
long ElementCount = GetElementCount (T);
|
||||
|
||||
/* Special handling for a character array initialized by a literal */
|
||||
if (IsTypeChar (ElementType) && CurTok.Tok == TOK_SCONST) {
|
||||
if (IsTypeChar (ElementType) &&
|
||||
(CurTok.Tok == TOK_SCONST ||
|
||||
(CurTok.Tok == TOK_LCURLY && NextTok.Tok == TOK_SCONST))) {
|
||||
|
||||
/* Char array initialized by string constant */
|
||||
const char* Str = GetLiteral (CurTok.IVal);
|
||||
int NeedParen;
|
||||
const char* Str;
|
||||
|
||||
/* If we initializer is enclosed in brackets, remember this fact and
|
||||
* skip the opening bracket.
|
||||
*/
|
||||
NeedParen = (CurTok.Tok == TOK_LCURLY);
|
||||
if (NeedParen) {
|
||||
NextToken ();
|
||||
}
|
||||
|
||||
/* Get the initializer string and its size */
|
||||
Str = GetLiteral (CurTok.IVal);
|
||||
Count = GetLiteralPoolOffs () - CurTok.IVal;
|
||||
|
||||
/* Translate into target charset */
|
||||
|
@ -1302,6 +1360,13 @@ static unsigned ParseArrayInit (type* T, int AllowFlexibleMembers)
|
|||
ResetLiteralPoolOffs (CurTok.IVal);
|
||||
NextToken ();
|
||||
|
||||
/* If the initializer was enclosed in curly braces, we need a closing
|
||||
* one.
|
||||
*/
|
||||
if (NeedParen) {
|
||||
ConsumeRCurly ();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/* Curly brace */
|
||||
|
|
|
@ -181,44 +181,6 @@ static unsigned typeadjust (ExprDesc* lhs, ExprDesc* rhs, int NoPush)
|
|||
|
||||
|
||||
|
||||
void DefineData (ExprDesc* Expr)
|
||||
/* Output a data definition for the given expression */
|
||||
{
|
||||
switch (ED_GetLoc (Expr)) {
|
||||
|
||||
case E_LOC_ABS:
|
||||
/* Absolute: numeric address or const */
|
||||
g_defdata (TypeOf (Expr->Type) | CF_CONST, Expr->IVal, 0);
|
||||
break;
|
||||
|
||||
case E_LOC_GLOBAL:
|
||||
/* Global variable */
|
||||
g_defdata (CF_EXTERNAL, Expr->Name, Expr->IVal);
|
||||
break;
|
||||
|
||||
case E_LOC_STATIC:
|
||||
case E_LOC_LITERAL:
|
||||
/* Static variable or literal in the literal pool */
|
||||
g_defdata (CF_STATIC, Expr->Name, Expr->IVal);
|
||||
break;
|
||||
|
||||
case E_LOC_REGISTER:
|
||||
/* Register variable. Taking the address is usually not
|
||||
* allowed.
|
||||
*/
|
||||
if (IS_Get (&AllowRegVarAddr) == 0) {
|
||||
Error ("Cannot take the address of a register variable");
|
||||
}
|
||||
g_defdata (CF_REGVAR, Expr->Name, Expr->IVal);
|
||||
break;
|
||||
|
||||
default:
|
||||
Internal ("Unknown constant type: 0x%04X", ED_GetLoc (Expr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int kcalc (token_t tok, long val1, long val2)
|
||||
/* Calculate an operation with left and right operand constant. */
|
||||
{
|
||||
|
|
|
@ -82,9 +82,6 @@ void hie1 (ExprDesc* lval);
|
|||
void hie0 (ExprDesc* Expr);
|
||||
/* Parse comma operator. */
|
||||
|
||||
void DefineData (ExprDesc* lval);
|
||||
/* Output a data definition for the given expression */
|
||||
|
||||
|
||||
|
||||
/* End of expr.h */
|
||||
|
|
Loading…
Add table
Reference in a new issue