return_statement(Bfunction*, const std::vector<Bexpression*>&,
source_location);
+ Bstatement*
+ if_statement(Bexpression* condition, Bstatement* then_block,
+ Bstatement* else_block, source_location);
+
// Labels.
Blabel*
return this->make_statement(ret);
}
+// If.
+
+Bstatement*
+Gcc_backend::if_statement(Bexpression* condition, Bstatement* then_block,
+ Bstatement* else_block, source_location location)
+{
+ tree cond_tree = condition->get_tree();
+ tree then_tree = then_block->get_tree();
+ tree else_tree = else_block == NULL ? NULL_TREE : else_block->get_tree();
+ if (cond_tree == error_mark_node
+ || then_tree == error_mark_node
+ || else_tree == error_mark_node)
+ return this->make_statement(error_mark_node);
+ tree ret = build3(COND_EXPR, void_type_node, cond_tree, then_tree,
+ else_tree);
+ SET_EXPR_LOCATION(ret, location);
+ return this->make_statement(ret);
+}
+
// Make a label.
Blabel*
return new Bexpression(t);
}
+Bstatement*
+tree_to_stat(tree t)
+{
+ return new Bstatement(t);
+}
+
Bfunction*
tree_to_function(tree t)
{
}
tree
-expression_to_tree(Bexpression* be)
+expr_to_tree(Bexpression* be)
{
return be->get_tree();
}
tree
-statement_to_tree(Bstatement* bs)
+stat_to_tree(Bstatement* bs)
{
return bs->get_tree();
}
ret = context->backend()->assignment_statement(tree_to_expr(lhs_tree),
tree_to_expr(rhs_tree),
this->location());
- return statement_to_tree(ret);
+ return stat_to_tree(ret);
}
// Make an assignment statement.
tree expr_tree = this->expr_->get_tree(context);
Bexpression* bexpr = tree_to_expr(expr_tree);
Bstatement* ret = context->backend()->expression_statement(bexpr);
- return statement_to_tree(ret);
+ return stat_to_tree(ret);
}
// Make an expression statement from an Expression.
Bstatement* ret;
ret = context->backend()->return_statement(tree_to_function(fndecl),
retvals, this->location());
- return statement_to_tree(ret);
+ return stat_to_tree(ret);
}
// Make a return statement.
tree
do_get_tree(Translate_context* context)
{
- return statement_to_tree(this->label_->get_goto(context,
- this->location()));
+ return stat_to_tree(this->label_->get_goto(context, this->location()));
}
private:
Blabel* blabel = this->label_->get_backend_label(context);
Bstatement* statement = context->backend()->goto_statement(blabel,
this->location());
- return statement_to_tree(statement);
+ return stat_to_tree(statement);
}
// Make a goto statement.
tree
do_get_tree(Translate_context* context)
{
- return statement_to_tree(this->label_->get_goto(context,
- this->location()));
+ return stat_to_tree(this->label_->get_goto(context, this->location()));
}
private:
Blabel* blabel = this->label_->get_backend_label(context);
Bstatement* statement;
statement = context->backend()->label_definition_statement(blabel);
- return statement_to_tree(statement);
+ return stat_to_tree(statement);
}
// Make a label statement.
tree
do_get_tree(Translate_context* context)
- { return statement_to_tree(this->label_->get_definition(context)); }
+ { return stat_to_tree(this->label_->get_definition(context)); }
private:
// The label.
tree else_tree = (this->else_block_ == NULL
? NULL_TREE
: this->else_block_->get_tree(context));
- if (cond_tree == error_mark_node
- || then_tree == error_mark_node
- || else_tree == error_mark_node)
- return error_mark_node;
- tree ret = build3(COND_EXPR, void_type_node, cond_tree, then_tree,
- else_tree);
- SET_EXPR_LOCATION(ret, this->location());
- return ret;
+
+ Bexpression* cond_expr = tree_to_expr(cond_tree);
+ Bstatement* then_stat = tree_to_stat(then_tree);
+ Bstatement* else_stat = (else_tree == NULL_TREE
+ ? NULL
+ : tree_to_stat(else_tree));
+
+ Bstatement* ret = context->backend()->if_statement(cond_expr, then_stat,
+ else_stat,
+ this->location());
+ return stat_to_tree(ret);
}
// Make an if statement.
if (!this->is_fallthrough_)
{
Bstatement* g = break_label->get_goto(context, this->location_);
- append_to_statement_list(statement_to_tree(g), stmt_list);
+ append_to_statement_list(stat_to_tree(g), stmt_list);
}
}
append_to_statement_list(s, &stmt_list);
Bstatement* ldef = break_label->get_definition(context);
- append_to_statement_list(statement_to_tree(ldef), &stmt_list);
+ append_to_statement_list(stat_to_tree(ldef), &stmt_list);
return stmt_list;
}
append_to_statement_list(default_clause->get_statements_tree(context),
&stmt_list);
Bstatement* ldef = break_label->get_definition(context);
- append_to_statement_list(statement_to_tree(ldef), &stmt_list);
+ append_to_statement_list(stat_to_tree(ldef), &stmt_list);
return stmt_list;
}
}
Bstatement* ldef = break_label->get_definition(context);
- append_to_statement_list(statement_to_tree(ldef), &stmt_list);
+ append_to_statement_list(stat_to_tree(ldef), &stmt_list);
tree switch_stmt = build3(SWITCH_EXPR, sizetype, call, stmt_list, NULL_TREE);
SET_EXPR_LOCATION(switch_stmt, location);
? clause->location()
: clause->statements()->end_location());
Bstatement* g = bottom_label->get_goto(context, gloc);
- append_to_statement_list(statement_to_tree(g), stmt_list);
+ append_to_statement_list(stat_to_tree(g), stmt_list);
}
// Class Select_statement.