From a8ce85adbf2863e98e5c24e9cc6f82947d4b3a29 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 21 Jul 2020 18:42:27 +0200 Subject: Support _Static_assert from C11 --- cparser/Parser.vy | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'cparser/Parser.vy') 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 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 declaration_specifiers_typespec_opt %type init_declarator_list %type init_declarator +%type<(Cabs.expression * Cabs.loc) * (Cabs.constant * Cabs.loc) * Cabs.loc> + static_assert_declaration %type storage_class_specifier %type type_specifier struct_or_union_specifier enum_specifier %type 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) -- cgit