Commit 00b44a6e by Ian Lance Taylor Committed by Ian Lance Taylor

Add compound_list to backend interface.

	* go-gcc.cc (Gcc_backend::compound_statement): New function.
	(Gcc_backend::assignment_statement): Use error_statement.
	(Gcc_backend::return_statement): Likewise.
	(Gcc_backend::if_statement): Likewise.
	(Gcc_backend::switch_statement): Likewise.
	(Gcc_backend::statement_list): Likewise.

From-SVN: r172521
parent eb229cf4
2011-04-15 Ian Lance Taylor <iant@google.com>
* go-gcc.cc (Gcc_backend::compound_statement): New function.
(Gcc_backend::assignment_statement): Use error_statement.
(Gcc_backend::return_statement): Likewise.
(Gcc_backend::if_statement): Likewise.
(Gcc_backend::switch_statement): Likewise.
(Gcc_backend::statement_list): Likewise.
2011-04-14 Ian Lance Taylor <iant@google.com> 2011-04-14 Ian Lance Taylor <iant@google.com>
* go-gcc.cc (Backend::error_statement): New function. * go-gcc.cc (Backend::error_statement): New function.
......
...@@ -191,6 +191,9 @@ class Gcc_backend : public Backend ...@@ -191,6 +191,9 @@ class Gcc_backend : public Backend
source_location); source_location);
Bstatement* Bstatement*
compound_statement(Bstatement*, Bstatement*);
Bstatement*
statement_list(const std::vector<Bstatement*>&); statement_list(const std::vector<Bstatement*>&);
// Labels. // Labels.
...@@ -244,7 +247,7 @@ Gcc_backend::assignment_statement(Bexpression* lhs, Bexpression* rhs, ...@@ -244,7 +247,7 @@ Gcc_backend::assignment_statement(Bexpression* lhs, Bexpression* rhs,
tree lhs_tree = lhs->get_tree(); tree lhs_tree = lhs->get_tree();
tree rhs_tree = rhs->get_tree(); tree rhs_tree = rhs->get_tree();
if (lhs_tree == error_mark_node || rhs_tree == error_mark_node) if (lhs_tree == error_mark_node || rhs_tree == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
return this->make_statement(fold_build2_loc(location, MODIFY_EXPR, return this->make_statement(fold_build2_loc(location, MODIFY_EXPR,
void_type_node, void_type_node,
lhs_tree, rhs_tree)); lhs_tree, rhs_tree));
...@@ -259,10 +262,10 @@ Gcc_backend::return_statement(Bfunction* bfunction, ...@@ -259,10 +262,10 @@ Gcc_backend::return_statement(Bfunction* bfunction,
{ {
tree fntree = bfunction->get_tree(); tree fntree = bfunction->get_tree();
if (fntree == error_mark_node) if (fntree == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
tree result = DECL_RESULT(fntree); tree result = DECL_RESULT(fntree);
if (result == error_mark_node) if (result == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
tree ret; tree ret;
if (vals.empty()) if (vals.empty())
ret = fold_build1_loc(location, RETURN_EXPR, void_type_node, NULL_TREE); ret = fold_build1_loc(location, RETURN_EXPR, void_type_node, NULL_TREE);
...@@ -270,7 +273,7 @@ Gcc_backend::return_statement(Bfunction* bfunction, ...@@ -270,7 +273,7 @@ Gcc_backend::return_statement(Bfunction* bfunction,
{ {
tree val = vals.front()->get_tree(); tree val = vals.front()->get_tree();
if (val == error_mark_node) if (val == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
tree set = fold_build2_loc(location, MODIFY_EXPR, void_type_node, tree set = fold_build2_loc(location, MODIFY_EXPR, void_type_node,
result, vals.front()->get_tree()); result, vals.front()->get_tree());
ret = fold_build1_loc(location, RETURN_EXPR, void_type_node, set); ret = fold_build1_loc(location, RETURN_EXPR, void_type_node, set);
...@@ -294,7 +297,7 @@ Gcc_backend::return_statement(Bfunction* bfunction, ...@@ -294,7 +297,7 @@ Gcc_backend::return_statement(Bfunction* bfunction,
rettmp, field, NULL_TREE); rettmp, field, NULL_TREE);
tree val = (*p)->get_tree(); tree val = (*p)->get_tree();
if (val == error_mark_node) if (val == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
tree set = fold_build2_loc(location, MODIFY_EXPR, void_type_node, tree set = fold_build2_loc(location, MODIFY_EXPR, void_type_node,
ref, (*p)->get_tree()); ref, (*p)->get_tree());
append_to_statement_list(set, &stmt_list); append_to_statement_list(set, &stmt_list);
...@@ -322,7 +325,7 @@ Gcc_backend::if_statement(Bexpression* condition, Bstatement* then_block, ...@@ -322,7 +325,7 @@ Gcc_backend::if_statement(Bexpression* condition, Bstatement* then_block,
if (cond_tree == error_mark_node if (cond_tree == error_mark_node
|| then_tree == error_mark_node || then_tree == error_mark_node
|| else_tree == error_mark_node) || else_tree == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
tree ret = build3_loc(location, COND_EXPR, void_type_node, cond_tree, tree ret = build3_loc(location, COND_EXPR, void_type_node, cond_tree,
then_tree, else_tree); then_tree, else_tree);
return this->make_statement(ret); return this->make_statement(ret);
...@@ -363,7 +366,7 @@ Gcc_backend::switch_statement( ...@@ -363,7 +366,7 @@ Gcc_backend::switch_statement(
{ {
tree t = (*pcv)->get_tree(); tree t = (*pcv)->get_tree();
if (t == error_mark_node) if (t == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
source_location loc = EXPR_LOCATION(t); source_location loc = EXPR_LOCATION(t);
tree label = create_artificial_label(loc); tree label = create_artificial_label(loc);
tree c = build3_loc(loc, CASE_LABEL_EXPR, void_type_node, tree c = build3_loc(loc, CASE_LABEL_EXPR, void_type_node,
...@@ -376,19 +379,36 @@ Gcc_backend::switch_statement( ...@@ -376,19 +379,36 @@ Gcc_backend::switch_statement(
{ {
tree t = (*ps)->get_tree(); tree t = (*ps)->get_tree();
if (t == error_mark_node) if (t == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
append_to_statement_list(t, &stmt_list); append_to_statement_list(t, &stmt_list);
} }
} }
tree tv = value->get_tree(); tree tv = value->get_tree();
if (tv == error_mark_node) if (tv == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
tree t = build3_loc(switch_location, SWITCH_EXPR, void_type_node, tree t = build3_loc(switch_location, SWITCH_EXPR, void_type_node,
tv, stmt_list, NULL_TREE); tv, stmt_list, NULL_TREE);
return this->make_statement(t); return this->make_statement(t);
} }
// Pair of statements.
Bstatement*
Gcc_backend::compound_statement(Bstatement* s1, Bstatement* s2)
{
tree stmt_list = NULL_TREE;
tree t = s1->get_tree();
if (t == error_mark_node)
return this->error_statement();
append_to_statement_list(t, &stmt_list);
t = s2->get_tree();
if (t == error_mark_node)
return this->error_statement();
append_to_statement_list(t, &stmt_list);
return this->make_statement(stmt_list);
}
// List of statements. // List of statements.
Bstatement* Bstatement*
...@@ -401,7 +421,7 @@ Gcc_backend::statement_list(const std::vector<Bstatement*>& statements) ...@@ -401,7 +421,7 @@ Gcc_backend::statement_list(const std::vector<Bstatement*>& statements)
{ {
tree t = (*p)->get_tree(); tree t = (*p)->get_tree();
if (t == error_mark_node) if (t == error_mark_node)
return this->make_statement(error_mark_node); return this->error_statement();
append_to_statement_list(t, &stmt_list); append_to_statement_list(t, &stmt_list);
} }
return this->make_statement(stmt_list); return this->make_statement(stmt_list);
......
...@@ -146,6 +146,10 @@ class Backend ...@@ -146,6 +146,10 @@ class Backend
const std::vector<Bstatement*>& statements, const std::vector<Bstatement*>& statements,
source_location) = 0; source_location) = 0;
// Create a single statement from two statements.
virtual Bstatement*
compound_statement(Bstatement*, Bstatement*) = 0;
// Create a single statement from a list of statements. // Create a single statement from a list of statements.
virtual Bstatement* virtual Bstatement*
statement_list(const std::vector<Bstatement*>&) = 0; statement_list(const std::vector<Bstatement*>&) = 0;
......
...@@ -3058,12 +3058,7 @@ Case_clauses::Case_clause::get_backend(Translate_context* context, ...@@ -3058,12 +3058,7 @@ Case_clauses::Case_clause::get_backend(Translate_context* context,
else if (break_stat == NULL) else if (break_stat == NULL)
return statements; return statements;
else else
{ return context->backend()->compound_statement(statements, break_stat);
std::vector<Bstatement*> list(2);
list[0] = statements;
list[1] = break_stat;
return context->backend()->statement_list(list);
}
} }
// Class Case_clauses. // Class Case_clauses.
...@@ -3332,11 +3327,9 @@ Constant_switch_statement::do_get_tree(Translate_context* context) ...@@ -3332,11 +3327,9 @@ Constant_switch_statement::do_get_tree(Translate_context* context)
all_cases, all_cases,
all_statements, all_statements,
this->location()); this->location());
Bstatement* ldef = break_label->get_definition(context);
std::vector<Bstatement*> stats(2); Bstatement* ret = context->backend()->compound_statement(switch_statement,
stats[0] = switch_statement; ldef);
stats[1] = break_label->get_definition(context);
Bstatement* ret = context->backend()->statement_list(stats);
return stat_to_tree(ret); return stat_to_tree(ret);
} }
...@@ -3876,12 +3869,7 @@ Send_statement::do_get_tree(Translate_context* context) ...@@ -3876,12 +3869,7 @@ Send_statement::do_get_tree(Translate_context* context)
if (btemp == NULL) if (btemp == NULL)
return stat_to_tree(s); return stat_to_tree(s);
else else
{ return stat_to_tree(context->backend()->compound_statement(btemp, s));
std::vector<Bstatement*> stats(2);
stats[0] = btemp;
stats[1] = s;
return stat_to_tree(context->backend()->statement_list(stats));
}
} }
// Make a send statement. // Make a send statement.
...@@ -4218,10 +4206,7 @@ Select_clauses::get_backend(Translate_context* context, ...@@ -4218,10 +4206,7 @@ Select_clauses::get_backend(Translate_context* context,
} }
if (s == NULL) if (s == NULL)
return ldef; return ldef;
std::vector<Bstatement*> stats(2); return context->backend()->compound_statement(s, ldef);
stats[0] = s;
stats[1] = ldef;
return context->backend()->statement_list(stats);
} }
gcc_assert(count > 0); gcc_assert(count > 0);
...@@ -4347,12 +4332,7 @@ Select_clauses::add_clause_backend( ...@@ -4347,12 +4332,7 @@ Select_clauses::add_clause_backend(
if (s == NULL) if (s == NULL)
(*clauses)[index] = g; (*clauses)[index] = g;
else else
{ (*clauses)[index] = context->backend()->compound_statement(s, g);
std::vector<Bstatement*> stats(2);
stats[0] = s;
stats[1] = g;
(*clauses)[index] = context->backend()->statement_list(stats);
}
} }
// Class Select_statement. // Class Select_statement.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment