Fixed nested array initializers.
This commit is contained in:
@@ -2092,6 +2092,7 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
|||||||
/* Parse initializaton for arrays. Return the number of data bytes. */
|
/* Parse initializaton for arrays. Return the number of data bytes. */
|
||||||
{
|
{
|
||||||
int Count;
|
int Count;
|
||||||
|
int HasCurly = 0;
|
||||||
|
|
||||||
/* Get the array data */
|
/* Get the array data */
|
||||||
Type* ElementType = GetElementType (T);
|
Type* ElementType = GetElementType (T);
|
||||||
@@ -2144,8 +2145,12 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Curly brace */
|
/* Arrays can be initialized without a pair of curly braces */
|
||||||
ConsumeLCurly ();
|
if (*Braces == 0 || CurTok.Tok == TOK_LCURLY) {
|
||||||
|
/* Consume the opening curly brace */
|
||||||
|
HasCurly = ConsumeLCurly ();
|
||||||
|
*Braces += HasCurly;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize the array members */
|
/* Initialize the array members */
|
||||||
Count = 0;
|
Count = 0;
|
||||||
@@ -2161,8 +2166,10 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Closing curly braces */
|
if (HasCurly) {
|
||||||
ConsumeRCurly ();
|
/* Closing curly braces */
|
||||||
|
ConsumeRCurly ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ElementCount == UNSPECIFIED) {
|
if (ElementCount == UNSPECIFIED) {
|
||||||
@@ -2176,7 +2183,7 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers)
|
|||||||
ElementCount = Count;
|
ElementCount = Count;
|
||||||
} else if (Count < ElementCount) {
|
} else if (Count < ElementCount) {
|
||||||
g_zerobytes ((ElementCount - Count) * ElementSize);
|
g_zerobytes ((ElementCount - Count) * ElementSize);
|
||||||
} else if (Count > ElementCount) {
|
} else if (Count > ElementCount && HasCurly) {
|
||||||
Error ("Excess elements in array initializer");
|
Error ("Excess elements in array initializer");
|
||||||
}
|
}
|
||||||
return ElementCount * ElementSize;
|
return ElementCount * ElementSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user