Use backend interface for if statements.
authorIan Lance Taylor <iant@google.com>
Wed, 6 Apr 2011 15:46:53 +0000 (15:46 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Wed, 6 Apr 2011 15:46:53 +0000 (15:46 +0000)
Rename some temporary conversion functions to shorter names.

* go-gcc.cc (Gcc_backend::if_statement): New function.
(tree_to_stat): New function.
(expr_to_tree): Renamed from expression_to_tree.
(stat_to_tree): Renamed from statement_to_tree.

From-SVN: r172052

gcc/go/ChangeLog
gcc/go/go-gcc.cc
gcc/go/gofrontend/backend.h
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/statements.cc

index b83eae8cb26e76959cd46c843f785e0a43140079..ff56bfe9883b3253020428406c0d6956c998a19c 100644 (file)
@@ -1,3 +1,10 @@
+2011-04-06  Ian Lance Taylor  <iant@google.com>
+
+       * go-gcc.cc (Gcc_backend::if_statement): New function.
+       (tree_to_stat): New function.
+       (expr_to_tree): Renamed from expression_to_tree.
+       (stat_to_tree): Renamed from statement_to_tree.
+
 2011-04-06  Ian Lance Taylor  <iant@google.com>
 
        * go-gcc.cc (Gcc_backend::expression_statement): New function.
index ce26d4d844e5654feb74173e0ba079a1b6e031a8..de689f8478e54747fa22f0c66af719bfdf73e5e8 100644 (file)
@@ -176,6 +176,10 @@ class Gcc_backend : public Backend
   return_statement(Bfunction*, const std::vector<Bexpression*>&,
                   source_location);
 
+  Bstatement*
+  if_statement(Bexpression* condition, Bstatement* then_block,
+              Bstatement* else_block, source_location);
+
   // Labels.
 
   Blabel*
@@ -293,6 +297,25 @@ Gcc_backend::return_statement(Bfunction* bfunction,
   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*
@@ -366,6 +389,12 @@ tree_to_expr(tree t)
   return new Bexpression(t);
 }
 
+Bstatement*
+tree_to_stat(tree t)
+{
+  return new Bstatement(t);
+}
+
 Bfunction*
 tree_to_function(tree t)
 {
@@ -373,13 +402,13 @@ 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();
 }
index a84b9e84c69860a15acc965886e7f61066c1c056..a6c242680ff3459dc2ecbc0a1bb9126460086422 100644 (file)
@@ -122,6 +122,11 @@ class Backend
   return_statement(Bfunction*, const std::vector<Bexpression*>&,
                   source_location) = 0;
 
+  // Create an if statement.  ELSE_BLOCK may be NULL.
+  virtual Bstatement*
+  if_statement(Bexpression* condition, Bstatement* then_block,
+              Bstatement* else_block, source_location) = 0;
+
   // Labels.
   
   // Create a new label.  NAME will be empty if this is a label
@@ -155,8 +160,9 @@ extern Backend* go_get_backend();
 // interface.
 
 extern Bexpression* tree_to_expr(tree);
+extern Bstatement* tree_to_stat(tree);
 extern Bfunction* tree_to_function(tree);
-extern tree expression_to_tree(Bexpression*);
-extern tree statement_to_tree(Bstatement*);
+extern tree expr_to_tree(Bexpression*);
+extern tree stat_to_tree(Bstatement*);
 
 #endif // !defined(GO_BACKEND_H)
index afd2191e857f6fb9155e7ca89b16b8da3c2b59a8..c516485f343cebc832581db365529f0e03049926 100644 (file)
@@ -12598,8 +12598,7 @@ class Label_addr_expression : public Expression
   tree
   do_get_tree(Translate_context* context)
   {
-    return expression_to_tree(this->label_->get_addr(context,
-                                                    this->location()));
+    return expr_to_tree(this->label_->get_addr(context, this->location()));
   }
 
  private:
index da29a35d00dd6bdef25cbec1da25df693570a382..131001a9ce1f54c7c49bba33f8655ec1b8b64d1e 100644 (file)
@@ -565,7 +565,7 @@ Assignment_statement::do_get_tree(Translate_context* context)
   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.
@@ -1596,7 +1596,7 @@ Expression_statement::do_get_tree(Translate_context* context)
   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.
@@ -2593,7 +2593,7 @@ Return_statement::do_get_tree(Translate_context* context)
   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.
@@ -2631,8 +2631,7 @@ class Bc_statement : public 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:
@@ -2710,7 +2709,7 @@ Goto_statement::do_get_tree(Translate_context* context)
   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.
@@ -2743,8 +2742,7 @@ class Goto_unnamed_statement : public 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:
@@ -2778,7 +2776,7 @@ Label_statement::do_get_tree(Translate_context* context)
   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.
@@ -2806,7 +2804,7 @@ class Unnamed_label_statement : public 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.
@@ -2914,14 +2912,17 @@ If_statement::do_get_tree(Translate_context* context)
   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.
@@ -3158,7 +3159,7 @@ Case_clauses::Case_clause::get_constant_tree(Translate_context* context,
   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);
     }
 }
 
@@ -3413,7 +3414,7 @@ Constant_switch_statement::do_get_tree(Translate_context* context)
   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;
 }
@@ -4272,7 +4273,7 @@ Select_clauses::get_tree(Translate_context* context,
       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;
     }
 
@@ -4364,7 +4365,7 @@ Select_clauses::get_tree(Translate_context* context,
     }
 
   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);
@@ -4390,7 +4391,7 @@ Select_clauses::add_clause_tree(Translate_context* context, int case_index,
                          ? 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.