Fix compile warnings

This commit is contained in:
Max Brunsfeld 2017-07-12 22:08:36 -07:00
parent 62c577af33
commit 7293e6f0cc
6 changed files with 51 additions and 55 deletions

View file

@ -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<size_t>(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<size_t>(symbol.index)) {
bits.resize(symbol.index + 1);
}
if (!bits[symbol.index]) {

View file

@ -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;
}
}

View file

@ -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];

View file

@ -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);

View file

@ -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(

View file

@ -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);