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

Remove a bunch of useless remove_content

parent d70078dc
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -22,7 +22,6 @@ struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange> ...@@ -22,7 +22,6 @@ struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange>
} else { } else {
// First we rearrange tree // First we rearrange tree
{ {
n->remove_content();
auto& children = n->children; auto& children = n->children;
auto rhs = std::move(children.back()); auto rhs = std::move(children.back());
children.pop_back(); children.pop_back();
...@@ -39,7 +38,6 @@ struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange> ...@@ -39,7 +38,6 @@ struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange>
Assert(n->children.size() == 2); Assert(n->children.size() == 2);
auto& rhs = n->children[1]; auto& rhs = n->children[1];
if (rhs->is_type<language::unary_minus>()) { if (rhs->is_type<language::unary_minus>()) {
rhs->remove_content();
n->set_type<language::plus_op>(); n->set_type<language::plus_op>();
rhs = std::move(rhs->children[0]); rhs = std::move(rhs->children[0]);
} }
...@@ -47,7 +45,6 @@ struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange> ...@@ -47,7 +45,6 @@ struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange>
Assert(n->children.size() == 2); Assert(n->children.size() == 2);
auto& rhs = n->children[1]; auto& rhs = n->children[1];
if (rhs->is_type<language::unary_minus>()) { if (rhs->is_type<language::unary_minus>()) {
rhs->remove_content();
n->set_type<language::minus_op>(); n->set_type<language::minus_op>();
rhs = std::move(rhs->children[0]); rhs = std::move(rhs->children[0]);
} }
...@@ -65,40 +62,32 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary ...@@ -65,40 +62,32 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary
{ {
if (n->children.size() == 1) { if (n->children.size() == 1) {
if (n->is_type<unary_expression>() or n->is_type<type_expression>()) { if (n->is_type<unary_expression>() or n->is_type<type_expression>()) {
n->remove_content();
n = std::move(n->children.back()); n = std::move(n->children.back());
transform(n, st...); transform(n, st...);
} else if (n->is_type<unary_minus>()) { } else if (n->is_type<unary_minus>()) {
auto& child = n->children[0]; auto& child = n->children[0];
if (child->is_type<unary_minus>()) { if (child->is_type<unary_minus>()) {
n->remove_content();
child->remove_content();
n = std::move(child->children[0]); n = std::move(child->children[0]);
transform(n, st...); transform(n, st...);
} }
} else if (n->is_type<unary_not>()) { } else if (n->is_type<unary_not>()) {
auto& child = n->children[0]; auto& child = n->children[0];
if (child->is_type<unary_not>()) { if (child->is_type<unary_not>()) {
n->remove_content();
child->remove_content();
n = std::move(child->children[0]); n = std::move(child->children[0]);
transform(n, st...); transform(n, st...);
} }
} }
} else if (n->children.size() == 2) { } else if (n->children.size() == 2) {
if (n->children[0]->is_type<language::unary_plus>()) { if (n->children[0]->is_type<language::unary_plus>()) {
n->remove_content();
n = std::move(n->children[1]); n = std::move(n->children[1]);
transform(n, st...); transform(n, st...);
} else if (n->children[0]->is_type<language::unary_minus>() or n->children[0]->is_type<language::unary_not>() or } else if (n->children[0]->is_type<language::unary_minus>() or n->children[0]->is_type<language::unary_not>() or
n->children[0]->is_type<language::unary_minusminus>() or n->children[0]->is_type<language::unary_minusminus>() or
n->children[0]->is_type<language::unary_plusplus>()) { n->children[0]->is_type<language::unary_plusplus>()) {
n->remove_content();
auto expression = std::move(n->children[1]); auto expression = std::move(n->children[1]);
auto unary_operator = std::move(n->children[0]); auto unary_operator = std::move(n->children[0]);
unary_operator->children.emplace_back(std::move(expression)); unary_operator->children.emplace_back(std::move(expression));
n = std::move(unary_operator); n = std::move(unary_operator);
n->remove_content();
transform(n, st...); transform(n, st...);
} }
} }
...@@ -111,11 +100,9 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary ...@@ -111,11 +100,9 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary
auto unary_operator = std::move(n->children[child_nb - 1]); auto unary_operator = std::move(n->children[child_nb - 1]);
n->children.pop_back(); n->children.pop_back();
unary_operator->remove_content();
unary_operator->children.emplace_back(std::move(n)); unary_operator->children.emplace_back(std::move(n));
n = std::move(unary_operator); n = std::move(unary_operator);
n->remove_content();
transform(n->children[0], st...); transform(n->children[0], st...);
} }
} }
...@@ -132,7 +119,6 @@ struct ASTBuilder::simplify_node_list : parse_tree::apply<ASTBuilder::simplify_n ...@@ -132,7 +119,6 @@ struct ASTBuilder::simplify_node_list : parse_tree::apply<ASTBuilder::simplify_n
if (n->is_type<language::name_list>() or n->is_type<language::function_argument_list>() or if (n->is_type<language::name_list>() or n->is_type<language::function_argument_list>() or
n->is_type<language::expression_list>()) { n->is_type<language::expression_list>()) {
if (n->children.size() == 1) { if (n->children.size() == 1) {
n->remove_content();
n = std::move(n->children.back()); n = std::move(n->children.back());
transform(n, st...); transform(n, st...);
} }
...@@ -148,7 +134,6 @@ struct ASTBuilder::simplify_statement_block : parse_tree::apply<ASTBuilder::simp ...@@ -148,7 +134,6 @@ struct ASTBuilder::simplify_statement_block : parse_tree::apply<ASTBuilder::simp
{ {
if ((n->is_type<language::statement_block>() or n->is_type<language::block>()) and (n->children.size() == 1)) { if ((n->is_type<language::statement_block>() or n->is_type<language::block>()) and (n->children.size() == 1)) {
if (not n->children[0]->is_type<language::declaration>()) { if (not n->children[0]->is_type<language::declaration>()) {
n->remove_content();
n = std::move(n->children.back()); n = std::move(n->children.back());
transform(n, st...); transform(n, st...);
} else { } else {
...@@ -165,7 +150,6 @@ struct ASTBuilder::simplify_for_statement_block : parse_tree::apply<ASTBuilder:: ...@@ -165,7 +150,6 @@ struct ASTBuilder::simplify_for_statement_block : parse_tree::apply<ASTBuilder::
transform(std::unique_ptr<ASTNode>& n, States&&... st) transform(std::unique_ptr<ASTNode>& n, States&&... st)
{ {
if ((n->is_type<language::for_statement_block>() or n->is_type<language::block>()) and (n->children.size() == 1)) { if ((n->is_type<language::for_statement_block>() or n->is_type<language::block>()) and (n->children.size() == 1)) {
n->remove_content();
n = std::move(n->children.back()); n = std::move(n->children.back());
transform(n, st...); transform(n, st...);
} }
...@@ -180,7 +164,6 @@ struct ASTBuilder::simplify_for_init : parse_tree::apply<ASTBuilder::simplify_fo ...@@ -180,7 +164,6 @@ struct ASTBuilder::simplify_for_init : parse_tree::apply<ASTBuilder::simplify_fo
{ {
Assert(n->children.size() <= 1); Assert(n->children.size() <= 1);
if (n->children.size() == 1) { if (n->children.size() == 1) {
n->remove_content();
n = std::move(n->children.back()); n = std::move(n->children.back());
} }
} }
...@@ -194,7 +177,6 @@ struct ASTBuilder::simplify_for_test : parse_tree::apply<ASTBuilder::simplify_fo ...@@ -194,7 +177,6 @@ struct ASTBuilder::simplify_for_test : parse_tree::apply<ASTBuilder::simplify_fo
{ {
Assert(n->children.size() <= 1); Assert(n->children.size() <= 1);
if (n->children.size() == 1) { if (n->children.size() == 1) {
n->remove_content();
n = std::move(n->children.back()); n = std::move(n->children.back());
} }
} }
...@@ -208,7 +190,6 @@ struct ASTBuilder::simplify_for_post : parse_tree::apply<ASTBuilder::simplify_fo ...@@ -208,7 +190,6 @@ struct ASTBuilder::simplify_for_post : parse_tree::apply<ASTBuilder::simplify_fo
{ {
Assert(n->children.size() <= 1); Assert(n->children.size() <= 1);
if (n->children.size() == 1) { if (n->children.size() == 1) {
n->remove_content();
n = std::move(n->children.back()); n = std::move(n->children.back());
} }
} }
...@@ -223,7 +204,6 @@ struct ASTBuilder::simplify_stream_statement : parse_tree::apply<ASTBuilder::sim ...@@ -223,7 +204,6 @@ struct ASTBuilder::simplify_stream_statement : parse_tree::apply<ASTBuilder::sim
for (size_t i = 1; i < n->children.size(); ++i) { for (size_t i = 1; i < n->children.size(); ++i) {
n->children[0]->children.emplace_back(std::move(n->children[i])); n->children[0]->children.emplace_back(std::move(n->children[i]));
} }
n->remove_content();
n = std::move(n->children[0]); n = std::move(n->children[0]);
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment