diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 26a9ae40..6e2f830a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -54,6 +54,25 @@ jobs: - run: flex --help - run: bundle install - run: bundle exec rspec + test-cpp: + needs: ruby-versions + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + ruby: ['head'] + compiler: ['g++', 'clang++'] + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: flex --help + - run: bundle install + - run: bundle exec rspec + env: + COMPILER: ${{ matrix.compiler }} test-memory: runs-on: ubuntu-20.04 strategy: diff --git a/sample/parse.y b/sample/parse.y index 2f6f238d..813a73aa 100644 --- a/sample/parse.y +++ b/sample/parse.y @@ -46,7 +46,7 @@ factor : number static enum yytokentype yylex(YYSTYPE *lval) { - return 0; + return (enum yytokentype)0; } static void yyerror(YYLTYPE *yylloc, const char *msg) diff --git a/spec/fixtures/integration/named_references.y b/spec/fixtures/integration/named_references.y index d7a1b601..80c1676a 100644 --- a/spec/fixtures/integration/named_references.y +++ b/spec/fixtures/integration/named_references.y @@ -1,14 +1,6 @@ %{ #include -typedef struct code_location { - int first_line; - int first_column; - int last_line; - int last_column; -} code_location_t; - -#define YYLTYPE code_location_t #define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ if (N) \ diff --git a/spec/fixtures/integration/typed_midrule_actions.y b/spec/fixtures/integration/typed_midrule_actions.y index 34a80517..435cc076 100644 --- a/spec/fixtures/integration/typed_midrule_actions.y +++ b/spec/fixtures/integration/typed_midrule_actions.y @@ -1,14 +1,6 @@ %{ #include -typedef struct code_location { - int first_line; - int first_column; - int last_line; - int last_column; -} code_location_t; - -#define YYLTYPE code_location_t #define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ if (N) \ diff --git a/spec/lrama/integration_spec.rb b/spec/lrama/integration_spec.rb index 7e91433e..59feb261 100644 --- a/spec/lrama/integration_spec.rb +++ b/spec/lrama/integration_spec.rb @@ -11,13 +11,21 @@ def exec_command(command) raise "#{command} failed." unless $?.success? end + def compiler + ENV['COMPILER'] || "gcc" + end + + def file_extension + ENV['COMPILER'] == "gcc" ? ".c" : ".cpp" + end + def test_parser(parser_name, input, expected, expect_success: true, lrama_command_args: [], debug: false) tmpdir = Dir.tmpdir grammar_file_path = fixture_path("integration/#{parser_name}.y") lexer_file_path = fixture_path("integration/#{parser_name}.l") - parser_c_path = tmpdir + "/#{parser_name}.c" + parser_c_path = tmpdir + "/#{parser_name}#{file_extension}" parser_h_path = tmpdir + "/#{parser_name}.h" - lexer_c_path = tmpdir + "/#{parser_name}-lexer.c" + lexer_c_path = tmpdir + "/#{parser_name}-lexer#{file_extension}" lexer_h_path = tmpdir + "/#{parser_name}-lexer.h" obj_path = tmpdir + "/#{parser_name}" @@ -29,7 +37,7 @@ def test_parser(parser_name, input, expected, expect_success: true, lrama_comman Lrama::Command.new.run(%W[-H#{parser_h_path} -o#{parser_c_path}] + lrama_command_args + %W[#{grammar_file_path}]) exec_command("flex --header-file=#{lexer_h_path} -o #{lexer_c_path} #{lexer_file_path}") - exec_command("gcc -Wall -ggdb3 -I#{tmpdir} #{parser_c_path} #{lexer_c_path} -o #{obj_path}") + exec_command("#{compiler} -Wall -ggdb3 -I#{tmpdir} #{parser_c_path} #{lexer_c_path} -o #{obj_path}") out = err = status = nil @@ -50,7 +58,7 @@ def test_parser(parser_name, input, expected, expect_success: true, lrama_comman def generate_object(grammar_file_path, c_path, obj_path, command_args: []) Lrama::Command.new.run(%W[-d -o #{c_path}] + command_args + %W[#{grammar_file_path}]) - exec_command("gcc -Wall #{c_path} -o #{obj_path}") + exec_command("#{compiler} -Wall #{c_path} -o #{obj_path}") end end @@ -262,7 +270,7 @@ def generate_object(grammar_file_path, c_path, obj_path, command_args: []) end describe "sample files" do - let(:c_path) { Dir.tmpdir + "/test.c" } + let(:c_path) { Dir.tmpdir + "/test#{file_extension}" } let(:obj_path) { Dir.tmpdir + "/test" } describe "calc.y" do diff --git a/template/bison/yacc.c b/template/bison/yacc.c index 353fb9de..6edd59a0 100644 --- a/template/bison/yacc.c +++ b/template/bison/yacc.c @@ -1166,9 +1166,9 @@ yydestruct (const char *yymsg, #endif enum yy_repair_type { - insert, - delete, - shift, + inserting, + deleting, + shifting, }; struct yy_repair { @@ -1401,27 +1401,27 @@ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar<%= output.user_formals if (current->repair_length + 1 > YYMAXREPAIR(<%= output.parse_param_name %>)) continue; - yy_repairs *new = (yy_repairs *) YYMALLOC (sizeof (yy_repairs)); - new->id = count; - new->next = 0; - new->stack_length = stack_length; - new->states = (yy_state_t *) YYMALLOC (sizeof (yy_state_t) * (stack_length)); - new->state = new->states + (current->state - current->states); - YYCOPY (new->states, current->states, current->state - current->states + 1); - new->repair_length = current->repair_length + 1; - new->prev_repair = current; - new->repair.type = insert; - new->repair.term = (yysymbol_kind_t) yyx; + yy_repairs *reps = (yy_repairs *) YYMALLOC (sizeof (yy_repairs)); + reps->id = count; + reps->next = 0; + reps->stack_length = stack_length; + reps->states = (yy_state_t *) YYMALLOC (sizeof (yy_state_t) * (stack_length)); + reps->state = reps->states + (current->state - current->states); + YYCOPY (reps->states, current->states, current->state - current->states + 1); + reps->repair_length = current->repair_length + 1; + reps->prev_repair = current; + reps->repair.type = inserting; + reps->repair.term = (yysymbol_kind_t) yyx; /* Process PDA assuming next token is yyx */ - if (! yy_process_repairs (new, yyx)) + if (! yy_process_repairs (reps, (yysymbol_kind_t)yyx)) { - YYFREE (new); + YYFREE (reps); continue; } - tail->next = new; - tail = new; + tail->next = reps; + tail = reps; count++; if (yyx == yytoken) @@ -1437,7 +1437,7 @@ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar<%= output.user_formals YYDPRINTF ((stderr, "New repairs is enqueued. count: %d, yystate: %d, yyx: %d\n", count, yystate, yyx)); - yy_print_repairs (new<%= output.user_args %>); + yy_print_repairs (reps<%= output.user_args %>); } } } @@ -1476,7 +1476,8 @@ int yychar; /* Default value used for initialization, for pacifying older GCCs or non-GCC compilers. */ #ifdef __cplusplus -static const YYSTYPE yyval_default = YY_INITIAL_VALUE(YYSTYPE()); +static const YYSTYPE yyval_default = {}; +(void) yyval_default; #else YY_INITIAL_VALUE (static const YYSTYPE yyval_default;) #endif