diff options
author | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2020-07-21 18:42:27 +0200 |
---|---|---|
committer | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2020-07-21 18:45:28 +0200 |
commit | a8ce85adbf2863e98e5c24e9cc6f82947d4b3a29 (patch) | |
tree | c289886f88b58716ecfe0f7261594a231a3b21be /cparser/Parser.vy | |
parent | 3a1b0e98a09dd9688e8f45f9677b7ea25f4720bf (diff) | |
download | compcert-a8ce85adbf2863e98e5c24e9cc6f82947d4b3a29.tar.gz compcert-a8ce85adbf2863e98e5c24e9cc6f82947d4b3a29.zip |
Support _Static_assert from C11
Diffstat (limited to 'cparser/Parser.vy')
-rw-r--r-- | cparser/Parser.vy | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/cparser/Parser.vy b/cparser/Parser.vy index 03bfa590..93d84ecf 100644 --- a/cparser/Parser.vy +++ b/cparser/Parser.vy @@ -37,7 +37,7 @@ Require Cabs. STRUCT UNION ENUM UNDERSCORE_BOOL PACKED ALIGNAS ATTRIBUTE ASM %token<Cabs.loc> CASE DEFAULT IF_ ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK - RETURN BUILTIN_VA_ARG BUILTIN_OFFSETOF + RETURN BUILTIN_VA_ARG BUILTIN_OFFSETOF STATIC_ASSERT %token EOF @@ -55,6 +55,8 @@ Require Cabs. %type<list Cabs.spec_elem> declaration_specifiers_typespec_opt %type<list Cabs.init_name (* Reverse order *)> init_declarator_list %type<Cabs.init_name> init_declarator +%type<(Cabs.expression * Cabs.loc) * (Cabs.constant * Cabs.loc) * Cabs.loc> + static_assert_declaration %type<Cabs.storage * Cabs.loc> storage_class_specifier %type<Cabs.typeSpecifier * Cabs.loc> type_specifier struct_or_union_specifier enum_specifier %type<Cabs.structOrUnion * Cabs.loc> struct_or_union @@ -343,6 +345,9 @@ declaration: { Cabs.DECDEF (fst decspec, rev' decls) (snd decspec) } | decspec = declaration_specifiers SEMICOLON { Cabs.DECDEF (fst decspec, []) (snd decspec) } +| asrt = static_assert_declaration + { let '((e, loc_e), (s, loc_s), loc) := asrt in + Cabs.STATIC_ASSERT e loc_e s loc_s loc } declaration_specifiers_typespec_opt: | storage = storage_class_specifier rest = declaration_specifiers_typespec_opt @@ -459,6 +464,10 @@ struct_declaration: (* Extension to C99 grammar needed to parse some GNU header files. *) | decspec = specifier_qualifier_list SEMICOLON { Cabs.Field_group (fst decspec) [(None,None)] (snd decspec) } +(* C11 static assertions *) +| asrt = static_assert_declaration + { let '((e, loc_e), (s, loc_s), loc) := asrt in + Cabs.Field_group_static_assert e loc_e s loc_s loc } specifier_qualifier_list: | typ = type_specifier rest = specifier_qualifier_list @@ -749,6 +758,14 @@ designator: | DOT id = OTHER_NAME { Cabs.INFIELD_INIT (fst id) } +(* C11 6.7.10 *) + +static_assert_declaration: +| loc = STATIC_ASSERT LPAREN expr = constant_expression + COMMA str = STRING_LITERAL RPAREN SEMICOLON + { let '((wide, chars), locs) := str in + (expr, (Cabs.CONST_STRING wide chars, locs), loc) } + (* 6.8 *) statement_dangerous: | stmt = labeled_statement(statement_dangerous) |