-static unsigned ParseSimpleInit (type* T)
-/* Parse initializaton for simple data types. Return the number of data bytes. */
+static unsigned ParseScalarInit (type* T)
+/* Parse initializaton for scalar data types. Return the number of data bytes. */
{
static const unsigned long Masks[] = {
0x000000FFUL, 0x0000FFFFUL, 0x00FFFFFFUL, 0xFFFFFFFFUL
};
+ unsigned BraceCount;
ExprDesc ED;
- /* Optional opening brace */
- unsigned BraceCount = OpeningCurlyBraces (0);
-
/* Get the size of the expected type */
unsigned Size = SizeOf (T);
CHECK (Size > 0 && Size <= sizeof(Masks)/sizeof(Masks[0]));
+ /* Optional opening brace */
+ BraceCount = OpeningCurlyBraces (0);
+
+ /* We warn if an initializer for a scalar contains braces, because this is
+ * quite unusual and often a sign for some problem in the input.
+ */
+ if (BraceCount > 0) {
+ Warning ("Braces around scalar initializer");
+ }
+
/* Expression */
ConstExpr (&ED);
if ((ED.Flags & E_MCTYPE) == E_TCONST) {
+static unsigned ParsePointerInit (type* T)
+/* Parse initializaton for pointer data types. Return the number of data bytes. */
+{
+ /* Optional opening brace */
+ unsigned BraceCount = OpeningCurlyBraces (0);
+
+ /* Expression */
+ ExprDesc ED;
+ ConstExpr (&ED);
+ if ((ED.Flags & E_MCTYPE) == E_TCONST) {
+ /* Make the const value the correct size */
+ ED.ConstVal &= 0xFFFF;
+ }
+ assignadjust (T, &ED);
+
+ /* Output the data */
+ DefineData (&ED);
+
+ /* Close eventually opening braces */
+ ClosingCurlyBraces (BraceCount);
+
+ /* Done */
+ return SIZEOF_PTR;
+}
+
+
+
static unsigned ParseArrayInit (type* T, int AllowFlexibleMembers)
/* Parse initializaton for arrays. Return the number of data bytes. */
{
case T_USHORT:
case T_INT:
case T_UINT:
- case T_PTR:
case T_LONG:
case T_ULONG:
- return ParseSimpleInit (T);
+ return ParseScalarInit (T);
+
+ case T_PTR:
+ return ParsePointerInit (T);
case T_ARRAY:
return ParseArrayInit (T, AllowFlexibleMembers);
}
}
-
+
unsigned ParseInit (type* T)