Skip to content
Snippets Groups Projects
Commit 0b0cd25e authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Fix AST construction for chained post incr/decr operators

Observe that instructions such as
``
a++ ++;
``
are not allowed, but this could generate a crash and not a clean error message
parent cbe794fb
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -99,14 +99,24 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary
n = std::move(unary_operator);
n->remove_content();
transform(n, st...);
} else if (n->children[1]->is<language::post_minusminus>() or n->children[1]->is<language::post_plusplus>()) {
n->remove_content();
auto expression = std::move(n->children[0]);
auto unary_operator = std::move(n->children[1]);
unary_operator->children.emplace_back(std::move(expression));
}
}
if (n->is<language::unary_expression>()) {
size_t child_nb = n->children.size();
if (child_nb > 1) {
if (n->children[child_nb - 1]->is<language::post_minusminus>() or
n->children[child_nb - 1]->is<language::post_plusplus>()) {
auto unary_operator = std::move(n->children[child_nb - 1]);
n->children.pop_back();
unary_operator->remove_content();
unary_operator->children.emplace_back(std::move(n));
n = std::move(unary_operator);
n->remove_content();
transform(n, st...);
transform(n->children[0], st...);
}
}
}
}
......@@ -203,8 +213,8 @@ struct ASTBuilder::simplify_stream_statement : parse_tree::apply<ASTBuilder::sim
};
template <typename Rule>
using selector =
parse_tree::selector<Rule,
using selector = parse_tree::selector<
Rule,
parse_tree::store_content::on<import_instruction,
module_name,
true_kw,
......@@ -233,7 +243,8 @@ using selector =
for_statement,
break_kw,
continue_kw>,
ASTBuilder::rearrange::on<logical_or, logical_and, bitwise_xor, equality, compare, sum, product, affectation, expression>,
ASTBuilder::rearrange::
on<logical_or, logical_and, bitwise_xor, equality, compare, sum, product, affectation, expression>,
ASTBuilder::simplify_unary::
on<unary_minus, unary_plus, unary_not, function_evaluation, type_expression, unary_expression>,
parse_tree::remove_content::on<plus_op,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment