-static void ParseTypeSpec (DeclSpec* D, int Default);
+static void ParseTypeSpec (DeclSpec* D, int Default, type Qualifiers);
/* Parse a type specificier */
static unsigned ParseInitInternal (type* T, int AllowFlexibleMembers);
/* Add an entry to the symbol table */
AddConstSym (Ident, type_int, SC_ENUM, EnumVal++);
- /* Check for end of definition */
+ /* Check for end of definition */
if (CurTok.Tok != TOK_COMMA)
break;
NextToken ();
/* Get the type of the entry */
DeclSpec Spec;
InitDeclSpec (&Spec);
- ParseTypeSpec (&Spec, -1);
+ ParseTypeSpec (&Spec, -1, T_QUAL_NONE);
/* Read fields with this type */
while (1) {
if (FieldSize > StructSize) {
StructSize = FieldSize;
}
- }
+ }
/* Add a field entry to the table */
AddLocalSym (Decl.Ident, Decl.Type, SC_STRUCTFIELD, Offs);
}
NextToken ();
}
- ConsumeSemi ();
+ ConsumeSemi ();
}
/* Skip the closing brace */
-static void ParseTypeSpec (DeclSpec* D, int Default)
+static void ParseTypeSpec (DeclSpec* D, int Default, type Qualifiers)
/* Parse a type specificier */
{
ident Ident;
SymEntry* Entry;
type StructType;
- type Qualifiers; /* Type qualifiers */
/* Assume we have an explicit type */
D->Flags &= ~DS_DEF_TYPE;
/* Read type qualifiers if we have any */
- Qualifiers = OptionalQualifiers (T_QUAL_NONE);
+ Qualifiers = OptionalQualifiers (Qualifiers);
/* Look at the data type */
switch (CurTok.Tok) {
case TOK_VOID:
NextToken ();
D->Type[0] = T_VOID;
- D->Type[1] = T_END;
+ D->Type[1] = T_END;
break;
case TOK_CHAR:
if (CurTok.Tok == TOK_UNSIGNED) {
NextToken ();
optionalint ();
- D->Type[0] = T_ULONG;
+ D->Type[0] = T_ULONG;
D->Type[1] = T_END;
} else {
optionalsigned ();
case TOK_LONG:
NextToken ();
optionalint ();
- D->Type[0] = T_ULONG;
+ D->Type[0] = T_ULONG;
D->Type[1] = T_END;
break;
case TOK_ENUM:
NextToken ();
- if (CurTok.Tok != TOK_LCURLY) {
+ if (CurTok.Tok != TOK_LCURLY) {
/* Named enum */
if (CurTok.Tok == TOK_IDENT) {
/* Find an entry with this name */
- Entry = FindTagSym (CurTok.Ident);
+ Entry = FindTagSym (CurTok.Ident);
if (Entry) {
if (SymIsLocal (Entry) && (Entry->Flags & SC_ENUM) == 0) {
Error ("Symbol `%s' is already different kind", Entry->Name);
}
/* Skip the identifier */
NextToken ();
- } else {
+ } else {
Error ("Identifier expected");
- }
- }
- /* Remember we have an extra type decl */
- D->Flags |= DS_EXTRA_TYPE;
- /* Parse the enum decl */
+ }
+ }
+ /* Remember we have an extra type decl */
+ D->Flags |= DS_EXTRA_TYPE;
+ /* Parse the enum decl */
ParseEnumDecl ();
- D->Type[0] = T_INT;
- D->Type[1] = T_END;
+ D->Type[0] = T_INT;
+ D->Type[1] = T_END;
break;
case TOK_IDENT:
- Entry = FindSym (CurTok.Ident);
- if (Entry && SymIsTypeDef (Entry)) {
+ Entry = FindSym (CurTok.Ident);
+ if (Entry && SymIsTypeDef (Entry)) {
/* It's a typedef */
NextToken ();
- TypeCpy (D->Type, Entry->Type);
+ TypeCpy (D->Type, Entry->Type);
break;
}
/* FALL THROUGH */
default:
if (Default < 0) {
Error ("Type expected");
- D->Type[0] = T_INT;
- D->Type[1] = T_END;
+ D->Type[0] = T_INT;
+ D->Type[1] = T_END;
} else {
- D->Flags |= DS_DEF_TYPE;
- D->Type[0] = (type) Default;
- D->Type[1] = T_END;
- }
- break;
+ D->Flags |= DS_DEF_TYPE;
+ D->Type[0] = (type) Default;
+ D->Type[1] = T_END;
+ }
+ break;
}
/* There may also be qualifiers *after* the initial type */
* we ignore all this, since we use auto anyway.
*/
if ((Spec.StorageClass & SC_AUTO) == 0 &&
- (Spec.StorageClass & SC_REGISTER) == 0) {
+ (Spec.StorageClass & SC_REGISTER) == 0) {
Error ("Illegal storage class");
}
/* Allow an ellipsis as last parameter */
if (CurTok.Tok == TOK_ELLIPSIS) {
- NextToken ();
+ NextToken ();
F->Flags |= FD_VARIADIC;
break;
}
if (CurTok.Tok == TOK_FASTCALL || CurTok.Tok == TOK_NEAR || CurTok.Tok == TOK_FAR) {
/* Remember the current type pointer */
- type* T = D->Type + D->Index;
+ type* T = D->Type + D->Index;
/* Read the flags */
unsigned Flags = FunctionModifierFlags ();
/* Get a type without a default */
InitDeclSpec (&Spec);
- ParseTypeSpec (&Spec, -1);
+ ParseTypeSpec (&Spec, -1, T_QUAL_NONE);
/* Parse additional declarators */
ParseDecl (&Spec, &Decl, DM_NO_IDENT);
void ParseDeclSpec (DeclSpec* D, unsigned DefStorage, int DefType)
/* Parse a declaration specification */
{
+ type Qualifiers;
+
/* Initialize the DeclSpec struct */
InitDeclSpec (D);
- /* First, get the storage class specifier for this declaration */
+ /* There may be qualifiers *before* the storage class specifier */
+ Qualifiers = OptionalQualifiers (T_QUAL_NONE);
+
+ /* Now get the storage class specifier for this declaration */
ParseStorageClass (D, DefStorage);
- /* Parse the type specifiers */
- ParseTypeSpec (D, DefType);
+ /* Parse the type specifiers passing any initial type qualifiers */
+ ParseTypeSpec (D, DefType, Qualifiers);
}