Some of the parser rules to handle incomplete array types versus arrays
with explicit length (not VLAs) are duplicated between the regular and
english parsers.
As this is the same in both cases we can use a new symbol and drop some
duplicate actions to simplify things a bit.
%token T_VLA "variable-length"
%type <strval> vla_ident
%token T_VLA "variable-length"
%type <strval> vla_ident
+%type <uintval> array_length
%type <boolval> varargs
%type <spectype> declspec_simple qualifier_simple
%type <spectype> typespec_simple typespec_tagged
%type <boolval> varargs
%type <spectype> declspec_simple qualifier_simple
%type <spectype> typespec_simple typespec_tagged
-array: T_LBRACKET T_UINT T_RBRACKET {
- if ($2 == 0)
- FAIL(_("array length must be positive"));
-
+array: T_LBRACKET array_length T_RBRACKET {
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.length = $2);
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.length = $2);
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.vla = $2);
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.vla = $2);
-} | T_LBRACKET T_RBRACKET {
- ALLOC_STRUCT($$, struct cdecl_declarator,
- .type = CDECL_DECL_ARRAY);
}
parameter: declspecs declarator {
}
parameter: declspecs declarator {
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.vla = $3);
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.vla = $3);
-} | T_ARRAY T_UINT T_OF {
- if ($2 == 0)
- FAIL(_("array length must be positive"));
-
+} | T_ARRAY array_length T_OF {
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.length = $2);
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.length = $2);
-} | T_ARRAY T_OF {
- ALLOC_STRUCT($$, struct cdecl_declarator,
- .type = CDECL_DECL_ARRAY,
- .u.array.length = 0);
+}
+
+array_length: { $$ = 0; }
+array_length: T_UINT {
+ if (!($$ = $1))
+ FAIL(_("array length must be positive"));
}
english_vla: T_IDENT | {
}
english_vla: T_IDENT | {