From 08d6d674b84f01c21b752eb11c107166e6d448c1 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Mon, 18 Mar 2024 09:09:32 +0000 Subject: [PATCH] C/C++ front-end: Revert scanner re-entrancy There is no need for scanner re-entrancy, and using flex' re-entrancy options fails the build on some macOS configurations. Partly reverts 1f240bc9f1a. --- src/ansi-c/ansi_c_language.cpp | 4 + src/ansi-c/ansi_c_parser.cpp | 17 - src/ansi-c/ansi_c_parser.h | 10 +- src/ansi-c/builtin_factory.cpp | 2 + src/ansi-c/parser.y | 814 +++++++++--------- src/ansi-c/parser_static.inc | 51 +- src/ansi-c/scanner.l | 444 +++++----- src/cpp/cpp_token_buffer.cpp | 8 +- src/cpp/cpp_token_buffer.h | 12 +- .../contracts/contracts_wrangler.cpp | 1 + 10 files changed, 661 insertions(+), 702 deletions(-) diff --git a/src/ansi-c/ansi_c_language.cpp b/src/ansi-c/ansi_c_language.cpp index c78caa499d5..5c58cf621a7 100644 --- a/src/ansi-c/ansi_c_language.cpp +++ b/src/ansi-c/ansi_c_language.cpp @@ -82,6 +82,8 @@ bool ansi_c_languaget::parse( ansi_c_parser.cpp11=false; // it's not C++ ansi_c_parser.mode=config.ansi_c.mode; + ansi_c_scanner_init(ansi_c_parser); + bool result=ansi_c_parser.parse(); if(!result) @@ -89,6 +91,7 @@ bool ansi_c_languaget::parse( ansi_c_parser.set_line_no(0); ansi_c_parser.set_file(path); ansi_c_parser.in=&i_preprocessed; + ansi_c_scanner_init(ansi_c_parser); result=ansi_c_parser.parse(); } @@ -202,6 +205,7 @@ bool ansi_c_languaget::to_expr( ansi_c_parser.cpp98 = false; // it's not C++ ansi_c_parser.cpp11 = false; // it's not C++ ansi_c_parser.mode = config.ansi_c.mode; + ansi_c_scanner_init(ansi_c_parser); bool result=ansi_c_parser.parse(); diff --git a/src/ansi-c/ansi_c_parser.cpp b/src/ansi-c/ansi_c_parser.cpp index 1e24533bc6f..c26911d93b0 100644 --- a/src/ansi-c/ansi_c_parser.cpp +++ b/src/ansi-c/ansi_c_parser.cpp @@ -10,23 +10,6 @@ Author: Daniel Kroening, kroening@kroening.com #include "c_storage_spec.h" -int yyansi_clex_init_extra(ansi_c_parsert *, void **); -int yyansi_clex_destroy(void *); -int yyansi_cparse(ansi_c_parsert &, void *); -void yyansi_cset_debug(int, void *); - -bool ansi_c_parsert::parse() -{ - void *scanner; - yyansi_clex_init_extra(this, &scanner); -#ifdef ANSI_C_DEBUG - yyansi_cset_debug(1, scanner); -#endif - bool parse_fail = yyansi_cparse(*this, scanner) != 0; - yyansi_clex_destroy(scanner); - return parse_fail; -} - ansi_c_id_classt ansi_c_parsert::lookup( const irep_idt &base_name, irep_idt &identifier, // output diff --git a/src/ansi-c/ansi_c_parser.h b/src/ansi-c/ansi_c_parser.h index 25476818579..78873560914 100644 --- a/src/ansi-c/ansi_c_parser.h +++ b/src/ansi-c/ansi_c_parser.h @@ -18,6 +18,9 @@ Author: Daniel Kroening, kroening@kroening.com #include "ansi_c_parse_tree.h" #include "ansi_c_scope.h" +class ansi_c_parsert; +int yyansi_cparse(ansi_c_parsert &); + class ansi_c_parsert:public parsert { public: @@ -41,7 +44,10 @@ class ansi_c_parsert:public parsert scopes.push_back(scopet()); } - bool parse() override; + bool parse() override + { + return yyansi_cparse(*this) != 0; + } void clear() override { @@ -169,4 +175,6 @@ class ansi_c_parsert:public parsert std::list> pragma_cprover_stack; }; +void ansi_c_scanner_init(ansi_c_parsert &); + #endif // CPROVER_ANSI_C_ANSI_C_PARSER_H diff --git a/src/ansi-c/builtin_factory.cpp b/src/ansi-c/builtin_factory.cpp index df95bbeda2e..86f035f960b 100644 --- a/src/ansi-c/builtin_factory.cpp +++ b/src/ansi-c/builtin_factory.cpp @@ -58,6 +58,8 @@ static bool convert( ansi_c_parser.cpp11=false; // it's not C++ ansi_c_parser.mode=config.ansi_c.mode; + ansi_c_scanner_init(ansi_c_parser); + if(ansi_c_parser.parse()) return true; diff --git a/src/ansi-c/parser.y b/src/ansi-c/parser.y index 2f06f3cc60a..1f9f49594a3 100644 --- a/src/ansi-c/parser.y +++ b/src/ansi-c/parser.y @@ -13,22 +13,23 @@ #ifdef ANSI_C_DEBUG #define YYDEBUG 1 #endif -#define PARSER ansi_c_parser +#define PARSER (*ansi_c_parser) #include "ansi_c_parser.h" -int yyansi_clex(void *); -char *yyansi_cget_text(void *); +int yyansi_clex(); +extern char *yyansi_ctext; -int yyansi_cerror( - ansi_c_parsert &ansi_c_parser, - void *scanner, - const std::string &error) +static ansi_c_parsert *ansi_c_parser; +int yyansi_cparse(void); +int yyansi_cparse(ansi_c_parsert &_ansi_c_parser) { - ansi_c_parser.parse_error(error, yyansi_cget_text(scanner)); - return 0; + ansi_c_parser = &_ansi_c_parser; + return yyansi_cparse(); } +int yyansi_cerror(const std::string &error); + #include "parser_static.inc" #include "literals/convert_integer_literal.h" @@ -55,10 +56,6 @@ int yyansi_cerror( #define YYMAXDEPTH 25600 %} -%parse-param {ansi_c_parsert &ansi_c_parser} -%parse-param {void *scanner} -%lex-param {void *scanner} - /*** token declaration **************************************************/ /*** ANSI-C keywords ***/ @@ -371,7 +368,7 @@ generic_selection: TOK_GENERIC '(' assignment_expression ',' generic_assoc_list ')' { $$=$1; - set(PARSER, $$, ID_generic_selection); + set($$, ID_generic_selection); mto($$, $3); parser_stack($$).add(ID_generic_associations).get_sub().swap((irept::subt&)parser_stack($5).operands()); } @@ -380,7 +377,7 @@ generic_selection: generic_assoc_list: generic_association { - init(PARSER, $$); mto($$, $1); + init($$); mto($$, $1); } | generic_assoc_list ',' generic_association { @@ -458,7 +455,7 @@ offsetof: offsetof_member_designator: member_name { - init(PARSER, $$); + init($$); exprt op{ID_member}; op.add_source_location()=parser_stack($1).source_location(); op.set(ID_component_name, parser_stack($1).get(ID_C_base_name)); @@ -467,24 +464,24 @@ offsetof_member_designator: | offsetof_member_designator '.' member_name { $$=$1; - set(PARSER, $2, ID_member); + set($2, ID_member); parser_stack($2).set(ID_component_name, parser_stack($3).get(ID_C_base_name)); mto($$, $2); } | offsetof_member_designator '[' comma_expression ']' { $$=$1; - set(PARSER, $2, ID_index); + set($2, ID_index); mto($2, $3); mto($$, $2); } | offsetof_member_designator TOK_ARROW member_name { $$=$1; - set(PARSER, $2, ID_index); + set($2, ID_index); parser_stack($2).add_to_operands(convert_integer_literal("0")); mto($$, $2); - set(PARSER, $2, ID_member); + set($2, ID_member); parser_stack($2).set(ID_component_name, parser_stack($3).get(ID_C_base_name)); mto($$, $2); } @@ -494,7 +491,7 @@ quantifier_expression: TOK_FORALL compound_scope '{' declaration comma_expression '}' { $$=$1; - set(PARSER, $$, ID_forall); + set($$, ID_forall); parser_stack($$).add_to_operands(tuple_exprt( { std::move(parser_stack($4)) } )); mto($$, $5); PARSER.pop_scope(); @@ -502,7 +499,7 @@ quantifier_expression: | TOK_EXISTS compound_scope '{' declaration comma_expression '}' { $$=$1; - set(PARSER, $$, ID_exists); + set($$, ID_exists); parser_stack($$).add_to_operands(tuple_exprt( { std::move(parser_stack($4)) } )); mto($$, $5); PARSER.pop_scope(); @@ -516,27 +513,27 @@ cprover_contract_loop_invariant: cprover_contract_loop_invariant_list: cprover_contract_loop_invariant - { init(PARSER, $$); mto($$, $1); } + { init($$); mto($$, $1); } | cprover_contract_loop_invariant_list cprover_contract_loop_invariant { $$=$1; mto($$, $2); } ; cprover_contract_loop_invariant_list_opt: /* nothing */ - { init(PARSER, $$); parser_stack($$).make_nil(); } + { init($$); parser_stack($$).make_nil(); } | cprover_contract_loop_invariant_list ; ACSL_binding_expression_list: ACSL_binding_expression - { init(PARSER, $$); mto($$, $1); } + { init($$); mto($$, $1); } | ACSL_binding_expression_list ',' ACSL_binding_expression { $$=$1; mto($$, $3); } ; cprover_contract_decreases_opt: /* nothing */ - { init(PARSER, $$); parser_stack($$).make_nil(); } + { init($$); parser_stack($$).make_nil(); } | TOK_CPROVER_DECREASES '(' ACSL_binding_expression_list ')' { $$=$3; } ; @@ -544,7 +541,7 @@ cprover_contract_decreases_opt: statement_expression: '(' compound_statement ')' { $$=$1; - set(PARSER, $$, ID_side_effect); + set($$, ID_side_effect); parser_stack($$).set(ID_statement, ID_statement_expression); mto($$, $2); } @@ -556,7 +553,7 @@ postfix_expression: { binary($$, $1, $2, ID_index, $3); } | postfix_expression '(' ')' { $$=$2; - set(PARSER, $$, ID_side_effect); + set($$, ID_side_effect); auto &side_effect = to_side_effect_expr(parser_stack($$)); side_effect.set_statement(ID_function_call); side_effect.operands().resize(2); @@ -566,7 +563,7 @@ postfix_expression: } | postfix_expression '(' argument_expression_list ')' { $$=$2; - set(PARSER, $$, ID_side_effect); + set($$, ID_side_effect); auto &side_effect = to_side_effect_expr(parser_stack($$)); side_effect.set_statement(ID_function_call); side_effect.operands().resize(2); @@ -576,25 +573,25 @@ postfix_expression: } | postfix_expression '.' member_name { $$=$2; - set(PARSER, $$, ID_member); + set($$, ID_member); mto($$, $1); parser_stack($$).set(ID_component_name, parser_stack($3).get(ID_C_base_name)); } | postfix_expression TOK_ARROW member_name { $$=$2; - set(PARSER, $$, ID_ptrmember); + set($$, ID_ptrmember); mto($$, $1); parser_stack($$).set(ID_component_name, parser_stack($3).get(ID_C_base_name)); } | postfix_expression TOK_INCR { $$=$2; - set(PARSER, $$, ID_side_effect); + set($$, ID_side_effect); parser_stack($$).set(ID_statement, ID_postincrement); mto($$, $1); } | postfix_expression TOK_DECR { $$=$2; - set(PARSER, $$, ID_side_effect); + set($$, ID_side_effect); parser_stack($$).set(ID_statement, ID_postdecrement); mto($$, $1); } @@ -605,7 +602,7 @@ postfix_expression: tmp.add_source_location()=parser_stack($4).source_location(); tmp.operands().swap(parser_stack($5).operands()); $$=$1; - set(PARSER, $$, ID_typecast); + set($$, ID_typecast); parser_stack($$).add_to_operands(std::move(tmp)); parser_stack($$).type().swap(parser_stack($2)); } @@ -616,7 +613,7 @@ postfix_expression: tmp.add_source_location()=parser_stack($4).source_location(); tmp.operands().swap(parser_stack($5).operands()); $$=$1; - set(PARSER, $$, ID_typecast); + set($$, ID_typecast); parser_stack($$).add_to_operands(std::move(tmp)); parser_stack($$).type().swap(parser_stack($2)); } @@ -630,7 +627,7 @@ member_name: argument_expression_list: assignment_expression { - init(PARSER, $$, ID_expression_list); + init($$, ID_expression_list); mto($$, $1); } | argument_expression_list ',' assignment_expression @@ -644,26 +641,26 @@ unary_expression: postfix_expression | TOK_INCR unary_expression { $$=$1; - set(PARSER, $$, ID_side_effect); + set($$, ID_side_effect); parser_stack($$).set(ID_statement, ID_preincrement); mto($$, $2); } | TOK_DECR unary_expression { $$=$1; - set(PARSER, $$, ID_side_effect); + set($$, ID_side_effect); parser_stack($$).set(ID_statement, ID_predecrement); mto($$, $2); } | '&' cast_expression { $$=$1; - set(PARSER, $$, ID_address_of); + set($$, ID_address_of); mto($$, $2); } | TOK_ANDAND gcc_local_label { // this takes the address of a label (a gcc extension) $$=$1; irep_idt identifier=PARSER.lookup_label(parser_stack($2).get(ID_C_base_name)); - set(PARSER, $$, ID_address_of); + set($$, ID_address_of); parser_stack($$).operands().resize(1); auto &op = to_unary_expr(parser_stack($$)).op(); op=parser_stack($2); @@ -672,43 +669,43 @@ unary_expression: } | '*' cast_expression { $$=$1; - set(PARSER, $$, ID_dereference); + set($$, ID_dereference); mto($$, $2); } | '+' cast_expression { $$=$1; - set(PARSER, $$, ID_unary_plus); + set($$, ID_unary_plus); mto($$, $2); } | '-' cast_expression { $$=$1; - set(PARSER, $$, ID_unary_minus); + set($$, ID_unary_minus); mto($$, $2); } | '~' cast_expression { $$=$1; - set(PARSER, $$, ID_bitnot); + set($$, ID_bitnot); mto($$, $2); } | '!' cast_expression { $$=$1; - set(PARSER, $$, ID_not); + set($$, ID_not); mto($$, $2); } | TOK_SIZEOF unary_expression { $$=$1; - set(PARSER, $$, ID_sizeof); + set($$, ID_sizeof); mto($$, $2); } | TOK_SIZEOF '(' type_name ')' { $$=$1; - set(PARSER, $$, ID_sizeof); + set($$, ID_sizeof); parser_stack($$).add(ID_type_arg).swap(parser_stack($3)); } | TOK_ALIGNOF unary_expression { // note no parentheses for expressions, just like sizeof $$=$1; - set(PARSER, $$, ID_alignof); + set($$, ID_alignof); mto($$, $2); } | TOK_ALIGNOF '(' type_name ')' @@ -724,18 +721,18 @@ cast_expression: | '(' type_name ')' cast_expression { $$=$1; - set(PARSER, $$, ID_typecast); + set($$, ID_typecast); mto($$, $4); parser_stack($$).type().swap(parser_stack($2)); } | TOK_REAL cast_expression { $$=$1; - set(PARSER, $$, ID_complex_real); + set($$, ID_complex_real); mto($$, $2); } | TOK_IMAG cast_expression { $$=$1; - set(PARSER, $$, ID_complex_imag); + set($$, ID_complex_imag); mto($$, $2); } ; @@ -846,7 +843,7 @@ ACSL_binding_expression: | TOK_ACSL_FORALL compound_scope declaration ACSL_binding_expression { $$=$1; - set(PARSER, $$, ID_forall); + set($$, ID_forall); parser_stack($$).add_to_operands(tuple_exprt( { std::move(parser_stack($3)) } )); mto($$, $4); PARSER.pop_scope(); @@ -854,7 +851,7 @@ ACSL_binding_expression: | TOK_ACSL_EXISTS compound_scope declaration ACSL_binding_expression { $$=$1; - set(PARSER, $$, ID_exists); + set($$, ID_exists); parser_stack($$).add_to_operands(tuple_exprt( { std::move(parser_stack($3)) } )); mto($$, $4); PARSER.pop_scope(); @@ -862,7 +859,7 @@ ACSL_binding_expression: | TOK_ACSL_LAMBDA compound_scope declaration ACSL_binding_expression { $$=$1; - set(PARSER, $$, ID_lambda); + set($$, ID_lambda); parser_stack($$).add_to_operands(tuple_exprt( { std::move(parser_stack($3)) } )); mto($$, $4); PARSER.pop_scope(); @@ -925,7 +922,7 @@ constant_expression: comma_expression_opt: /* nothing */ - { init(PARSER, $$); parser_stack($$).make_nil(); } + { init($$); parser_stack($$).make_nil(); } | comma_expression ; @@ -935,13 +932,13 @@ declaration: declaration_specifier ';' { // type only, no declarator! - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); } | type_specifier ';' { // type only, no identifier! - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); } | static_assert_declaration ';' @@ -953,7 +950,7 @@ static_assert_declaration: TOK_STATIC_ASSERT '(' assignment_expression ',' assignment_expression ')' { $$=$1; - set(PARSER, $$, ID_declaration); + set($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_static_assert(true); mto($$, $3); mto($$, $5); @@ -963,7 +960,7 @@ static_assert_declaration: default_declaring_list: declaration_qualifier_list identifier_declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } @@ -975,7 +972,7 @@ default_declaring_list: } | type_qualifier_list identifier_declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } @@ -1014,7 +1011,7 @@ post_declarator_attribute: post_declarator_attributes: post_declarator_attributes post_declarator_attribute { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | post_declarator_attribute ; @@ -1022,7 +1019,7 @@ post_declarator_attributes: post_declarator_attributes_opt: /* nothing */ { - init(PARSER, $$); + init($$); } | post_declarator_attributes ; @@ -1031,10 +1028,10 @@ declaring_list: declaration_specifier declarator post_declarator_attributes_opt { - $2=merge(PARSER, $3, $2); // type attribute + $2=merge($3, $2); // type attribute // the symbol has to be visible during initialization - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } @@ -1047,10 +1044,10 @@ declaring_list: | type_specifier declarator post_declarator_attributes_opt { - $2=merge(PARSER, $3, $2); + $2=merge($3, $2); // the symbol has to be visible during initialization - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } @@ -1067,10 +1064,10 @@ declaring_list: parser_stack($1).id(ID_typeof); parser_stack($1).copy_to_operands(parser_stack($5)); - $2=merge(PARSER, $3, $2); + $2=merge($3, $2); // the symbol has to be visible during initialization - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); // add the initializer @@ -1080,8 +1077,8 @@ declaring_list: post_declarator_attributes_opt { // type attribute goes into declarator - $5=merge(PARSER, $5, $3); - $4=merge(PARSER, $5, $4); + $5=merge($5, $3); + $4=merge($5, $4); PARSER.add_declarator(parser_stack($1), parser_stack($4)); } initializer_opt @@ -1112,16 +1109,16 @@ declaration_qualifier_list: storage_class | type_qualifier_list storage_class { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | gcc_attribute_specifier | declaration_qualifier_list gcc_attribute_specifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | declaration_qualifier_list declaration_qualifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } ; @@ -1129,14 +1126,14 @@ type_qualifier_list: type_qualifier | type_qualifier_list type_qualifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } /* The following is to allow mixing of type attributes with type qualifiers, but the list has to start with a proper type qualifier. */ | type_qualifier_list gcc_attribute_specifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } ; @@ -1144,7 +1141,7 @@ attribute_type_qualifier_list: attribute_or_type_qualifier | attribute_type_qualifier_list attribute_or_type_qualifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } ; @@ -1154,14 +1151,14 @@ declaration_qualifier: ; type_qualifier: - TOK_ATOMIC_TYPE_QUALIFIER { $$=$1; set(PARSER, $$, ID_atomic); } - | TOK_CONST { $$=$1; set(PARSER, $$, ID_const); } - | TOK_RESTRICT { $$=$1; set(PARSER, $$, ID_restrict); } - | TOK_VOLATILE { $$=$1; set(PARSER, $$, ID_volatile); } - | TOK_CPROVER_ATOMIC { $$=$1; set(PARSER, $$, ID_cprover_atomic); } - | TOK_PTR32 { $$=$1; set(PARSER, $$, ID_ptr32); } - | TOK_PTR64 { $$=$1; set(PARSER, $$, ID_ptr64); } - | TOK_MSC_BASED '(' comma_expression ')' { $$=$1; set(PARSER, $$, ID_msc_based); mto($$, $3); } + TOK_ATOMIC_TYPE_QUALIFIER { $$=$1; set($$, ID_atomic); } + | TOK_CONST { $$=$1; set($$, ID_const); } + | TOK_RESTRICT { $$=$1; set($$, ID_restrict); } + | TOK_VOLATILE { $$=$1; set($$, ID_volatile); } + | TOK_CPROVER_ATOMIC { $$=$1; set($$, ID_cprover_atomic); } + | TOK_PTR32 { $$=$1; set($$, ID_ptr32); } + | TOK_PTR64 { $$=$1; set($$, ID_ptr64); } + | TOK_MSC_BASED '(' comma_expression ')' { $$=$1; set($$, ID_msc_based); mto($$, $3); } | alignas_specifier ; @@ -1193,60 +1190,60 @@ attribute_type_qualifier_storage_class_list: attribute_or_type_qualifier_or_storage_class | attribute_type_qualifier_storage_class_list attribute_or_type_qualifier_or_storage_class { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } ; basic_declaration_specifier: declaration_qualifier_list basic_type_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | basic_type_specifier storage_class gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | basic_declaration_specifier declaration_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | basic_declaration_specifier basic_type_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; basic_type_specifier: basic_type_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, $2); // type attribute + $$=merge($1, $2); // type attribute } | type_qualifier_list basic_type_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | basic_type_specifier type_qualifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | basic_type_specifier basic_type_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; sue_declaration_specifier: declaration_qualifier_list elaborated_type_name { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | sue_type_specifier storage_class gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | sue_declaration_specifier declaration_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; @@ -1254,71 +1251,71 @@ sue_type_specifier: elaborated_type_name | type_qualifier_list elaborated_type_name { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | sue_type_specifier type_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; typedef_declaration_specifier: typedef_type_specifier storage_class gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | declaration_qualifier_list typedef_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | typedef_declaration_specifier declaration_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; typeof_declaration_specifier: typeof_type_specifier storage_class gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | declaration_qualifier_list typeof_specifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | typeof_declaration_specifier declaration_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; atomic_declaration_specifier: atomic_type_specifier storage_class gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | declaration_qualifier_list atomic_specifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | atomic_declaration_specifier declaration_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; typedef_type_specifier: typedef_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | type_qualifier_list typedef_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | typedef_type_specifier type_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; @@ -1339,15 +1336,15 @@ typeof_type_specifier: typeof_specifier | type_qualifier_list typeof_specifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | type_qualifier_list typeof_specifier type_qualifier_list { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | typeof_specifier type_qualifier_list { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } ; @@ -1364,15 +1361,15 @@ atomic_type_specifier: atomic_specifier | type_qualifier_list atomic_specifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } | type_qualifier_list atomic_specifier type_qualifier_list { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | atomic_specifier type_qualifier_list { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } ; @@ -1409,13 +1406,13 @@ msc_decl_modifier: { $$=$1; mto($$, $3); mto($$, $5); mto($$, $7); mto($$, $9); } - | ',' { init(PARSER, $$, ID_nil); } + | ',' { init($$, ID_nil); } ; msc_declspec_seq: msc_decl_modifier { - init(PARSER, $$); mto($$, $1); + init($$); mto($$, $1); } | msc_declspec_seq msc_decl_modifier { @@ -1426,19 +1423,19 @@ msc_declspec_seq: msc_declspec: TOK_MSC_DECLSPEC '(' msc_declspec_seq ')' { - $$=$1; set(PARSER, $$, ID_msc_declspec); + $$=$1; set($$, ID_msc_declspec); parser_stack($$).operands().swap(parser_stack($3).operands()); } | TOK_MSC_DECLSPEC '(' ')' { - $$=$1; set(PARSER, $$, ID_msc_declspec); + $$=$1; set($$, ID_msc_declspec); } ; msc_declspec_opt: /* blank */ { - init(PARSER, $$, ID_nil); + init($$, ID_nil); } | msc_declspec_opt msc_declspec { @@ -1457,85 +1454,85 @@ msc_declspec_opt: ; storage_class: - TOK_TYPEDEF { $$=$1; set(PARSER, $$, ID_typedef); } - | TOK_EXTERN { $$=$1; set(PARSER, $$, ID_extern); } - | TOK_STATIC { $$=$1; set(PARSER, $$, ID_static); } - | TOK_AUTO { $$=$1; set(PARSER, $$, ID_auto); } - | TOK_REGISTER { $$=$1; set(PARSER, $$, ID_register); } - | TOK_INLINE { $$=$1; set(PARSER, $$, ID_inline); } - | TOK_THREAD_LOCAL { $$=$1; set(PARSER, $$, ID_thread_local); } - | TOK_GCC_ASM { $$=$1; set(PARSER, $$, ID_asm); } + TOK_TYPEDEF { $$=$1; set($$, ID_typedef); } + | TOK_EXTERN { $$=$1; set($$, ID_extern); } + | TOK_STATIC { $$=$1; set($$, ID_static); } + | TOK_AUTO { $$=$1; set($$, ID_auto); } + | TOK_REGISTER { $$=$1; set($$, ID_register); } + | TOK_INLINE { $$=$1; set($$, ID_inline); } + | TOK_THREAD_LOCAL { $$=$1; set($$, ID_thread_local); } + | TOK_GCC_ASM { $$=$1; set($$, ID_asm); } | msc_declspec { $$=$1; } | TOK_MSC_FORCEINLINE { // equivalent to always_inline, and seemingly also has the semantics // of extern inline in that multiple definitions can be provided in // the same translation unit - init(PARSER, $$); - set(PARSER, $$, ID_static); - set(PARSER, $1, ID_inline); + init($$); + set($$, ID_static); + set($1, ID_inline); #if 0 // enable once always_inline support is reinstantiated $1=merge($1, $$); - init(PARSER, $$); - set(PARSER, $$, ID_always_inline); - $$=merge(PARSER, $1, $$); + init($$); + set($$, ID_always_inline); + $$=merge($1, $$); #else - $$=merge(PARSER, $1, $$); + $$=merge($1, $$); #endif } ; basic_type_name: - TOK_INT { $$=$1; set(PARSER, $$, ID_int); } - | TOK_INT8 { $$=$1; set(PARSER, $$, ID_int8); } - | TOK_INT16 { $$=$1; set(PARSER, $$, ID_int16); } - | TOK_INT32 { $$=$1; set(PARSER, $$, ID_int32); } - | TOK_INT64 { $$=$1; set(PARSER, $$, ID_int64); } - | TOK_CHAR { $$=$1; set(PARSER, $$, ID_char); } - | TOK_SHORT { $$=$1; set(PARSER, $$, ID_short); } - | TOK_LONG { $$=$1; set(PARSER, $$, ID_long); } - | TOK_FLOAT { $$=$1; set(PARSER, $$, ID_float); } - | TOK_GCC_FLOAT16 { $$=$1; set(PARSER, $$, ID_gcc_float16); } - | TOK_GCC_FLOAT32 { $$=$1; set(PARSER, $$, ID_gcc_float32); } - | TOK_GCC_FLOAT32X { $$=$1; set(PARSER, $$, ID_gcc_float32x); } - | TOK_GCC_FLOAT64 { $$=$1; set(PARSER, $$, ID_gcc_float64); } - | TOK_GCC_FLOAT64X { $$=$1; set(PARSER, $$, ID_gcc_float64x); } - | TOK_GCC_FLOAT80 { $$=$1; set(PARSER, $$, ID_gcc_float80); } - | TOK_GCC_FLOAT128 { $$=$1; set(PARSER, $$, ID_gcc_float128); } - | TOK_GCC_FLOAT128X { $$=$1; set(PARSER, $$, ID_gcc_float128x); } - | TOK_GCC_INT128 { $$=$1; set(PARSER, $$, ID_gcc_int128); } - | TOK_GCC_DECIMAL32 { $$=$1; set(PARSER, $$, ID_gcc_decimal32); } - | TOK_GCC_DECIMAL64 { $$=$1; set(PARSER, $$, ID_gcc_decimal64); } - | TOK_GCC_DECIMAL128 { $$=$1; set(PARSER, $$, ID_gcc_decimal128); } - | TOK_DOUBLE { $$=$1; set(PARSER, $$, ID_double); } - | TOK_SIGNED { $$=$1; set(PARSER, $$, ID_signed); } - | TOK_UNSIGNED { $$=$1; set(PARSER, $$, ID_unsigned); } - | TOK_VOID { $$=$1; set(PARSER, $$, ID_void); } - | TOK_BOOL { $$=$1; set(PARSER, $$, ID_c_bool); } - | TOK_COMPLEX { $$=$1; set(PARSER, $$, ID_complex); } + TOK_INT { $$=$1; set($$, ID_int); } + | TOK_INT8 { $$=$1; set($$, ID_int8); } + | TOK_INT16 { $$=$1; set($$, ID_int16); } + | TOK_INT32 { $$=$1; set($$, ID_int32); } + | TOK_INT64 { $$=$1; set($$, ID_int64); } + | TOK_CHAR { $$=$1; set($$, ID_char); } + | TOK_SHORT { $$=$1; set($$, ID_short); } + | TOK_LONG { $$=$1; set($$, ID_long); } + | TOK_FLOAT { $$=$1; set($$, ID_float); } + | TOK_GCC_FLOAT16 { $$=$1; set($$, ID_gcc_float16); } + | TOK_GCC_FLOAT32 { $$=$1; set($$, ID_gcc_float32); } + | TOK_GCC_FLOAT32X { $$=$1; set($$, ID_gcc_float32x); } + | TOK_GCC_FLOAT64 { $$=$1; set($$, ID_gcc_float64); } + | TOK_GCC_FLOAT64X { $$=$1; set($$, ID_gcc_float64x); } + | TOK_GCC_FLOAT80 { $$=$1; set($$, ID_gcc_float80); } + | TOK_GCC_FLOAT128 { $$=$1; set($$, ID_gcc_float128); } + | TOK_GCC_FLOAT128X { $$=$1; set($$, ID_gcc_float128x); } + | TOK_GCC_INT128 { $$=$1; set($$, ID_gcc_int128); } + | TOK_GCC_DECIMAL32 { $$=$1; set($$, ID_gcc_decimal32); } + | TOK_GCC_DECIMAL64 { $$=$1; set($$, ID_gcc_decimal64); } + | TOK_GCC_DECIMAL128 { $$=$1; set($$, ID_gcc_decimal128); } + | TOK_DOUBLE { $$=$1; set($$, ID_double); } + | TOK_SIGNED { $$=$1; set($$, ID_signed); } + | TOK_UNSIGNED { $$=$1; set($$, ID_unsigned); } + | TOK_VOID { $$=$1; set($$, ID_void); } + | TOK_BOOL { $$=$1; set($$, ID_c_bool); } + | TOK_COMPLEX { $$=$1; set($$, ID_complex); } | TOK_CPROVER_BITVECTOR '[' comma_expression ']' { $$=$1; - set(PARSER, $$, ID_custom_bv); + set($$, ID_custom_bv); parser_stack($$).add(ID_size).swap(parser_stack($3)); } | TOK_CPROVER_FLOATBV '[' comma_expression ']' '[' comma_expression ']' { $$=$1; - set(PARSER, $$, ID_custom_floatbv); + set($$, ID_custom_floatbv); parser_stack($$).add(ID_size).swap(parser_stack($3)); parser_stack($$).add(ID_f).swap(parser_stack($6)); } | TOK_CPROVER_FIXEDBV '[' comma_expression ']' '[' comma_expression ']' { $$=$1; - set(PARSER, $$, ID_custom_fixedbv); + set($$, ID_custom_fixedbv); parser_stack($$).add(ID_size).swap(parser_stack($3)); parser_stack($$).add(ID_f).swap(parser_stack($6)); } - | TOK_CPROVER_BOOL { $$=$1; set(PARSER, $$, ID_proper_bool); } + | TOK_CPROVER_BOOL { $$=$1; set($$, ID_proper_bool); } ; elaborated_type_name: @@ -1551,10 +1548,10 @@ array_of_construct: pragma_packed: { - init(PARSER, $$); + init($$); if(!PARSER.pragma_pack.empty() && PARSER.pragma_pack.back().is_one()) - set(PARSER, $$, ID_packed); + set($$, ID_packed); } ; @@ -1574,7 +1571,7 @@ aggregate_name: (irept::subt &)parser_stack($6).operands()); // throw in the gcc attributes - $$=merge(PARSER, $1, merge(PARSER, $2, merge(PARSER, $8, $9))); + $$=merge($1, merge($2, merge($8, $9))); } | aggregate_key gcc_type_attribute_opt @@ -1594,7 +1591,7 @@ aggregate_name: (irept::subt &)parser_stack($7).operands()); // throw in the gcc attributes - $$=merge(PARSER, $1, merge(PARSER, $2, merge(PARSER, $9, $10))); + $$=merge($1, merge($2, merge($9, $10))); } | aggregate_key gcc_type_attribute_opt @@ -1608,57 +1605,57 @@ aggregate_name: { parser_stack($1).set(ID_components, ID_nil); // type attributes - $$=merge(PARSER, $1, merge(PARSER, $2, $6)); + $$=merge($1, merge($2, $6)); } ; aggregate_key: TOK_STRUCT - { $$=$1; set(PARSER, $$, ID_struct); } + { $$=$1; set($$, ID_struct); } | TOK_UNION - { $$=$1; set(PARSER, $$, ID_union); } + { $$=$1; set($$, ID_union); } ; gcc_type_attribute: TOK_GCC_ATTRIBUTE_PACKED - { $$=$1; set(PARSER, $$, ID_packed); } + { $$=$1; set($$, ID_packed); } | TOK_GCC_ATTRIBUTE_TRANSPARENT_UNION - { $$=$1; set(PARSER, $$, ID_transparent_union); } + { $$=$1; set($$, ID_transparent_union); } | TOK_GCC_ATTRIBUTE_VECTOR_SIZE '(' comma_expression ')' - { $$=$1; set(PARSER, $$, ID_frontend_vector); parser_stack($$).add(ID_size)=parser_stack($3); } + { $$=$1; set($$, ID_frontend_vector); parser_stack($$).add(ID_size)=parser_stack($3); } | TOK_GCC_ATTRIBUTE_ALIGNED - { $$=$1; set(PARSER, $$, ID_aligned); } + { $$=$1; set($$, ID_aligned); } | TOK_GCC_ATTRIBUTE_ALIGNED '(' comma_expression ')' - { $$=$1; set(PARSER, $$, ID_aligned); parser_stack($$).set(ID_size, parser_stack($3)); } + { $$=$1; set($$, ID_aligned); parser_stack($$).set(ID_size, parser_stack($3)); } | TOK_GCC_ATTRIBUTE_MODE '(' identifier ')' - { $$=$1; set(PARSER, $$, ID_gcc_attribute_mode); parser_stack($$).set(ID_size, parser_stack($3).get(ID_identifier)); } + { $$=$1; set($$, ID_gcc_attribute_mode); parser_stack($$).set(ID_size, parser_stack($3).get(ID_identifier)); } | TOK_GCC_ATTRIBUTE_GNU_INLINE - { $$=$1; set(PARSER, $$, ID_static); } /* GCC extern inline - cleanup in ansi_c_declarationt::to_symbol */ + { $$=$1; set($$, ID_static); } /* GCC extern inline - cleanup in ansi_c_declarationt::to_symbol */ | TOK_GCC_ATTRIBUTE_WEAK - { $$=$1; set(PARSER, $$, ID_weak); } + { $$=$1; set($$, ID_weak); } | TOK_GCC_ATTRIBUTE_ALIAS '(' TOK_STRING ')' - { $$=$1; set(PARSER, $$, ID_alias); mto($$, $3); } + { $$=$1; set($$, ID_alias); mto($$, $3); } | TOK_GCC_ATTRIBUTE_SECTION '(' TOK_STRING ')' - { $$=$1; set(PARSER, $$, ID_section); mto($$, $3); } + { $$=$1; set($$, ID_section); mto($$, $3); } | TOK_GCC_ATTRIBUTE_NORETURN - { $$=$1; set(PARSER, $$, ID_noreturn); } + { $$=$1; set($$, ID_noreturn); } | TOK_GCC_ATTRIBUTE_CONSTRUCTOR - { $$=$1; set(PARSER, $$, ID_constructor); } + { $$=$1; set($$, ID_constructor); } | TOK_GCC_ATTRIBUTE_DESTRUCTOR - { $$=$1; set(PARSER, $$, ID_destructor); } + { $$=$1; set($$, ID_destructor); } | TOK_GCC_ATTRIBUTE_USED - { $$=$1; set(PARSER, $$, ID_used); } + { $$=$1; set($$, ID_used); } ; gcc_attribute: /* empty */ { - init(PARSER, $$); + init($$); } | TOK_GCC_ATTRIBUTE_FALLTHROUGH { // attribute ignored - init(PARSER, $$); + init($$); } | gcc_type_attribute ; @@ -1667,7 +1664,7 @@ gcc_attribute_list: gcc_attribute | gcc_attribute_list ',' gcc_attribute { - $$=merge(PARSER, $1, $3); + $$=merge($1, $3); } ; @@ -1675,13 +1672,13 @@ gcc_attribute_specifier: TOK_GCC_ATTRIBUTE '(' '(' gcc_attribute_list ')' ')' { $$=$4; } | TOK_NORETURN - { $$=$1; set(PARSER, $$, ID_noreturn); } + { $$=$1; set($$, ID_noreturn); } ; gcc_type_attribute_opt: /* empty */ { - init(PARSER, $$); + init($$); } | gcc_type_attribute_list ; @@ -1690,14 +1687,14 @@ gcc_type_attribute_list: gcc_attribute_specifier | gcc_type_attribute_list gcc_attribute_specifier { - $$=merge(PARSER, $1, $2); + $$=merge($1, $2); } ; member_declaration_list_opt: /* Nothing */ { - init(PARSER, $$, ID_declaration_list); + init($$, ID_declaration_list); } | member_declaration_list ; @@ -1705,7 +1702,7 @@ member_declaration_list_opt: member_declaration_list: member_declaration { - init(PARSER, $$, ID_declaration_list); + init($$, ID_declaration_list); mto($$, $1); } | member_declaration_list member_declaration @@ -1734,9 +1731,9 @@ member_default_declaring_list: type_qualifier_list member_identifier_declarator { - $2=merge(PARSER, $2, $1); + $2=merge($2, $1); - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_member(true); parser_stack($$).add_source_location()=parser_stack($2).source_location(); parser_stack($$).type().swap(parser_stack($2)); @@ -1762,19 +1759,19 @@ member_declaring_list: // communicate #pragma pack(n) alignment constraints by // by both setting packing AND alignment for individual struct/union // members; see padding.cpp for more details - init(PARSER, $$); - set(PARSER, $$, ID_packed); - $2=merge(PARSER, $2, $$); + init($$); + set($$, ID_packed); + $2=merge($2, $$); - init(PARSER, $$); - set(PARSER, $$, ID_aligned); + init($$); + set($$, ID_aligned); parser_stack($$).set(ID_size, PARSER.pragma_pack.back()); - $2=merge(PARSER, $2, $$); + $2=merge($2, $$); } - $2=merge(PARSER, $2, $1); + $2=merge($2, $1); - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_member(true); parser_stack($$).add_source_location()=parser_stack($2).source_location(); parser_stack($$).type().swap(parser_stack($2)); @@ -1793,14 +1790,14 @@ member_declarator: $$=$1; if(parser_stack($2).is_not_nil()) - make_subtype(PARSER, $$, $2); + make_subtype($$, $2); if(parser_stack($3).is_not_nil()) // type attribute - $$=merge(PARSER, $3, $$); + $$=merge($3, $$); } | /* empty */ { - init(PARSER, $$, ID_abstract); + init($$, ID_abstract); } | bit_field_size gcc_type_attribute_opt { @@ -1808,7 +1805,7 @@ member_declarator: stack_type($$).add_subtype()=typet(ID_abstract); if(parser_stack($2).is_not_nil()) // type attribute - $$=merge(PARSER, $2, $$); + $$=merge($2, $$); } ; @@ -1817,10 +1814,10 @@ member_identifier_declarator: { $$=$1; if(parser_stack($2).is_not_nil()) - make_subtype(PARSER, $$, $2); + make_subtype($$, $2); if(parser_stack($3).is_not_nil()) // type attribute - $$=merge(PARSER, $3, $$); + $$=merge($3, $$); } | bit_field_size gcc_type_attribute_opt { @@ -1828,14 +1825,14 @@ member_identifier_declarator: stack_type($$).add_subtype()=typet(ID_abstract); if(parser_stack($2).is_not_nil()) // type attribute - $$=merge(PARSER, $2, $$); + $$=merge($2, $$); } ; bit_field_size_opt: /* nothing */ { - init(PARSER, $$, ID_nil); + init($$, ID_nil); } | bit_field_size ; @@ -1844,7 +1841,7 @@ bit_field_size: ':' constant_expression { $$=$1; - set(PARSER, $$, ID_c_bit_field); + set($$, ID_c_bit_field); stack_type($$).set(ID_size, parser_stack($2)); stack_type($$).add_subtype().id(ID_abstract); } @@ -1865,7 +1862,7 @@ enum_name: gcc_type_attribute_opt { parser_stack($1).operands().swap(parser_stack($6).operands()); - $$=merge(PARSER, $1, merge(PARSER, $2, $8)); // throw in the gcc attributes + $$=merge($1, merge($2, $8)); // throw in the gcc attributes } | enum_key gcc_type_attribute_opt @@ -1892,7 +1889,7 @@ enum_name: parser_stack($1).id(ID_c_enum_tag); } - $$=merge(PARSER, $1, merge(PARSER, $2, $7)); // throw in the gcc attributes + $$=merge($1, merge($2, $7)); // throw in the gcc attributes } ; @@ -1900,7 +1897,7 @@ basic_type_name_list: basic_type_name | basic_type_name_list basic_type_name { - $$ = merge(PARSER, $1, $2); + $$ = merge($1, $2); } enum_underlying_type: @@ -1910,7 +1907,7 @@ enum_underlying_type: enum_underlying_type_opt: /* empty */ { - init(PARSER, $$); + init($$); parser_stack($$).make_nil(); } | ':' enum_underlying_type @@ -1921,7 +1918,7 @@ enum_underlying_type_opt: braced_enumerator_list_opt: /* empty */ { - init(PARSER, $$); + init($$); parser_stack($$).make_nil(); } | '{' enumerator_list_opt '}' @@ -1932,14 +1929,14 @@ braced_enumerator_list_opt: enum_key: TOK_ENUM { $$=$1; - set(PARSER, $$, ID_c_enum); + set($$, ID_c_enum); } ; enumerator_list_opt: /* nothing */ { - init(PARSER, $$, ID_declaration_list); + init($$, ID_declaration_list); } | enumerator_list ; @@ -1947,7 +1944,7 @@ enumerator_list_opt: enumerator_list: enumerator_declaration { - init(PARSER, $$, ID_declaration_list); + init($$, ID_declaration_list); mto($$, $1); } | enumerator_list ',' enumerator_declaration @@ -1964,7 +1961,7 @@ enumerator_list: enumerator_declaration: identifier_or_typedef_name gcc_type_attribute_opt enumerator_value_opt { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_enum_constant(true); PARSER.add_declarator(parser_stack($$), parser_stack($1)); to_ansi_c_declaration(parser_stack($$)).add_initializer(parser_stack($3)); @@ -1974,7 +1971,7 @@ enumerator_declaration: enumerator_value_opt: /* nothing */ { - init(PARSER, $$); + init($$); parser_stack($$).make_nil(); } | '=' constant_expression @@ -1996,7 +1993,7 @@ parameter_type_list: KnR_parameter_list: KnR_parameter { - init(PARSER, $$, ID_parameters); + init($$, ID_parameters); mts($$, $1); } | KnR_parameter_list ',' KnR_parameter @@ -2008,7 +2005,7 @@ KnR_parameter_list: KnR_parameter: identifier { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type()=typet(ID_KnR); PARSER.add_declarator(parser_stack($$), parser_stack($1)); } @@ -2017,7 +2014,7 @@ KnR_parameter: identifier parameter_list: parameter_declaration { - init(PARSER, $$, ID_parameters); + init($$, ID_parameters); mts($$, $1); } | parameter_list ',' parameter_declaration @@ -2030,7 +2027,7 @@ parameter_list: parameter_declaration: declaration_specifier { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); exprt declarator=exprt(ID_abstract); @@ -2038,15 +2035,15 @@ parameter_declaration: } | declaration_specifier parameter_abstract_declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } | declaration_specifier identifier_declarator gcc_type_attribute_opt { - $2=merge(PARSER, $3, $2); // type attribute to go into declarator - init(PARSER, $$, ID_declaration); + $2=merge($3, $2); // type attribute to go into declarator + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); @@ -2055,14 +2052,14 @@ parameter_declaration: { // the second tree is really the declarator -- not part // of the type! - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } | declaration_qualifier_list { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); exprt declarator=exprt(ID_abstract); @@ -2070,22 +2067,22 @@ parameter_declaration: } | declaration_qualifier_list parameter_abstract_declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } | declaration_qualifier_list identifier_declarator gcc_type_attribute_opt { - $2=merge(PARSER, $3, $2); // type attribute to go into declarator - init(PARSER, $$, ID_declaration); + $2=merge($3, $2); // type attribute to go into declarator + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } | type_specifier { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); exprt declarator=exprt(ID_abstract); @@ -2093,15 +2090,15 @@ parameter_declaration: } | type_specifier parameter_abstract_declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } | type_specifier identifier_declarator gcc_type_attribute_opt { - $2=merge(PARSER, $3, $2); // type attribute to go into declarator - init(PARSER, $$, ID_declaration); + $2=merge($3, $2); // type attribute to go into declarator + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); @@ -2109,14 +2106,14 @@ parameter_declaration: | type_specifier parameter_typedef_declarator { // the second tree is really the declarator -- not part of the type! - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } | type_qualifier_list { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); exprt declarator=exprt(ID_abstract); @@ -2124,15 +2121,15 @@ parameter_declaration: } | type_qualifier_list parameter_abstract_declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } | type_qualifier_list identifier_declarator gcc_type_attribute_opt { - $2=merge(PARSER, $3, $2); // type attribute to go into declarator - init(PARSER, $$, ID_declaration); + $2=merge($3, $2); // type attribute to go into declarator + init($$, ID_declaration); to_ansi_c_declaration(parser_stack($$)).set_is_parameter(true); to_ansi_c_declaration(parser_stack($$)).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); @@ -2147,28 +2144,28 @@ identifier_or_typedef_name: type_name: gcc_type_attribute_opt type_specifier { - $$=merge(PARSER, $2, $1); + $$=merge($2, $1); } | gcc_type_attribute_opt type_specifier abstract_declarator { - $$=merge(PARSER, $2, $1); - make_subtype(PARSER, $$, $3); + $$=merge($2, $1); + make_subtype($$, $3); } | gcc_type_attribute_opt type_qualifier_list { - $$=merge(PARSER, $2, $1); + $$=merge($2, $1); } | gcc_type_attribute_opt type_qualifier_list abstract_declarator { - $$=merge(PARSER, $2, $1); - make_subtype(PARSER, $$, $3); + $$=merge($2, $1); + make_subtype($$, $3); } ; initializer_opt: /* nothing */ { - init(PARSER, $$); + init($$); parser_stack($$).make_nil(); } | '=' initializer @@ -2185,13 +2182,13 @@ initializer: | '{' initializer_list_opt '}' { $$=$1; - set(PARSER, $$, ID_initializer_list); + set($$, ID_initializer_list); parser_stack($$).operands().swap(parser_stack($2).operands()); } | '{' initializer_list ',' '}' { $$=$1; - set(PARSER, $$, ID_initializer_list); + set($$, ID_initializer_list); parser_stack($$).operands().swap(parser_stack($2).operands()); } ; @@ -2216,8 +2213,8 @@ initializer_list_opt: initializer_list | /* nothing */ { - init(PARSER, $$); - set(PARSER, $$, ID_initializer_list); + init($$); + set($$, ID_initializer_list); parser_stack($$).operands().clear(); } ; @@ -2234,7 +2231,7 @@ designated_initializer: /* the following two are obsolete GCC extensions */ | designator initializer { - init(PARSER, $$, ID_designated_initializer); + init($$, ID_designated_initializer); parser_stack($$).add(ID_designator).swap(parser_stack($1)); mto($$, $2); } @@ -2255,14 +2252,14 @@ designated_initializer: designator: '.' member_name { - init(PARSER, $$); + init($$); parser_stack($1).id(ID_member); parser_stack($1).set(ID_component_name, parser_stack($2).get(ID_C_base_name)); mto($$, $1); } | '[' comma_expression ']' { - init(PARSER, $$); + init($$); parser_stack($1).id(ID_index); mto($1, $2); mto($$, $1); @@ -2270,7 +2267,7 @@ designator: | '[' comma_expression TOK_ELLIPSIS comma_expression ']' { // TODO - init(PARSER, $$); + init($$); parser_stack($1).id(ID_index); mto($1, $2); mto($$, $1); @@ -2324,8 +2321,8 @@ stmt_not_decl_or_attr: declaration_statement: declaration { - init(PARSER, $$); - statement(PARSER, $$, ID_decl); + init($$); + statement($$, ID_decl); mto($$, $1); } ; @@ -2333,7 +2330,7 @@ declaration_statement: gcc_attribute_specifier_opt: /* empty */ { - init(PARSER, $$); + init($$); } | gcc_attribute_specifier ; @@ -2348,7 +2345,7 @@ labeled_statement: { // we ignore the GCC attribute $$=$2; - statement(PARSER, $$, ID_label); + statement($$, ID_label); irep_idt identifier=PARSER.lookup_label(parser_stack($1).get(ID_C_base_name)); parser_stack($$).set(ID_label, identifier); mto($$, $4); @@ -2356,7 +2353,7 @@ labeled_statement: | msc_label_identifier ':' statement { $$=$2; - statement(PARSER, $$, ID_label); + statement($$, ID_label); irep_idt identifier=PARSER.lookup_label(parser_stack($1).get(ID_C_base_name)); parser_stack($$).set(ID_label, identifier); mto($$, $3); @@ -2364,7 +2361,7 @@ labeled_statement: | TOK_CASE constant_expression ':' statement { $$=$1; - statement(PARSER, $$, ID_switch_case); + statement($$, ID_switch_case); mto($$, $2); mto($$, $4); } @@ -2372,7 +2369,7 @@ labeled_statement: { // this is a GCC extension $$=$1; - statement(PARSER, $$, ID_gcc_switch_case_range); + statement($$, ID_gcc_switch_case_range); mto($$, $2); mto($$, $4); mto($$, $6); @@ -2380,7 +2377,7 @@ labeled_statement: | TOK_DEFAULT ':' statement { $$=$1; - statement(PARSER, $$, ID_switch_case); + statement($$, ID_switch_case); parser_stack($$).operands().push_back(nil_exprt()); mto($$, $3); parser_stack($$).set(ID_default, true); @@ -2395,7 +2392,7 @@ statement_attribute: // https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html // We ignore all such attributes. $$=$1; - statement(PARSER, $$, ID_skip); + statement($$, ID_skip); } ; @@ -2403,14 +2400,14 @@ compound_statement: compound_scope '{' '}' { $$=$2; - statement(PARSER, $$, ID_block); + statement($$, ID_block); parser_stack($$).set(ID_C_end_location, parser_stack($3).source_location()); PARSER.pop_scope(); } | compound_scope '{' statement_list '}' { $$=$2; - statement(PARSER, $$, ID_block); + statement($$, ID_block); parser_stack($$).set(ID_C_end_location, parser_stack($4).source_location()); parser_stack($$).operands().swap(parser_stack($3).operands()); PARSER.pop_scope(); @@ -2418,7 +2415,7 @@ compound_statement: | compound_scope '{' TOK_ASM_STRING '}' { $$=$2; - statement(PARSER, $$, ID_asm); + statement($$, ID_asm); parser_stack($$).set(ID_C_end_location, parser_stack($4).source_location()); mto($$, $3); PARSER.pop_scope(); @@ -2436,7 +2433,7 @@ compound_scope: statement_list: statement { - init(PARSER, $$); + init($$); mto($$, $1); } | statement_list statement @@ -2451,10 +2448,10 @@ expression_statement: $$=$2; if(parser_stack($1).is_nil()) - statement(PARSER, $$, ID_skip); + statement($$, ID_skip); else { - statement(PARSER, $$, ID_expression); + statement($$, ID_expression); mto($$, $1); } } @@ -2464,21 +2461,21 @@ selection_statement: TOK_IF '(' comma_expression ')' statement { $$=$1; - statement(PARSER, $$, ID_ifthenelse); + statement($$, ID_ifthenelse); parser_stack($$).add_to_operands( std::move(parser_stack($3)), std::move(parser_stack($5)), nil_exprt()); } | TOK_IF '(' comma_expression ')' statement TOK_ELSE statement { $$=$1; - statement(PARSER, $$, ID_ifthenelse); + statement($$, ID_ifthenelse); parser_stack($$).add_to_operands( std::move(parser_stack($3)), std::move(parser_stack($5)), std::move(parser_stack($7))); } | TOK_SWITCH '(' comma_expression ')' statement { $$=$1; - statement(PARSER, $$, ID_switch); + statement($$, ID_switch); parser_stack($$).add_to_operands(std::move(parser_stack($3)), std::move(parser_stack($5))); } ; @@ -2496,7 +2493,7 @@ iteration_statement: statement { $$=$1; - statement(PARSER, $$, ID_while); + statement($$, ID_while); parser_stack($$).add_to_operands(std::move(parser_stack($3)), std::move(parser_stack($8))); if(!parser_stack($5).operands().empty()) @@ -2516,7 +2513,7 @@ iteration_statement: TOK_WHILE '(' comma_expression ')' ';' { $$=$1; - statement(PARSER, $$, ID_dowhile); + statement($$, ID_dowhile); parser_stack($$).add_to_operands(std::move(parser_stack($8)), std::move(parser_stack($5))); if(!parser_stack($2).operands().empty()) @@ -2546,7 +2543,7 @@ iteration_statement: statement { $$=$1; - statement(PARSER, $$, ID_for); + statement($$, ID_for); parser_stack($$).operands().reserve(4); mto($$, $4); mto($$, $5); @@ -2573,7 +2570,7 @@ jump_statement: $$=$1; if(parser_stack($2).id()==ID_symbol) { - statement(PARSER, $$, ID_goto); + statement($$, ID_goto); irep_idt identifier=PARSER.lookup_label(parser_stack($2).get(ID_C_base_name)); parser_stack($$).set(ID_destination, identifier); } @@ -2581,36 +2578,36 @@ jump_statement: { // this is a gcc extension. // the original grammar uses identifier_or_typedef_name - statement(PARSER, $$, ID_gcc_computed_goto); + statement($$, ID_gcc_computed_goto); mto($$, $2); } } | TOK_GOTO typedef_name ';' { $$=$1; - statement(PARSER, $$, ID_goto); + statement($$, ID_goto); irep_idt identifier=PARSER.lookup_label(parser_stack($2).get(ID_C_base_name)); parser_stack($$).set(ID_destination, identifier); } | TOK_CONTINUE ';' - { $$=$1; statement(PARSER, $$, ID_continue); } + { $$=$1; statement($$, ID_continue); } | TOK_BREAK ';' - { $$=$1; statement(PARSER, $$, ID_break); } + { $$=$1; statement($$, ID_break); } | TOK_RETURN ';' { $$=$1; - statement(PARSER, $$, ID_return); + statement($$, ID_return); parser_stack($$).operands().push_back(nil_exprt()); } | TOK_RETURN comma_expression ';' - { $$=$1; statement(PARSER, $$, ID_return); mto($$, $2); } + { $$=$1; statement($$, ID_return); mto($$, $2); } ; gcc_local_label_statement: TOK_GCC_LABEL gcc_local_label_list ';' { $$=$1; - statement(PARSER, $$, ID_gcc_local_label); + statement($$, ID_gcc_local_label); // put these into the scope for(const auto &op : as_const(parser_stack($2)).operands()) @@ -2631,7 +2628,7 @@ gcc_local_label_statement: gcc_local_label_list: gcc_local_label { - init(PARSER, $$); + init($$); mto($$, $1); } | gcc_local_label_list ',' gcc_local_label @@ -2647,14 +2644,14 @@ gcc_local_label: identifier_or_typedef_name gcc_asm_statement: TOK_GCC_ASM_PAREN volatile_or_goto_opt '(' gcc_asm_commands ')' ';' { $$=$1; - statement(PARSER, $$, ID_asm); + statement($$, ID_asm); parser_stack($$).set(ID_flavor, ID_gcc); parser_stack($$).operands().swap(parser_stack($4).operands()); } | TOK_GCC_ASM_PAREN volatile_or_goto_opt '{' TOK_ASM_STRING '}' { $$=$1; - statement(PARSER, $$, ID_asm); + statement($$, ID_asm); parser_stack($$).set(ID_flavor, ID_gcc); parser_stack($$).operands().resize(5); to_multi_ary_expr(parser_stack($$)).op0()=parser_stack($4); @@ -2664,13 +2661,13 @@ gcc_asm_statement: msc_asm_statement: TOK_MSC_ASM '{' TOK_ASM_STRING '}' { $$=$1; - statement(PARSER, $$, ID_asm); + statement($$, ID_asm); parser_stack($$).set(ID_flavor, ID_msc); mto($$, $3); } | TOK_MSC_ASM TOK_ASM_STRING { $$=$1; - statement(PARSER, $$, ID_asm); + statement($$, ID_asm); parser_stack($$).set(ID_flavor, ID_msc); mto($$, $2); } @@ -2681,7 +2678,7 @@ msc_seh_statement: TOK_MSC_EXCEPT '(' comma_expression ')' compound_statement { $$=$1; - statement(PARSER, $$, ID_msc_try_except); + statement($$, ID_msc_try_except); mto($$, $2); mto($$, $5); mto($$, $7); @@ -2690,14 +2687,14 @@ msc_seh_statement: TOK_MSC_FINALLY compound_statement { $$=$1; - statement(PARSER, $$, ID_msc_try_finally); + statement($$, ID_msc_try_finally); mto($$, $2); mto($$, $4); } | TOK_MSC_LEAVE { $$=$1; - statement(PARSER, $$, ID_msc_leave); + statement($$, ID_msc_leave); } ; @@ -2705,13 +2702,13 @@ cprover_exception_statement: TOK_CPROVER_THROW ';' { $$=$1; - statement(PARSER, $$, ID_CPROVER_throw); + statement($$, ID_CPROVER_throw); } | TOK_CPROVER_TRY compound_statement TOK_CPROVER_CATCH compound_statement { $$=$1; - statement(PARSER, $$, ID_CPROVER_try_catch); + statement($$, ID_CPROVER_try_catch); mto($$, $2); mto($$, $4); } @@ -2719,7 +2716,7 @@ cprover_exception_statement: TOK_CPROVER_FINALLY compound_statement { $$=$1; - statement(PARSER, $$, ID_CPROVER_try_finally); + statement($$, ID_CPROVER_try_finally); mto($$, $2); mto($$, $4); } @@ -2743,20 +2740,20 @@ volatile_or_goto_opt: gcc_asm_commands: gcc_asm_assembler_template { - init(PARSER, $$); + init($$); parser_stack($$).operands().resize(5); parser_stack($$).operands()[0]=parser_stack($1); } | gcc_asm_assembler_template gcc_asm_outputs { - init(PARSER, $$); + init($$); parser_stack($$).operands().resize(5); parser_stack($$).operands()[0]=parser_stack($1); parser_stack($$).operands()[1]=parser_stack($2); } | gcc_asm_assembler_template gcc_asm_outputs gcc_asm_inputs { - init(PARSER, $$); + init($$); parser_stack($$).operands().resize(5); parser_stack($$).operands()[0]=parser_stack($1); parser_stack($$).operands()[1]=parser_stack($2); @@ -2764,7 +2761,7 @@ gcc_asm_commands: } | gcc_asm_assembler_template gcc_asm_outputs gcc_asm_inputs gcc_asm_clobbered_registers { - init(PARSER, $$); + init($$); parser_stack($$).operands().resize(5); parser_stack($$).operands()[0]=parser_stack($1); parser_stack($$).operands()[1]=parser_stack($2); @@ -2773,7 +2770,7 @@ gcc_asm_commands: } | gcc_asm_assembler_template gcc_asm_outputs gcc_asm_inputs gcc_asm_clobbered_registers gcc_asm_labels { - init(PARSER, $$); + init($$); parser_stack($$).operands().resize(5); parser_stack($$).operands()[0]=parser_stack($1); parser_stack($$).operands()[1]=parser_stack($2); @@ -2813,7 +2810,7 @@ gcc_asm_output: gcc_asm_output_list: gcc_asm_output { - init(PARSER, $$, irep_idt()); + init($$, irep_idt()); mto($$, $1); } | gcc_asm_output_list ',' gcc_asm_output @@ -2850,7 +2847,7 @@ gcc_asm_input: gcc_asm_input_list: gcc_asm_input { - init(PARSER, $$, irep_idt()); + init($$, irep_idt()); mto($$, $1); } | gcc_asm_input_list ',' gcc_asm_input @@ -2871,7 +2868,7 @@ gcc_asm_clobbered_registers: gcc_asm_clobbered_register: string { - init(PARSER, $$, ID_gcc_asm_clobbered_register); + init($$, ID_gcc_asm_clobbered_register); mto($$, $1); } ; @@ -2879,7 +2876,7 @@ gcc_asm_clobbered_register: gcc_asm_clobbered_registers_list: gcc_asm_clobbered_register { - init(PARSER, $$, irep_idt()); + init($$, irep_idt()); mto($$, $1); } | gcc_asm_clobbered_registers_list ',' gcc_asm_clobbered_register @@ -2900,7 +2897,7 @@ gcc_asm_labels: gcc_asm_labels_list: gcc_asm_label { - init(PARSER, $$); + init($$); mto($$, $1); } | gcc_asm_labels_list ',' gcc_asm_label @@ -2984,7 +2981,7 @@ function_body: KnR_parameter_header_opt: /* empty */ { - init(PARSER, $$); + init($$); } | KnR_parameter_header ; @@ -2992,7 +2989,7 @@ KnR_parameter_header_opt: KnR_parameter_header: KnR_parameter_declaration { - init(PARSER, $$, ID_decl_block); + init($$, ID_decl_block); mto($$, $1); } | KnR_parameter_header KnR_parameter_declaration @@ -3011,30 +3008,30 @@ KnR_declaration_qualifier_list: storage_class | type_qualifier storage_class { - $$=merge(PARSER, $2, $1); + $$=merge($2, $1); } | KnR_declaration_qualifier_list declaration_qualifier { - $$=merge(PARSER, $2, $1); + $$=merge($2, $1); } ; KnR_basic_declaration_specifier: KnR_declaration_qualifier_list basic_type_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | basic_type_specifier storage_class gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | KnR_basic_declaration_specifier declaration_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | KnR_basic_declaration_specifier basic_type_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; @@ -3042,15 +3039,15 @@ KnR_basic_declaration_specifier: KnR_typedef_declaration_specifier: typedef_type_specifier storage_class gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | KnR_declaration_qualifier_list typedef_name gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } | KnR_typedef_declaration_specifier declaration_qualifier gcc_type_attribute_opt { - $$=merge(PARSER, $1, merge(PARSER, $2, $3)); + $$=merge($1, merge($2, $3)); } ; @@ -3059,13 +3056,13 @@ KnR_sue_declaration_specifier: KnR_declaration_qualifier_list aggregate_key identifier_or_typedef_name gcc_type_attribute_opt { parser_stack($2).set(ID_tag, parser_stack($3)); - $$=merge(PARSER, $1, merge(PARSER, $2, $4)); + $$=merge($1, merge($2, $4)); } | KnR_declaration_qualifier_list enum_key identifier_or_typedef_name gcc_type_attribute_opt { parser_stack($2).id(ID_c_enum_tag); parser_stack($2).set(ID_tag, parser_stack($3)); - $$=merge(PARSER, $1, merge(PARSER, $2, $4)); + $$=merge($1, merge($2, $4)); } ; @@ -3079,13 +3076,13 @@ KnR_declaration_specifier: KnR_parameter_declaring_list: KnR_declaration_specifier declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } | type_specifier declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); } @@ -3099,41 +3096,41 @@ KnR_parameter_declaring_list: function_head: identifier_declarator /* no return type given */ { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); irept return_type(ID_int); parser_stack($$).type().swap(return_type); PARSER.add_declarator(parser_stack($$), parser_stack($1)); - create_function_scope(PARSER, $$); + create_function_scope($$); } | declaration_specifier declarator post_declarator_attributes_opt { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); - $2=merge(PARSER, $3, $2); + $2=merge($3, $2); PARSER.add_declarator(parser_stack($$), parser_stack($2)); - create_function_scope(PARSER, $$); + create_function_scope($$); } | type_specifier declarator post_declarator_attributes_opt { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); - $2=merge(PARSER, $3, $2); + $2=merge($3, $2); PARSER.add_declarator(parser_stack($$), parser_stack($2)); - create_function_scope(PARSER, $$); + create_function_scope($$); } | declaration_qualifier_list identifier_declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); - create_function_scope(PARSER, $$); + create_function_scope($$); } | type_qualifier_list identifier_declarator { - init(PARSER, $$, ID_declaration); + init($$, ID_declaration); parser_stack($$).type().swap(parser_stack($1)); PARSER.add_declarator(parser_stack($$), parser_stack($2)); - create_function_scope(PARSER, $$); + create_function_scope($$); } ; @@ -3147,24 +3144,24 @@ paren_attribute_declarator: '(' gcc_type_attribute_list identifier_declarator ')' { stack_type($1)=typet(ID_abstract); - $2=merge(PARSER, $2, $1); // dest=$2 - make_subtype(PARSER, $3, $2); // dest=$3 + $2=merge($2, $1); // dest=$2 + make_subtype($3, $2); // dest=$3 $$=$3; } | '(' gcc_type_attribute_list identifier_declarator ')' postfixing_abstract_declarator { stack_type($1)=typet(ID_abstract); - $2=merge(PARSER, $2, $1); // dest=$2 - make_subtype(PARSER, $3, $2); // dest=$3 + $2=merge($2, $1); // dest=$2 + make_subtype($3, $2); // dest=$3 /* note: this is (a pointer to) a function ($5) */ /* or an array ($5) with name ($3) */ $$=$3; - make_subtype(PARSER, $$, $5); + make_subtype($$, $5); } | '*' paren_attribute_declarator { $$=$2; - do_pointer(PARSER, $1, $2); + do_pointer($1, $2); } ; @@ -3178,7 +3175,7 @@ parameter_typedef_declarator: | typedef_name postfixing_abstract_declarator { $$=$1; - make_subtype(PARSER, $$, $2); + make_subtype($$, $2); } | clean_typedef_declarator ; @@ -3188,12 +3185,12 @@ clean_typedef_declarator: | '*' parameter_typedef_declarator { $$=$2; - do_pointer(PARSER, $1, $2); + do_pointer($1, $2); } | '*' attribute_type_qualifier_list parameter_typedef_declarator { - $$=merge(PARSER, $2, $3); - do_pointer(PARSER, $1, $2); + $$=merge($2, $3); + do_pointer($1, $2); } ; @@ -3205,7 +3202,7 @@ clean_postfix_typedef_declarator: /* note: this is a pointer ($2) to a function ($4) */ /* or an array ($4)! */ $$=$2; - make_subtype(PARSER, $$, $4); + make_subtype($$, $4); } ; @@ -3214,23 +3211,23 @@ paren_typedef_declarator: | '*' '(' simple_paren_typedef_declarator ')' { $$=$3; - do_pointer(PARSER, $1, $3); + do_pointer($1, $3); } | '*' attribute_type_qualifier_list '(' simple_paren_typedef_declarator ')' { // not sure where the type qualifiers belong - $$=merge(PARSER, $2, $4); - do_pointer(PARSER, $1, $2); + $$=merge($2, $4); + do_pointer($1, $2); } | '*' paren_typedef_declarator { $$=$2; - do_pointer(PARSER, $1, $2); + do_pointer($1, $2); } | '*' attribute_type_qualifier_list paren_typedef_declarator { - $$=merge(PARSER, $2, $3); - do_pointer(PARSER, $1, $2); + $$=merge($2, $3); + do_pointer($1, $2); } ; @@ -3240,14 +3237,14 @@ paren_postfix_typedef_declarator: | '(' simple_paren_typedef_declarator postfixing_abstract_declarator ')' { /* note: this is a function ($3) with a typedef name ($2) */ $$=$2; - make_subtype(PARSER, $$, $3); + make_subtype($$, $3); } | '(' paren_typedef_declarator ')' postfixing_abstract_declarator { /* note: this is a pointer ($2) to a function ($4) */ /* or an array ($4)! */ $$=$2; - make_subtype(PARSER, $$, $4); + make_subtype($$, $4); } ; @@ -3267,14 +3264,14 @@ unary_identifier_declarator: | '*' identifier_declarator { $$=$2; - do_pointer(PARSER, $1, $2); + do_pointer($1, $2); } | '^' identifier_declarator { // This is an Apple extension to C/C++/Objective C. // http://en.wikipedia.org/wiki/Blocks_(C_language_extension) $$=$2; - do_pointer(PARSER, $1, $2); + do_pointer($1, $2); } | '*' attribute_type_qualifier_list identifier_declarator { @@ -3284,8 +3281,8 @@ unary_identifier_declarator: // the width is added during conversion. stack_type($1).id(ID_frontend_pointer); stack_type($1).add_subtype()=typet(ID_abstract); - $2=merge(PARSER, $2, $1); // dest=$2 - make_subtype(PARSER, $3, $2); // dest=$3 + $2=merge($2, $1); // dest=$2 + make_subtype($3, $2); // dest=$3 $$=$3; } ; @@ -3295,7 +3292,7 @@ postfix_identifier_declarator: { /* note: this is a function or array ($2) with name ($1) */ $$=$1; - make_subtype(PARSER, $$, $2); + make_subtype($$, $2); } | '(' unary_identifier_declarator ')' { $$ = $2; } @@ -3304,7 +3301,7 @@ postfix_identifier_declarator: /* note: this is a pointer ($2) to a function ($4) */ /* or an array ($4)! */ $$=$2; - make_subtype(PARSER, $$, $4); + make_subtype($$, $4); } ; @@ -3335,13 +3332,13 @@ cprover_function_contract: TOK_CPROVER_ENSURES '(' ACSL_binding_expression ')' { $$=$1; - set(PARSER, $$, ID_C_spec_ensures); + set($$, ID_C_spec_ensures); mto($$, $3); } | TOK_CPROVER_REQUIRES '(' ACSL_binding_expression ')' { $$=$1; - set(PARSER, $$, ID_C_spec_requires); + set($$, ID_C_spec_requires); mto($$, $3); } | cprover_contract_assigns @@ -3351,7 +3348,7 @@ cprover_function_contract: unary_expression_list: unary_expression { - init(PARSER, $$, ID_expression_list); + init($$, ID_expression_list); parser_stack($$).add_source_location()=parser_stack($1).source_location(); mto($$, $1); } @@ -3365,7 +3362,7 @@ unary_expression_list: conditional_target_group: unary_expression_list { - init(PARSER, $$, ID_conditional_target_group); + init($$, ID_conditional_target_group); parser_stack($$).add_source_location()=parser_stack($1).source_location(); parser_stack($$).add_to_operands(true_exprt{}); mto($$, $1); @@ -3373,7 +3370,7 @@ conditional_target_group: | logical_equivalence_expression ':' unary_expression_list { $$=$2; - set(PARSER, $$, ID_conditional_target_group); + set($$, ID_conditional_target_group); mto($$, $1); mto($$, $3); } @@ -3382,7 +3379,7 @@ conditional_target_group: conditional_target_list: conditional_target_group { - init(PARSER, $$, ID_target_list); + init($$, ID_target_list); mto($$, $1); } | conditional_target_list ';' conditional_target_group @@ -3406,20 +3403,20 @@ cprover_contract_assigns: TOK_CPROVER_ASSIGNS '(' conditional_target_list_opt_semicol ')' { $$=$1; - set(PARSER, $$, ID_C_spec_assigns); + set($$, ID_C_spec_assigns); mto($$, $3); } | TOK_CPROVER_ASSIGNS '(' ')' { $$=$1; - set(PARSER, $$, ID_C_spec_assigns); + set($$, ID_C_spec_assigns); parser_stack($$).add_to_operands(exprt(ID_target_list)); } ; cprover_contract_assigns_opt: /* nothing */ - { init(PARSER, $$); parser_stack($$).make_nil(); } + { init($$); parser_stack($$).make_nil(); } | cprover_contract_assigns ; @@ -3427,13 +3424,13 @@ cprover_contract_frees: TOK_CPROVER_FREES '(' conditional_target_list_opt_semicol ')' { $$=$1; - set(PARSER, $$, ID_C_spec_frees); + set($$, ID_C_spec_frees); mto($$, $3); } | TOK_CPROVER_FREES '(' ')' { $$=$1; - set(PARSER, $$, ID_C_spec_frees); + set($$, ID_C_spec_frees); parser_stack($$).add_to_operands(exprt(ID_target_list)); } ; @@ -3443,13 +3440,13 @@ cprover_function_contract_sequence: | cprover_function_contract_sequence cprover_function_contract { $$=$1; - merge(PARSER, $$, $2); + merge($$, $2); } ; cprover_function_contract_sequence_opt: /* nothing */ - { init(PARSER, $$); } + { init($$); } | cprover_function_contract_sequence { // Function contracts should either be attached to a @@ -3460,10 +3457,7 @@ cprover_function_contract_sequence_opt: int contract_in_top_level_function_scope = (PARSER.scopes.size() == 2); if(!contract_in_global_scope && !contract_in_top_level_function_scope) { - yyansi_cerror( - PARSER, - scanner, - "Function contracts allowed only at top-level declarations."); + yyansi_cerror("Function contracts allowed only at top-level declarations."); YYABORT; } } @@ -3477,7 +3471,7 @@ postfixing_abstract_declarator: KnR_parameter_header { $$=$1; - set(PARSER, $$, ID_code); + set($$, ID_code); stack_type($$).add_subtype()=typet(ID_abstract); stack_type($$).add(ID_parameters); stack_type($$).set(ID_C_KnR, true); @@ -3494,7 +3488,7 @@ postfixing_abstract_declarator: KnR_parameter_header_opt { $$=$1; - set(PARSER, $$, ID_code); + set($$, ID_code); stack_type($$).add_subtype()=typet(ID_abstract); stack_type($$).add(ID_parameters).get_sub(). swap((irept::subt &)(to_type_with_subtypes(stack_type($3)).subtypes())); @@ -3521,7 +3515,7 @@ parameter_postfixing_abstract_declarator: } cprover_function_contract_sequence_opt { - set(PARSER, $1, ID_code); + set($1, ID_code); stack_type($1).add(ID_parameters); stack_type($1).add_subtype()=typet(ID_abstract); PARSER.pop_scope(); @@ -3532,7 +3526,7 @@ parameter_postfixing_abstract_declarator: PARSER.set_function(irep_idt()); } - $$ = merge(PARSER, $4, $1); + $$ = merge($4, $1); } | '(' { @@ -3552,7 +3546,7 @@ parameter_postfixing_abstract_declarator: KnR_parameter_header_opt cprover_function_contract_sequence_opt { - set(PARSER, $1, ID_code); + set($1, ID_code); stack_type($1).add_subtype()=typet(ID_abstract); stack_type($1).add(ID_parameters).get_sub(). swap((irept::subt &)(to_type_with_subtypes(stack_type($3)).subtypes())); @@ -3570,7 +3564,7 @@ parameter_postfixing_abstract_declarator: parser_stack($$).set(ID_C_KnR, true); } - $$ = merge(PARSER, $6, $1); + $$ = merge($6, $1); } ; @@ -3578,7 +3572,7 @@ array_abstract_declarator: '[' ']' { $$=$1; - set(PARSER, $$, ID_array); + set($$, ID_array); stack_type($$).add_subtype()=typet(ID_abstract); stack_type($$).add(ID_size).make_nil(); } @@ -3587,23 +3581,23 @@ array_abstract_declarator: // this is C99: e.g., restrict, const, etc // The type qualifier belongs to the array, not the // contents of the array, nor the size. - set(PARSER, $1, ID_array); + set($1, ID_array); stack_type($1).add_subtype()=typet(ID_abstract); stack_type($1).add(ID_size).make_nil(); - $$=merge(PARSER, $2, $1); + $$=merge($2, $1); } | '[' '*' ']' { // these should be allowed in prototypes only $$=$1; - set(PARSER, $$, ID_array); + set($$, ID_array); stack_type($$).add_subtype()=typet(ID_abstract); stack_type($$).add(ID_size).make_nil(); } | '[' constant_expression ']' { $$=$1; - set(PARSER, $$, ID_array); + set($$, ID_array); stack_type($$).add(ID_size).swap(parser_stack($2)); stack_type($$).add_subtype()=typet(ID_abstract); } @@ -3611,29 +3605,29 @@ array_abstract_declarator: { // The type qualifier belongs to the array, not the // contents of the array, nor the size. - set(PARSER, $1, ID_array); + set($1, ID_array); stack_type($1).add(ID_size).swap(parser_stack($3)); stack_type($1).add_subtype()=typet(ID_abstract); - $$=merge(PARSER, $2, $1); // dest=$2 + $$=merge($2, $1); // dest=$2 } | array_abstract_declarator '[' constant_expression ']' { // we need to push this down $$=$1; - set(PARSER, $2, ID_array); + set($2, ID_array); stack_type($2).add(ID_size).swap(parser_stack($3)); stack_type($2).add_subtype()=typet(ID_abstract); - make_subtype(PARSER, $1, $2); + make_subtype($1, $2); } | array_abstract_declarator '[' '*' ']' { // these should be allowed in prototypes only // we need to push this down $$=$1; - set(PARSER, $2, ID_array); + set($2, ID_array); stack_type($2).add(ID_size).make_nil(); stack_type($2).add_subtype()=typet(ID_abstract); - make_subtype(PARSER, $1, $2); + make_subtype($1, $2); } ; @@ -3654,12 +3648,12 @@ unary_abstract_declarator: // the width is added during conversion. stack_type($1).id(ID_frontend_pointer); stack_type($1).add_subtype()=typet(ID_abstract); - $$=merge(PARSER, $2, $1); + $$=merge($2, $1); } | '*' abstract_declarator { $$=$2; - do_pointer(PARSER, $1, $2); + do_pointer($1, $2); } | '*' attribute_type_qualifier_list abstract_declarator { @@ -3669,8 +3663,8 @@ unary_abstract_declarator: // the width is added during conversion. stack_type($1).id(ID_frontend_pointer); stack_type($1).add_subtype()=typet(ID_abstract); - $2=merge(PARSER, $2, $1); // dest=$2 - make_subtype(PARSER, $3, $2); // dest=$3 + $2=merge($2, $1); // dest=$2 + make_subtype($3, $2); // dest=$3 $$=$3; } | '^' @@ -3678,7 +3672,7 @@ unary_abstract_declarator: // This is an Apple extension to C/C++/Objective C. // http://en.wikipedia.org/wiki/Blocks_(C_language_extension) $$=$1; - set(PARSER, $$, ID_block_pointer); + set($$, ID_block_pointer); stack_type($$).add_subtype()=typet(ID_abstract); } ; @@ -3700,12 +3694,12 @@ parameter_unary_abstract_declarator: // the width is added during conversion. stack_type($1).id(ID_frontend_pointer); stack_type($1).add_subtype()=typet(ID_abstract); - $$=merge(PARSER, $2, $1); + $$=merge($2, $1); } | '*' parameter_abstract_declarator { $$=$2; - do_pointer(PARSER, $1, $2); + do_pointer($1, $2); } | '*' attribute_type_qualifier_list parameter_abstract_declarator { @@ -3715,8 +3709,8 @@ parameter_unary_abstract_declarator: // the width is added during conversion. stack_type($1).id(ID_frontend_pointer); stack_type($1).add_subtype()=typet(ID_abstract); - $2=merge(PARSER, $2, $1); // dest=$2 - make_subtype(PARSER, $3, $2); // dest=$3 + $2=merge($2, $1); // dest=$2 + make_subtype($3, $2); // dest=$3 $$=$3; } | '^' @@ -3724,7 +3718,7 @@ parameter_unary_abstract_declarator: // This is an Apple extension to C/C++/Objective C. // http://en.wikipedia.org/wiki/Blocks_(C_language_extension) $$=$1; - set(PARSER, $$, ID_block_pointer); + set($$, ID_block_pointer); stack_type($$).add_subtype()=typet(ID_abstract); } ; @@ -3740,13 +3734,13 @@ postfix_abstract_declarator: { /* note: this is a pointer ($2) to a function or array ($4) */ $$=$2; - make_subtype(PARSER, $$, $4); + make_subtype($$, $4); } | '(' unary_abstract_declarator ')' postfixing_abstract_declarator { /* note: this is a pointer ($2) to a function or array ($4) */ $$=$2; - make_subtype(PARSER, $$, $4); + make_subtype($$, $4); } ; @@ -3760,6 +3754,6 @@ parameter_postfix_abstract_declarator: { /* note: this is a pointer ($2) to a function ($4) */ $$=$2; - make_subtype(PARSER, $$, $4); + make_subtype($$, $4); } ; diff --git a/src/ansi-c/parser_static.inc b/src/ansi-c/parser_static.inc index 3dfd8b772b0..b38947b7e92 100644 --- a/src/ansi-c/parser_static.inc +++ b/src/ansi-c/parser_static.inc @@ -9,7 +9,7 @@ #define mto(x, y) parser_stack(x).add_to_operands(std::move(parser_stack(y))) #define mts(x, y) (to_type_with_subtypes(stack_type(x)).move_to_subtypes(stack_type(y))) -#define binary(x, y, l, id, z) { init(PARSER, x, id); \ +#define binary(x, y, l, id, z) { init(x, id); \ parser_stack(x).add_source_location()=parser_stack(l).source_location(); \ parser_stack(x).add_to_operands(std::move(parser_stack(y)), std::move(parser_stack(z))); } @@ -25,7 +25,7 @@ Function: init \*******************************************************************/ -static void init(ansi_c_parsert &ansi_c_parser, YYSTYPE &expr) +static void init(YYSTYPE &expr) { newstack(expr); } @@ -42,10 +42,7 @@ Function: init \*******************************************************************/ -inline static void init( - ansi_c_parsert &ansi_c_parser, - YYSTYPE &expr, - const irep_idt &id) +inline static void init(YYSTYPE &expr, const irep_idt &id) { newstack(expr); parser_stack(expr).id(id); @@ -63,10 +60,7 @@ Function: set \*******************************************************************/ -inline static void set( - ansi_c_parsert &ansi_c_parser, - YYSTYPE expr, - const irep_idt &id) +inline static void set(YYSTYPE expr, const irep_idt &id) { parser_stack(expr).id(id); } @@ -83,12 +77,9 @@ Function: statement \*******************************************************************/ -static void statement( - ansi_c_parsert &ansi_c_parser, - YYSTYPE &expr, - const irep_idt &id) +static void statement(YYSTYPE &expr, const irep_idt &id) { - set(ansi_c_parser, expr, ID_code); + set(expr, ID_code); parser_stack(expr).set(ID_statement, id); } @@ -145,10 +136,7 @@ Function: merge_types \*******************************************************************/ #if 0 -static void merge_types( - ansi_c_parsert &ansi_c_parser, - const YYSTYPE dest, - const YYSTYPE src) +static void merge_types(const YYSTYPE dest, const YYSTYPE src) { merge_types(parser_stack(dest), parser_stack(src)); } @@ -166,10 +154,7 @@ Function: merge \*******************************************************************/ -static YYSTYPE merge( - ansi_c_parsert &ansi_c_parser, - const YYSTYPE src1, - const YYSTYPE src2) +static YYSTYPE merge(const YYSTYPE src1, const YYSTYPE src2) { merge_types(parser_stack(src1), parser_stack(src2)); return src1; @@ -285,10 +270,7 @@ Function: make_subtype \*******************************************************************/ -static void make_subtype( - ansi_c_parsert &ansi_c_parser, - YYSTYPE dest, - YYSTYPE src) +static void make_subtype(YYSTYPE dest, YYSTYPE src) { make_subtype(stack_type(dest), stack_type(src)); } @@ -305,7 +287,7 @@ Function: make_pointer \*******************************************************************/ -static void make_pointer(ansi_c_parsert &ansi_c_parser, const YYSTYPE dest) +static void make_pointer(const YYSTYPE dest) { // The below deliberately avoids pointer_type(). // The width is set during conversion. @@ -325,13 +307,10 @@ Function: do_pointer \*******************************************************************/ -static void do_pointer( - ansi_c_parsert &ansi_c_parser, - const YYSTYPE ptr, - const YYSTYPE dest) +static void do_pointer(const YYSTYPE ptr, const YYSTYPE dest) { - make_pointer(ansi_c_parser, ptr); - make_subtype(ansi_c_parser, dest, ptr); + make_pointer(ptr); + make_subtype(dest, ptr); } /*******************************************************************\ @@ -346,9 +325,7 @@ Function: create_function_scope \*******************************************************************/ -static void create_function_scope( - ansi_c_parsert &ansi_c_parser, - const YYSTYPE d) +static void create_function_scope(const YYSTYPE d) { ansi_c_declarationt &declaration=to_ansi_c_declaration(parser_stack(d)); ansi_c_declaratort &declarator=declaration.declarator(); diff --git a/src/ansi-c/scanner.l b/src/ansi-c/scanner.l index 6d0373dbc9c..9a97ff32626 100644 --- a/src/ansi-c/scanner.l +++ b/src/ansi-c/scanner.l @@ -2,8 +2,6 @@ %option noinput %option stack %option noyywrap -%option reentrant -%option extra-type="ansi_c_parsert *" %{ @@ -41,36 +39,46 @@ static int isatty(int) { return 0; } #include "literals/convert_string_literal.h" #include "literals/unescape_string.h" -#define PARSER (*yyansi_cget_extra(yyscanner)) +#define PARSER (*ansi_c_parser) #define YYSTYPE unsigned #undef ECHO #define ECHO #include "ansi_c_parser.h" #include "ansi_c_y.tab.h" +#ifdef ANSI_C_DEBUG +extern int yyansi_cdebug; +#endif -int yyansi_cerror(ansi_c_parsert &, void *, const std::string &); +static ansi_c_parsert *ansi_c_parser; +void ansi_c_scanner_init(ansi_c_parsert &_ansi_c_parser) +{ +#ifdef ANSI_C_DEBUG + yyansi_cdebug=1; +#endif + ansi_c_parser = &_ansi_c_parser; + YY_FLUSH_BUFFER; + BEGIN(0); +} + +int yyansi_cerror(const std::string &error) +{ + ansi_c_parser->parse_error(error, yyansi_ctext); + return 0; +} #define loc() \ { newstack(yyansi_clval); PARSER.set_source_location(parser_stack(yyansi_clval)); } -ansi_c_parsert *yyansi_cget_extra(void *); -#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) -size_t yyansi_cget_leng(void *); -#else -int yyansi_cget_leng(void *); -#endif -char *yyansi_cget_text(void *); - -int make_identifier(void *yyscanner) +int make_identifier() { loc(); // deal with universal charater names std::string final_base_name; - final_base_name.reserve(yyansi_cget_leng(yyscanner)); + final_base_name.reserve(yyleng); - for(const char *p=yyansi_cget_text(yyscanner); *p!=0; p++) + for(const char *p=yytext; *p!=0; p++) { if(p[0]=='\\' && (p[1]=='u' || p[1]=='U')) { @@ -129,7 +137,7 @@ int make_identifier(void *yyscanner) } } -int MSC_Keyword(int token, void *yyscanner) +int MSC_Keyword(int token) { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { @@ -138,10 +146,10 @@ int MSC_Keyword(int token, void *yyscanner) return token; } else - return make_identifier(yyscanner); + return make_identifier(); } -int cpp98_keyword(int token, void *yyscanner) +int cpp98_keyword(int token) { if(PARSER.cpp98) { @@ -149,10 +157,10 @@ int cpp98_keyword(int token, void *yyscanner) return token; } else - return make_identifier(yyscanner); + return make_identifier(); } -int cpp11_keyword(int token, void *yyscanner) +int cpp11_keyword(int token) { if(PARSER.cpp11) { @@ -160,10 +168,10 @@ int cpp11_keyword(int token, void *yyscanner) return token; } else - return make_identifier(yyscanner); + return make_identifier(); } -int MSC_cpp_keyword(int token, void *yyscanner) +int MSC_cpp_keyword(int token) { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { @@ -171,10 +179,10 @@ int MSC_cpp_keyword(int token, void *yyscanner) return token; } else - return make_identifier(yyscanner); + return make_identifier(); } -int cpp_operator(int token, void *yyscanner) +int cpp_operator(int token) { if(PARSER.cpp98) { @@ -183,7 +191,7 @@ int cpp_operator(int token, void *yyscanner) } else { - yyansi_cerror(PARSER, yyscanner, "C++ operator not allowed in C mode"); + yyansi_cerror("C++ operator not allowed in C mode"); return TOK_SCANNER_ERROR; } } @@ -287,17 +295,17 @@ enable_or_disable ("enable"|"disable") { "*/" { BEGIN(GRAMMAR); } /* end comment state, back to GRAMMAR */ - "/*" { yyansi_cerror(PARSER, yyscanner, "Probably nested comments"); } - <> { yyansi_cerror(PARSER, yyscanner, "Unterminated comment"); return TOK_SCANNER_ERROR; } + "/*" { yyansi_cerror("Probably nested comments"); } + <> { yyansi_cerror("Unterminated comment"); return TOK_SCANNER_ERROR; } [^*/\n]* { /* ignore every char except '*' and NL (performance!) */ } . { } /* all single characters within comments are ignored */ \n { } } { - "*/" { yy_pop_state(yyscanner); } /* end comment state, back to STRING_LITERAL */ - "/*" { yyansi_cerror(PARSER, yyscanner, "Probably nested comments"); } - <> { yyansi_cerror(PARSER, yyscanner, "Unterminated comment"); return TOK_SCANNER_ERROR; } + "*/" { yy_pop_state(); } /* end comment state, back to STRING_LITERAL */ + "/*" { yyansi_cerror("Probably nested comments"); } + <> { yyansi_cerror("Unterminated comment"); return TOK_SCANNER_ERROR; } [^*/\n]* { /* ignore every char except '*' and NL (performance!) */ } . { } /* all single characters within comments are ignored */ \n { } @@ -323,9 +331,9 @@ enable_or_disable ("enable"|"disable") loc(); // String literals can be continued in // the next line - yy_push_state(STRING_LITERAL, yyscanner); + yy_push_state(STRING_LITERAL); // use yy_top_state() to keep the compiler happy - (void)yy_top_state(yyscanner); + (void)yy_top_state(); } {string_lit} { PARSER.string_literal.append(yytext); } @@ -336,13 +344,13 @@ enable_or_disable ("enable"|"disable") PARSER.set_line_no(PARSER.get_line_no()-1); } {cppstart}.* { /* ignore */ } -"/*" { yy_push_state(STRING_LITERAL_COMMENT, yyscanner); /* C comment, ignore */ } +"/*" { yy_push_state(STRING_LITERAL_COMMENT); /* C comment, ignore */ } "//".*\n { /* C++ comment, ignore */ } . { // anything else: back to normal source_locationt l=parser_stack(yyansi_clval).source_location(); parser_stack(yyansi_clval)=convert_string_literal(PARSER.string_literal); parser_stack(yyansi_clval).add_source_location().swap(l); - yy_pop_state(yyscanner); // back to normal + yy_pop_state(); // back to normal yyless(0); // put back return TOK_STRING; } @@ -427,8 +435,6 @@ enable_or_disable ("enable"|"disable") if(clash) { yyansi_cerror( - PARSER, - yyscanner, "Found enable and disable pragmas for " + id2string(check_name)); return TOK_SCANNER_ERROR; @@ -438,7 +444,7 @@ enable_or_disable ("enable"|"disable") } . { - yyansi_cerror(PARSER, yyscanner, "Unsupported #pragma CPROVER"); + yyansi_cerror("Unsupported #pragma CPROVER"); return TOK_SCANNER_ERROR; } @@ -461,7 +467,7 @@ enable_or_disable ("enable"|"disable") return '{'; } else - return make_identifier(yyscanner); + return make_identifier(); } {cppstart}"endasm" { @@ -470,7 +476,7 @@ enable_or_disable ("enable"|"disable") } {cppdirective} { - yyansi_cerror(PARSER, yyscanner, "Preprocessor directive found"); + yyansi_cerror("Preprocessor directive found"); return TOK_SCANNER_ERROR; } @@ -481,7 +487,7 @@ enable_or_disable ("enable"|"disable") { "auto" { loc(); return TOK_AUTO; } "_Bool" { if(PARSER.cpp98) - return make_identifier(yyscanner); + return make_identifier(); else { loc(); return TOK_BOOL; } } @@ -525,43 +531,43 @@ enable_or_disable ("enable"|"disable") && !PARSER.cpp98) { loc(); return TOK_GCC_AUTO_TYPE; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Float16" { if(PARSER.float16_type) { loc(); return TOK_GCC_FLOAT16; } else - return make_identifier(yyscanner); + return make_identifier(); } "__bf16" { if(PARSER.bf16_type) { loc(); return TOK_GCC_FLOAT16; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Float32" { if(PARSER.ts_18661_3_Floatn_types) { loc(); return TOK_GCC_FLOAT32; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Float32x" { if(PARSER.ts_18661_3_Floatn_types) { loc(); return TOK_GCC_FLOAT32X; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Float64" { if(PARSER.ts_18661_3_Floatn_types) { loc(); return TOK_GCC_FLOAT64; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Float64x" { if(PARSER.ts_18661_3_Floatn_types) { loc(); return TOK_GCC_FLOAT64X; } else - return make_identifier(yyscanner); + return make_identifier(); } {CPROVER_PREFIX}"Float64x" { @@ -577,13 +583,13 @@ enable_or_disable ("enable"|"disable") if(PARSER.mode==configt::ansi_ct::flavourt::CLANG) { loc(); return TOK_GCC_FLOAT128; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Float128" { if(PARSER.ts_18661_3_Floatn_types) { loc(); return TOK_GCC_FLOAT128; } else - return make_identifier(yyscanner); + return make_identifier(); } {CPROVER_PREFIX}"Float128" { @@ -593,61 +599,61 @@ enable_or_disable ("enable"|"disable") "_Float128x" { if(PARSER.ts_18661_3_Floatn_types) { loc(); return TOK_GCC_FLOAT128X; } else - return make_identifier(yyscanner); + return make_identifier(); } "__int128" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || PARSER.mode==configt::ansi_ct::flavourt::CLANG) { loc(); return TOK_GCC_INT128; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Decimal32" { // clang doesn't have it if(PARSER.mode==configt::ansi_ct::flavourt::GCC) { loc(); return TOK_GCC_DECIMAL32; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Decimal64" { // clang doesn't have it if(PARSER.mode==configt::ansi_ct::flavourt::GCC) { loc(); return TOK_GCC_DECIMAL64; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Decimal128" { // clang doesn't have it if(PARSER.mode==configt::ansi_ct::flavourt::GCC) { loc(); return TOK_GCC_DECIMAL128; } else - return make_identifier(yyscanner); + return make_identifier(); } -"__int8" { return MSC_Keyword(TOK_INT8, yyscanner); } -"__int16" { return MSC_Keyword(TOK_INT16, yyscanner); } -"__int32" { return MSC_Keyword(TOK_INT32, yyscanner); } +"__int8" { return MSC_Keyword(TOK_INT8); } +"__int16" { return MSC_Keyword(TOK_INT16); } +"__int32" { return MSC_Keyword(TOK_INT32); } "__int64" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO || PARSER.mode==configt::ansi_ct::flavourt::ARM || PARSER.mode==configt::ansi_ct::flavourt::CODEWARRIOR) { loc(); return TOK_INT64; } else - return make_identifier(yyscanner); + return make_identifier(); } "_int64" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { loc(); return TOK_INT64; } else - return make_identifier(yyscanner); + return make_identifier(); } -"__ptr32" { return MSC_Keyword(TOK_PTR32, yyscanner); } -"__ptr64" { return MSC_Keyword(TOK_PTR64, yyscanner); } +"__ptr32" { return MSC_Keyword(TOK_PTR32); } +"__ptr64" { return MSC_Keyword(TOK_PTR64); } %{ /* -"__stdcall" { return MSC_Keyword(TOK_STDCALL, yyscanner); } -"__fastcall" { return MSC_Keyword(TOK_FASTCALL, yyscanner); } -"__clrcall" { return MSC_Keyword(TOK_CLRCALL, yyscanner); } +"__stdcall" { return MSC_Keyword(TOK_STDCALL); } +"__fastcall" { return MSC_Keyword(TOK_FASTCALL); } +"__clrcall" { return MSC_Keyword(TOK_CLRCALL); } */ %} @@ -657,7 +663,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_COMPLEX; } else - return make_identifier(yyscanner); + return make_identifier(); } "__real__" | @@ -666,7 +672,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_REAL; } else - return make_identifier(yyscanner); + return make_identifier(); } "__imag__" | @@ -675,7 +681,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_IMAG; } else - return make_identifier(yyscanner); + return make_identifier(); } %{ @@ -686,7 +692,7 @@ enable_or_disable ("enable"|"disable") "_var_arg_typeof" { if(PARSER.mode==configt::ansi_ct::flavourt::CODEWARRIOR) { loc(); return TOK_CW_VAR_ARG_TYPEOF; } else - return make_identifier(yyscanner); + return make_identifier(); } "__builtin_va_arg" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || @@ -694,7 +700,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_BUILTIN_VA_ARG; } else - return make_identifier(yyscanner); + return make_identifier(); } "__builtin_offsetof" | @@ -704,7 +710,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_OFFSETOF; } else - return make_identifier(yyscanner); + return make_identifier(); } "__builtin_types_compatible_p" { @@ -713,7 +719,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_GCC_BUILTIN_TYPES_COMPATIBLE_P; } else - return make_identifier(yyscanner); + return make_identifier(); } "__builtin_convertvector" { @@ -721,7 +727,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::CLANG) { loc(); return TOK_CLANG_BUILTIN_CONVERTVECTOR; } else - return make_identifier(yyscanner); + return make_identifier(); } "__alignof__" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || @@ -729,7 +735,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_ALIGNOF; } else - return make_identifier(yyscanner); + return make_identifier(); } "__alignof" { // MS supports __alignof: @@ -740,13 +746,13 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_ALIGNOF; } else - return make_identifier(yyscanner); + return make_identifier(); } "__ALIGNOF__" { if(PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_ALIGNOF; } else - return make_identifier(yyscanner); + return make_identifier(); } "__builtin_alignof" { @@ -756,7 +762,7 @@ enable_or_disable ("enable"|"disable") PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_ALIGNOF; } else - return make_identifier(yyscanner); + return make_identifier(); } "__asm" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) @@ -787,7 +793,7 @@ enable_or_disable ("enable"|"disable") BEGIN(GCC_ASM); } else - return make_identifier(yyscanner); + return make_identifier(); } "__asm__" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || @@ -804,71 +810,71 @@ enable_or_disable ("enable"|"disable") BEGIN(GCC_ASM); } else - return make_identifier(yyscanner); + return make_identifier(); } "__based" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { loc(); return TOK_MSC_BASED; } else - return make_identifier(yyscanner); + return make_identifier(); } "__unaligned" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { /* ignore for now */ } else - return make_identifier(yyscanner); + return make_identifier(); } "__wchar_t" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { loc(); return TOK_WCHAR_T; } else - return make_identifier(yyscanner); + return make_identifier(); } %{ /* C++ Keywords and Operators */ %} -alignas { return cpp11_keyword(TOK_ALIGNAS, yyscanner); } // C++11 -alignof { return cpp11_keyword(TOK_ALIGNOF, yyscanner); } // C++11 -and { return cpp98_keyword(TOK_ANDAND, yyscanner); } -and_eq { return cpp98_keyword(TOK_ANDASSIGN, yyscanner); } -bool { return cpp98_keyword(TOK_BOOL, yyscanner); } -catch { return cpp98_keyword(TOK_CATCH, yyscanner); } +alignas { return cpp11_keyword(TOK_ALIGNAS); } // C++11 +alignof { return cpp11_keyword(TOK_ALIGNOF); } // C++11 +and { return cpp98_keyword(TOK_ANDAND); } +and_eq { return cpp98_keyword(TOK_ANDASSIGN); } +bool { return cpp98_keyword(TOK_BOOL); } +catch { return cpp98_keyword(TOK_CATCH); } char16_t { // C++11, but Visual Studio uses typedefs if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO) - return make_identifier(yyscanner); + return make_identifier(); else - return cpp11_keyword(TOK_CHAR16_T, yyscanner); + return cpp11_keyword(TOK_CHAR16_T); } char32_t { // C++11, but Visual Studio uses typedefs if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO) - return make_identifier(yyscanner); + return make_identifier(); else - return cpp11_keyword(TOK_CHAR32_T, yyscanner); + return cpp11_keyword(TOK_CHAR32_T); } -class { return cpp98_keyword(TOK_CLASS, yyscanner); } -compl { return cpp98_keyword('~', yyscanner); } -constexpr { return cpp11_keyword(TOK_CONSTEXPR, yyscanner); } // C++11 -delete { return cpp98_keyword(TOK_DELETE, yyscanner); } -decltype { return cpp11_keyword(TOK_DECLTYPE, yyscanner); } // C++11 -explicit { return cpp98_keyword(TOK_EXPLICIT, yyscanner); } -false { return cpp98_keyword(TOK_FALSE, yyscanner); } -friend { return cpp98_keyword(TOK_FRIEND, yyscanner); } -mutable { return cpp98_keyword(TOK_MUTABLE, yyscanner); } -namespace { return cpp98_keyword(TOK_NAMESPACE, yyscanner); } -new { return cpp98_keyword(TOK_NEW, yyscanner); } -noexcept { return cpp11_keyword(TOK_NOEXCEPT, yyscanner); } // C++11 -noreturn { return cpp11_keyword(TOK_NORETURN, yyscanner); } // C++11 -not { return cpp98_keyword('!', yyscanner); } -not_eq { return cpp98_keyword(TOK_NE, yyscanner); } -nullptr { return cpp11_keyword(TOK_NULLPTR, yyscanner); } // C++11 -operator { return cpp98_keyword(TOK_OPERATOR, yyscanner); } -or { return cpp98_keyword(TOK_OROR, yyscanner); } -or_eq { return cpp98_keyword(TOK_ORASSIGN, yyscanner); } -private { return cpp98_keyword(TOK_PRIVATE, yyscanner); } -protected { return cpp98_keyword(TOK_PROTECTED, yyscanner); } -public { return cpp98_keyword(TOK_PUBLIC, yyscanner); } +class { return cpp98_keyword(TOK_CLASS); } +compl { return cpp98_keyword('~'); } +constexpr { return cpp11_keyword(TOK_CONSTEXPR); } // C++11 +delete { return cpp98_keyword(TOK_DELETE); } +decltype { return cpp11_keyword(TOK_DECLTYPE); } // C++11 +explicit { return cpp98_keyword(TOK_EXPLICIT); } +false { return cpp98_keyword(TOK_FALSE); } +friend { return cpp98_keyword(TOK_FRIEND); } +mutable { return cpp98_keyword(TOK_MUTABLE); } +namespace { return cpp98_keyword(TOK_NAMESPACE); } +new { return cpp98_keyword(TOK_NEW); } +noexcept { return cpp11_keyword(TOK_NOEXCEPT); } // C++11 +noreturn { return cpp11_keyword(TOK_NORETURN); } // C++11 +not { return cpp98_keyword('!'); } +not_eq { return cpp98_keyword(TOK_NE); } +nullptr { return cpp11_keyword(TOK_NULLPTR); } // C++11 +operator { return cpp98_keyword(TOK_OPERATOR); } +or { return cpp98_keyword(TOK_OROR); } +or_eq { return cpp98_keyword(TOK_ORASSIGN); } +private { return cpp98_keyword(TOK_PRIVATE); } +protected { return cpp98_keyword(TOK_PROTECTED); } +public { return cpp98_keyword(TOK_PUBLIC); } static_assert { // C++11, but Visual Studio supports it in all modes (and // doesn't support _Static_assert) if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO) @@ -876,30 +882,30 @@ static_assert { // C++11, but Visual Studio supports it in all modes (and loc(); return TOK_STATIC_ASSERT; } else - return cpp11_keyword(TOK_STATIC_ASSERT, yyscanner); + return cpp11_keyword(TOK_STATIC_ASSERT); } -template { return cpp98_keyword(TOK_TEMPLATE, yyscanner); } -this { return cpp98_keyword(TOK_THIS, yyscanner); } -thread_local { return cpp11_keyword(TOK_THREAD_LOCAL, yyscanner); } // C++11 -throw { return cpp98_keyword(TOK_THROW, yyscanner); } -true { return cpp98_keyword(TOK_TRUE, yyscanner); } -typeid { return cpp98_keyword(TOK_TYPEID, yyscanner); } -typename { return cpp98_keyword(TOK_TYPENAME, yyscanner); } -using { return cpp98_keyword(TOK_USING, yyscanner); } -virtual { return cpp98_keyword(TOK_VIRTUAL, yyscanner); } +template { return cpp98_keyword(TOK_TEMPLATE); } +this { return cpp98_keyword(TOK_THIS); } +thread_local { return cpp11_keyword(TOK_THREAD_LOCAL); } // C++11 +throw { return cpp98_keyword(TOK_THROW); } +true { return cpp98_keyword(TOK_TRUE); } +typeid { return cpp98_keyword(TOK_TYPEID); } +typename { return cpp98_keyword(TOK_TYPENAME); } +using { return cpp98_keyword(TOK_USING); } +virtual { return cpp98_keyword(TOK_VIRTUAL); } wchar_t { // CodeWarrior doesn't have wchar_t built in, // and MSC has a command-line option to turn it off if(PARSER.mode==configt::ansi_ct::flavourt::CODEWARRIOR) - return make_identifier(yyscanner); + return make_identifier(); else - return cpp98_keyword(TOK_WCHAR_T, yyscanner); + return cpp98_keyword(TOK_WCHAR_T); } -xor { return cpp98_keyword('^', yyscanner); } -xor_eq { return cpp98_keyword(TOK_XORASSIGN, yyscanner); } -".*" { return cpp_operator(TOK_DOTPM, yyscanner); } -"->*" { return cpp_operator(TOK_ARROWPM, yyscanner); } +xor { return cpp98_keyword('^'); } +xor_eq { return cpp98_keyword(TOK_XORASSIGN); } +".*" { return cpp_operator(TOK_DOTPM); } +"->*" { return cpp_operator(TOK_ARROWPM); } "::" { if(PARSER.cpp98) - return cpp_operator(TOK_SCOPE, yyscanner); + return cpp_operator(TOK_SCOPE); else { yyless(1); // puts all but one : back into stream @@ -912,9 +918,9 @@ xor_eq { return cpp98_keyword(TOK_XORASSIGN, yyscanner); } __decltype { if(PARSER.cpp98 && (PARSER.mode==configt::ansi_ct::flavourt::GCC || PARSER.mode==configt::ansi_ct::flavourt::CLANG)) - return cpp98_keyword(TOK_DECLTYPE, yyscanner); + return cpp98_keyword(TOK_DECLTYPE); else - return make_identifier(yyscanner); + return make_identifier(); } %{ @@ -924,38 +930,38 @@ __decltype { if(PARSER.cpp98 && http://clang.llvm.org/docs/LanguageExtensions.html#checks-for-type-trait-primitives */ %} -"__has_assign" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_copy" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_finalizer" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_nothrow_assign" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_nothrow_constructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_nothrow_copy" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_trivial_assign" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_trivial_constructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_trivial_copy" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_trivial_destructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_user_destructor" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__has_virtual_destructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_abstract" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_base_of" { loc(); return cpp98_keyword(TOK_BINARY_TYPE_PREDICATE, yyscanner); } -"__is_class" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_convertible_to" { loc(); return cpp98_keyword(TOK_BINARY_TYPE_PREDICATE, yyscanner); } -"__is_delegate" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_empty" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_enum" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_interface_class" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_pod" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_polymorphic" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_ref_array" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_ref_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_sealed" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_simple_value_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_union" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } -"__is_value_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE, yyscanner); } - -"__if_exists" { loc(); return MSC_cpp_keyword(TOK_MSC_IF_EXISTS, yyscanner); } -"__if_not_exists" { loc(); return MSC_cpp_keyword(TOK_MSC_IF_NOT_EXISTS, yyscanner); } -"__underlying_type" { loc(); return cpp98_keyword(TOK_UNDERLYING_TYPE, yyscanner); } +"__has_assign" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_copy" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_finalizer" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_nothrow_assign" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_nothrow_constructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_nothrow_copy" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_trivial_assign" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_trivial_constructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_trivial_copy" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_trivial_destructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_user_destructor" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__has_virtual_destructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_abstract" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_base_of" { loc(); return cpp98_keyword(TOK_BINARY_TYPE_PREDICATE); } +"__is_class" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_convertible_to" { loc(); return cpp98_keyword(TOK_BINARY_TYPE_PREDICATE); } +"__is_delegate" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_empty" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_enum" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_interface_class" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_pod" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_polymorphic" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_ref_array" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_ref_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_sealed" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_simple_value_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_union" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); } +"__is_value_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); } + +"__if_exists" { loc(); return MSC_cpp_keyword(TOK_MSC_IF_EXISTS); } +"__if_not_exists" { loc(); return MSC_cpp_keyword(TOK_MSC_IF_NOT_EXISTS); } +"__underlying_type" { loc(); return cpp98_keyword(TOK_UNDERLYING_TYPE); } "["{ws}"repeatable" | "["{ws}"source_annotation_attribute" | @@ -980,30 +986,30 @@ __decltype { if(PARSER.cpp98 && "__char16_t" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || PARSER.mode==configt::ansi_ct::flavourt::CLANG) - return cpp98_keyword(TOK_CHAR16_T, yyscanner); // GNU extension + return cpp98_keyword(TOK_CHAR16_T); // GNU extension else - return make_identifier(yyscanner); + return make_identifier(); } "__nullptr" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || PARSER.mode==configt::ansi_ct::flavourt::CLANG) - return cpp98_keyword(TOK_NULLPTR, yyscanner); // GNU extension + return cpp98_keyword(TOK_NULLPTR); // GNU extension else - return make_identifier(yyscanner); + return make_identifier(); } "__null" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || PARSER.mode==configt::ansi_ct::flavourt::CLANG) - return cpp98_keyword(TOK_NULLPTR, yyscanner); // GNU extension + return cpp98_keyword(TOK_NULLPTR); // GNU extension else - return make_identifier(yyscanner); + return make_identifier(); } "__char32_t" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || PARSER.mode==configt::ansi_ct::flavourt::CLANG) - return cpp98_keyword(TOK_CHAR32_T, yyscanner); // GNU extension + return cpp98_keyword(TOK_CHAR32_T); // GNU extension else - return make_identifier(yyscanner); + return make_identifier(); } "__declspec" | @@ -1024,7 +1030,7 @@ __decltype { if(PARSER.cpp98 && loc(); return TOK_MSC_DECLSPEC; } else - return make_identifier(yyscanner); + return make_identifier(); } "__pragma" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) @@ -1033,7 +1039,7 @@ __decltype { if(PARSER.cpp98 && PARSER.parenthesis_counter=0; } else - return make_identifier(yyscanner); + return make_identifier(); } "__attribute__" | @@ -1047,7 +1053,7 @@ __decltype { if(PARSER.cpp98 && return TOK_GCC_ATTRIBUTE; } else - return make_identifier(yyscanner); + return make_identifier(); } "__aligned" { /* ignore */ } @@ -1085,7 +1091,7 @@ __decltype { if(PARSER.cpp98 && // ignore } else - return make_identifier(yyscanner); + return make_identifier(); } "__align" { /* an ARM extension */ @@ -1095,7 +1101,7 @@ __decltype { if(PARSER.cpp98 && PARSER.parenthesis_counter=0; } else - return make_identifier(yyscanner); + return make_identifier(); } "__smc" { /* an ARM extension */ @@ -1105,7 +1111,7 @@ __decltype { if(PARSER.cpp98 && PARSER.parenthesis_counter=0; } else - return make_identifier(yyscanner); + return make_identifier(); } "__INTADDR__" { /* an ARM extension */ @@ -1114,7 +1120,7 @@ __decltype { if(PARSER.cpp98 && // ignore } else - return make_identifier(yyscanner); + return make_identifier(); } "__irq" { /* an ARM extension */ @@ -1123,7 +1129,7 @@ __decltype { if(PARSER.cpp98 && // ignore } else - return make_identifier(yyscanner); + return make_identifier(); } "__packed" { /* an ARM extension */ @@ -1132,7 +1138,7 @@ __decltype { if(PARSER.cpp98 && // ignore } else - return make_identifier(yyscanner); + return make_identifier(); } "__value_in_regs" { /* an ARM extension */ @@ -1141,7 +1147,7 @@ __decltype { if(PARSER.cpp98 && // ignore } else - return make_identifier(yyscanner); + return make_identifier(); } "__weak" { /* an ARM extension */ @@ -1150,7 +1156,7 @@ __decltype { if(PARSER.cpp98 && // ignore } else - return make_identifier(yyscanner); + return make_identifier(); } "__writeonly" { /* an ARM extension */ @@ -1159,7 +1165,7 @@ __decltype { if(PARSER.cpp98 && // ignore } else - return make_identifier(yyscanner); + return make_identifier(); } "__global_reg" { /* an ARM extension */ @@ -1169,7 +1175,7 @@ __decltype { if(PARSER.cpp98 && PARSER.parenthesis_counter=0; } else - return make_identifier(yyscanner); + return make_identifier(); } "__svc" { /* an ARM extension */ @@ -1179,7 +1185,7 @@ __decltype { if(PARSER.cpp98 && PARSER.parenthesis_counter=0; } else - return make_identifier(yyscanner); + return make_identifier(); } "__svc_indirect" { /* an ARM extension */ @@ -1189,7 +1195,7 @@ __decltype { if(PARSER.cpp98 && PARSER.parenthesis_counter=0; } else - return make_identifier(yyscanner); + return make_identifier(); } "__svc_indirect_r7" { /* an ARM extension */ @@ -1199,7 +1205,7 @@ __decltype { if(PARSER.cpp98 && PARSER.parenthesis_counter=0; } else - return make_identifier(yyscanner); + return make_identifier(); } "__softfp" { /* an ARM extension */ @@ -1208,7 +1214,7 @@ __decltype { if(PARSER.cpp98 && // ignore } else - return make_identifier(yyscanner); + return make_identifier(); } "typeof" { if(PARSER.cpp98 || @@ -1218,14 +1224,14 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_TYPEOF; } else - return make_identifier(yyscanner); + return make_identifier(); } "__typeof" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || PARSER.mode==configt::ansi_ct::flavourt::CLANG || PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_TYPEOF; } else - return make_identifier(yyscanner); + return make_identifier(); } "__typeof__" { loc(); return TOK_TYPEOF; } @@ -1234,14 +1240,14 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_MSC_FORCEINLINE; } else - return make_identifier(yyscanner); + return make_identifier(); } "_inline" { // http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { loc(); return TOK_INLINE; } else - return make_identifier(yyscanner); + return make_identifier(); } "__inline" { loc(); return TOK_INLINE; } @@ -1252,37 +1258,37 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_GCC_LABEL; } else - return make_identifier(yyscanner); + return make_identifier(); } "__try" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { loc(); return TOK_MSC_TRY; } else - return make_identifier(yyscanner); + return make_identifier(); } "try" { if(PARSER.cpp98) // C++? { loc(); return TOK_TRY; } else - return make_identifier(yyscanner); + return make_identifier(); } "__finally" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { loc(); return TOK_MSC_FINALLY; } else - return make_identifier(yyscanner); + return make_identifier(); } "__except" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { loc(); return TOK_MSC_EXCEPT; } else - return make_identifier(yyscanner); + return make_identifier(); } "__leave" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO) { loc(); return TOK_MSC_LEAVE; } else - return make_identifier(yyscanner); + return make_identifier(); } {CPROVER_PREFIX}"atomic" { loc(); return TOK_CPROVER_ATOMIC; } @@ -1384,7 +1390,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM) { loc(); return TOK_THREAD_LOCAL; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a C11 keyword */ @@ -1395,7 +1401,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM)) { loc(); return TOK_ALIGNAS; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a C11 keyword */ @@ -1407,7 +1413,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)) { loc(); return TOK_ALIGNOF; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a C11 keyword. It can be used as a type qualifier @@ -1428,7 +1434,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM)) { loc(); return TOK_ATOMIC_TYPE_SPECIFIER; } else - return make_identifier(yyscanner); + return make_identifier(); } "_Atomic" { if(!PARSER.cpp98 && @@ -1437,7 +1443,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM)) { loc(); return TOK_ATOMIC_TYPE_QUALIFIER; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a C11 keyword */ @@ -1448,7 +1454,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM)) { loc(); return TOK_GENERIC; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a C11 keyword */ @@ -1459,7 +1465,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM)) { loc(); return TOK_IMAGINARY; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a C11 keyword */ @@ -1470,7 +1476,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM)) { loc(); return TOK_NORETURN; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a C11 keyword */ @@ -1481,7 +1487,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM)) { loc(); return TOK_STATIC_ASSERT; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a C11 keyword */ @@ -1492,7 +1498,7 @@ __decltype { if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::ARM)) { loc(); return TOK_THREAD_LOCAL; } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a clang extension */ @@ -1500,7 +1506,7 @@ __decltype { if(PARSER.cpp98 && "_Nullable" { if(PARSER.mode==configt::ansi_ct::flavourt::CLANG) { /* ignore */ } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a clang extension */ @@ -1508,7 +1514,7 @@ __decltype { if(PARSER.cpp98 && "_Nonnull" { if(PARSER.mode==configt::ansi_ct::flavourt::CLANG) { /* ignore */ } else - return make_identifier(yyscanner); + return make_identifier(); } /* This is a clang extension */ @@ -1516,7 +1522,7 @@ __decltype { if(PARSER.cpp98 && "_Null_unspecified" { if(PARSER.mode==configt::ansi_ct::flavourt::CLANG) { /* ignore */ } else - return make_identifier(yyscanner); + return make_identifier(); } } @@ -1557,7 +1563,7 @@ __decltype { if(PARSER.cpp98 && { -{identifier} { return make_identifier(yyscanner); } +{identifier} { return make_identifier(); } {integer_s} { newstack(yyansi_clval); parser_stack(yyansi_clval)=convert_integer_literal(yytext); @@ -1568,10 +1574,7 @@ __decltype { if(PARSER.cpp98 && {clang_ext_float_s} { if(PARSER.mode!=configt::ansi_ct::flavourt::GCC && PARSER.mode != configt::ansi_ct::flavourt::CLANG) { - yyansi_cerror( - PARSER, - yyscanner, - "Floating-point constant with unsupported extension"); + yyansi_cerror("Floating-point constant with unsupported extension"); return TOK_SCANNER_ERROR; } newstack(yyansi_clval); @@ -1582,10 +1585,7 @@ __decltype { if(PARSER.cpp98 && {gcc_ext_float_s} { if(PARSER.mode!=configt::ansi_ct::flavourt::GCC) { - yyansi_cerror( - PARSER, - yyscanner, - "Floating-point constant with unsupported extension"); + yyansi_cerror("Floating-point constant with unsupported extension"); return TOK_SCANNER_ERROR; } newstack(yyansi_clval); @@ -1796,7 +1796,7 @@ __decltype { if(PARSER.cpp98 && } {ws} { /* ignore */ } {newline} { /* ignore */ } -{identifier} { return make_identifier(yyscanner); } +{identifier} { return make_identifier(); } . { loc(); return yytext[0]; } } diff --git a/src/cpp/cpp_token_buffer.cpp b/src/cpp/cpp_token_buffer.cpp index cc1696286b4..d5c97e731d4 100644 --- a/src/cpp/cpp_token_buffer.cpp +++ b/src/cpp/cpp_token_buffer.cpp @@ -65,8 +65,8 @@ int cpp_token_buffert::LookAhead(unsigned offset, cpp_tokent &token) return token.kind; } -int yyansi_clex(void *); -char *yyansi_cget_text(void *); +int yyansi_clex(); +extern char *yyansi_ctext; void cpp_token_buffert::read_token() { @@ -76,8 +76,8 @@ void cpp_token_buffert::read_token() int kind; ansi_c_parser.stack.clear(); - kind = yyansi_clex(ansi_c_scanner_state); - tokens.back().text = yyansi_cget_text(ansi_c_scanner_state); + kind = yyansi_clex(); + tokens.back().text = yyansi_ctext; if(ansi_c_parser.stack.size()==1) { tokens.back().data=ansi_c_parser.stack.front(); diff --git a/src/cpp/cpp_token_buffer.h b/src/cpp/cpp_token_buffer.h index aaa831bca98..0721c85878d 100644 --- a/src/cpp/cpp_token_buffer.h +++ b/src/cpp/cpp_token_buffer.h @@ -21,10 +21,6 @@ Author: Daniel Kroening, kroening@cs.cmu.edu #include -int yyansi_clex_init_extra(ansi_c_parsert *, void **); -int yyansi_clex_destroy(void *); -int yyansi_cparse(ansi_c_parsert &, void *); - class cpp_token_buffert { public: @@ -39,13 +35,7 @@ class cpp_token_buffert config.cpp.cpp_standard == configt::cppt::cpp_standardt::CPP17; ansi_c_parser.ts_18661_3_Floatn_types = false; ansi_c_parser.mode = config.ansi_c.mode; - - yyansi_clex_init_extra(&ansi_c_parser, &ansi_c_scanner_state); - } - - ~cpp_token_buffert() - { - yyansi_clex_destroy(ansi_c_scanner_state); + ansi_c_scanner_init(ansi_c_parser); } typedef unsigned int post; diff --git a/src/goto-instrument/contracts/contracts_wrangler.cpp b/src/goto-instrument/contracts/contracts_wrangler.cpp index 5d3b8fb04a6..36c8bb117a8 100644 --- a/src/goto-instrument/contracts/contracts_wrangler.cpp +++ b/src/goto-instrument/contracts/contracts_wrangler.cpp @@ -150,6 +150,7 @@ void contracts_wranglert::mangle( ansi_c_parser.cpp98 = false; // it's not C++ ansi_c_parser.cpp11 = false; // it's not C++ ansi_c_parser.mode = config.ansi_c.mode; + ansi_c_scanner_init(ansi_c_parser); ansi_c_parser.parse(); // Extract the invariants from prase_tree.