OSDN Git Service

Use backend interface for if statements.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Apr 2011 15:46:53 +0000 (15:46 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@172052 138bc75d-0d04-0410-961f-82ee72b054a4

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

index b83eae8..ff56bfe 100644 (file)
@@ -1,5 +1,12 @@
 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.
 
 2011-04-04  Ian Lance Taylor  <iant@google.com>
index ce26d4d..de689f8 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 a84b9e8..a6c2426 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 afd2191..c516485 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 da29a35..131001a 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.