diff --git a/src/compiler/build_tables/lookahead_set.cc b/src/compiler/build_tables/lookahead_set.cc index 443ba0cd..7b33cca2 100644 --- a/src/compiler/build_tables/lookahead_set.cc +++ b/src/compiler/build_tables/lookahead_set.cc @@ -29,7 +29,7 @@ bool LookaheadSet::operator==(const LookaheadSet &other) const { bool LookaheadSet::contains(const Symbol &symbol) const { if (symbol == rules::END_OF_INPUT()) return eof; auto &bits = symbol.is_external() ? external_bits : terminal_bits; - return bits.size() > symbol.index && bits[symbol.index]; + return bits.size() > static_cast(symbol.index) && bits[symbol.index]; } size_t LookaheadSet::size() const { @@ -95,7 +95,7 @@ bool LookaheadSet::insert(const Symbol &symbol) { } auto &bits = symbol.is_external() ? external_bits : terminal_bits; - if (bits.size() <= symbol.index) { + if (bits.size() <= static_cast(symbol.index)) { bits.resize(symbol.index + 1); } if (!bits[symbol.index]) { diff --git a/src/runtime/stack.c b/src/runtime/stack.c index 6bb59095..92e90661 100644 --- a/src/runtime/stack.c +++ b/src/runtime/stack.c @@ -86,15 +86,14 @@ recur: self->ref_count--; if (self->ref_count > 0) return; - StackNode *last_predecessor = NULL; + StackNode *first_predecessor = NULL; if (self->link_count > 0) { - unsigned i = 0; - for (; i < self->link_count - 1; i++) { + for (unsigned i = self->link_count - 1; i > 0; i--) { if (self->links[i].tree) ts_tree_release(self->links[i].tree); stack_node_release(self->links[i].node, pool); } - if (self->links[i].tree) ts_tree_release(self->links[i].tree); - last_predecessor = self->links[i].node; + if (self->links[0].tree) ts_tree_release(self->links[0].tree); + first_predecessor = self->links[0].node; } if (pool->size < MAX_NODE_POOL_SIZE) { @@ -103,8 +102,8 @@ recur: ts_free(self); } - if (last_predecessor) { - self = last_predecessor; + if (first_predecessor) { + self = first_predecessor; goto recur; } } diff --git a/test/compiler/build_tables/parse_item_set_builder_test.cc b/test/compiler/build_tables/parse_item_set_builder_test.cc index 2884c523..4e2b28e6 100644 --- a/test/compiler/build_tables/parse_item_set_builder_test.cc +++ b/test/compiler/build_tables/parse_item_set_builder_test.cc @@ -46,7 +46,7 @@ describe("ParseItemSetBuilder", []() { {Symbol::terminal(15), 0, AssociativityNone}, }, 0} }}, - }, {}, {}, {}}; + }, {}, {}, {}, {}}; auto production = [&](int variable_index, int production_index) -> const Production & { return grammar.variables[variable_index].productions[production_index]; @@ -97,7 +97,7 @@ describe("ParseItemSetBuilder", []() { }, 0}, Production{{}, 0} }}, - }, {}, {}, {}}; + }, {}, {}, {}, {}}; auto production = [&](int variable_index, int production_index) -> const Production & { return grammar.variables[variable_index].productions[production_index]; diff --git a/test/compiler/prepare_grammar/expand_repeats_test.cc b/test/compiler/prepare_grammar/expand_repeats_test.cc index 244e5c5f..87c8b879 100644 --- a/test/compiler/prepare_grammar/expand_repeats_test.cc +++ b/test/compiler/prepare_grammar/expand_repeats_test.cc @@ -15,7 +15,7 @@ describe("expand_repeats", []() { { Variable{"rule0", VariableTypeNamed, Repeat{Symbol::terminal(0)}}, }, - {}, {}, {} + {}, {}, {}, {} }; auto result = expand_repeats(grammar); @@ -37,7 +37,7 @@ describe("expand_repeats", []() { Repeat{Symbol::terminal(11)}, })}, }, - {}, {}, {} + {}, {}, {}, {} }; auto result = expand_repeats(grammar); @@ -62,7 +62,7 @@ describe("expand_repeats", []() { Repeat{Symbol::terminal(11)} })}, }, - {}, {}, {} + {}, {}, {}, {} }; auto result = expand_repeats(grammar); @@ -91,7 +91,7 @@ describe("expand_repeats", []() { Repeat{Symbol::terminal(4)} })}, }, - {}, {}, {} + {}, {}, {}, {} }; auto result = expand_repeats(grammar); @@ -120,7 +120,7 @@ describe("expand_repeats", []() { Repeat{Symbol::terminal(11)}, })}, }, - {}, {}, {} + {}, {}, {}, {} }; auto result = expand_repeats(grammar); @@ -147,7 +147,7 @@ describe("expand_repeats", []() { Variable{"rule0", VariableTypeNamed, Repeat{Symbol::terminal(10)}}, Variable{"rule1", VariableTypeNamed, Repeat{Symbol::terminal(11)}}, }, - {}, {}, {} + {}, {}, {}, {} }; auto result = expand_repeats(grammar); diff --git a/test/compiler/prepare_grammar/extract_tokens_test.cc b/test/compiler/prepare_grammar/extract_tokens_test.cc index e720ec3c..2e515e89 100644 --- a/test/compiler/prepare_grammar/extract_tokens_test.cc +++ b/test/compiler/prepare_grammar/extract_tokens_test.cc @@ -48,9 +48,7 @@ describe("extract_tokens", []() { Repeat{Symbol::non_terminal(3)} }, }, - {}, - {}, - {} + {}, {}, {}, {} }); InitialSyntaxGrammar &syntax_grammar = get<0>(result); @@ -158,9 +156,7 @@ describe("extract_tokens", []() { }) }, }, - {}, - {}, - {} + {}, {}, {}, {} }); InitialSyntaxGrammar &syntax_grammar = get<0>(result); @@ -189,23 +185,26 @@ describe("extract_tokens", []() { }); it("does not move entire rules into the lexical grammar if their content is used elsewhere in the grammar", [&]() { - auto result = extract_tokens(InternedGrammar{{ - Variable{ - "rule_A", - VariableTypeNamed, - Rule::seq({ Symbol::non_terminal(1), String{"ab"} }) + auto result = extract_tokens(InternedGrammar{ + { + Variable{ + "rule_A", + VariableTypeNamed, + Rule::seq({ Symbol::non_terminal(1), String{"ab"} }) + }, + Variable{ + "rule_B", + VariableTypeNamed, + String{"cd"} + }, + Variable{ + "rule_C", + VariableTypeNamed, + Rule::seq({ String{"ef"}, String{"cd"} }) + }, }, - Variable{ - "rule_B", - VariableTypeNamed, - String{"cd"} - }, - Variable{ - "rule_C", - VariableTypeNamed, - Rule::seq({ String{"ef"}, String{"cd"} }) - }, - }, {}, {}, {}}); + {}, {}, {}, {} + }); InitialSyntaxGrammar &syntax_grammar = get<0>(result); LexicalGrammar &lexical_grammar = get<1>(result); @@ -275,7 +274,7 @@ describe("extract_tokens", []() { { { Symbol::non_terminal(1), Symbol::non_terminal(2) } }, - {} + {}, {} }); InitialSyntaxGrammar &syntax_grammar = get<0>(result); @@ -296,8 +295,7 @@ describe("extract_tokens", []() { String{"y"}, Pattern{" "}, }, - {}, - {} + {}, {}, {} }); AssertThat(get<2>(result), Equals(CompileError::none())); @@ -318,8 +316,7 @@ describe("extract_tokens", []() { { String{"y"}, }, - {}, - {} + {}, {}, {} }); AssertThat(get<2>(result), Equals(CompileError::none())); @@ -349,8 +346,7 @@ describe("extract_tokens", []() { { Symbol::non_terminal(2), }, - {}, - {} + {}, {}, {} }); AssertThat(get<2>(result), Equals(CompileError::none())); @@ -379,8 +375,7 @@ describe("extract_tokens", []() { { Symbol::non_terminal(1) }, - {}, - {} + {}, {}, {} }); AssertThat(get<2>(result), Equals(CompileError( @@ -398,8 +393,7 @@ describe("extract_tokens", []() { { Rule::choice({ Symbol::non_terminal(1), Blank{} }) }, - {}, - {} + {}, {}, {} }); AssertThat(get<2>(result), Equals(CompileError( @@ -427,7 +421,8 @@ describe("extract_tokens", []() { {}, { Variable{"rule_A", VariableTypeNamed, Symbol::non_terminal(0)} - } + }, + {} }); AssertThat(get<2>(result), Equals(CompileError( diff --git a/test/compiler/prepare_grammar/intern_symbols_test.cc b/test/compiler/prepare_grammar/intern_symbols_test.cc index a0097544..22944f53 100644 --- a/test/compiler/prepare_grammar/intern_symbols_test.cc +++ b/test/compiler/prepare_grammar/intern_symbols_test.cc @@ -16,7 +16,8 @@ describe("intern_symbols", []() { {"x", VariableTypeNamed, Rule::choice({ NamedSymbol{"y"}, NamedSymbol{"_z"} })}, {"y", VariableTypeNamed, NamedSymbol{"_z"}}, {"_z", VariableTypeNamed, String{"stuff"}} - }, {}, {}, {} + }, + {}, {}, {}, {} }; auto result = intern_symbols(grammar); @@ -35,7 +36,7 @@ describe("intern_symbols", []() { { {"x", VariableTypeNamed, NamedSymbol{"y"}}, }, - {}, {}, {} + {}, {}, {}, {} }; auto result = intern_symbols(grammar); @@ -54,7 +55,7 @@ describe("intern_symbols", []() { { NamedSymbol{"z"} }, - {}, {} + {}, {}, {} }; auto result = intern_symbols(grammar); @@ -84,7 +85,8 @@ describe("intern_symbols", []() { VariableTypeNamed, NamedSymbol{"z"} }, - } + }, + {} }; auto result = intern_symbols(grammar);