summaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-10-04 18:07:20 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-10-04 18:07:20 +0000
commitcd440cffc72ba69b285b55d6d396c7d879bb8d54 (patch)
treeeea8468b131614593562965119db0820aa44ace6 /gcc/go
parent8f93a8266bec80d619c5725291f77abde22999f5 (diff)
downloadgcc-cd440cffc72ba69b285b55d6d396c7d879bb8d54.tar.gz
compiler: Use backend interface for temporary reference expressions.
* go-gcc.cc (Backend::convert_expression): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@203209 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/ChangeLog4
-rw-r--r--gcc/go/go-gcc.cc17
-rw-r--r--gcc/go/gofrontend/backend.h4
-rw-r--r--gcc/go/gofrontend/expressions.cc17
4 files changed, 34 insertions, 8 deletions
diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog
index 0c9340600b0..eddf39326c3 100644
--- a/gcc/go/ChangeLog
+++ b/gcc/go/ChangeLog
@@ -1,3 +1,7 @@
+2013-10-04 Chris Manghane <cmang@google.com>
+
+ * go-gcc.cc (Backend::convert_expression): New function.
+
2013-10-02 Chris Manghane <cmang@google.com>
* go-gcc.cc: Include "real.h" and "realmpfr.h".
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index 55b60ade21d..fcfd41b34ab 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -229,6 +229,9 @@ class Gcc_backend : public Backend
Bexpression*
complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag);
+ Bexpression*
+ convert_expression(Btype* type, Bexpression* expr, Location);
+
// Statements.
Bstatement*
@@ -949,6 +952,20 @@ Gcc_backend::complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag)
return tree_to_expr(ret);
}
+// An expression that converts an expression to a different type.
+
+Bexpression*
+Gcc_backend::convert_expression(Btype* type, Bexpression* expr, Location)
+{
+ tree type_tree = type->get_tree();
+ tree expr_tree = expr->get_tree();
+ if (type_tree == error_mark_node || expr_tree == error_mark_node)
+ return this->error_expression();
+
+ tree ret = fold_convert(type_tree, expr_tree);
+ return tree_to_expr(ret);
+}
+
// An expression as a statement.
Bstatement*
diff --git a/gcc/go/gofrontend/backend.h b/gcc/go/gofrontend/backend.h
index d0abdd7f798..fa3e3cc6893 100644
--- a/gcc/go/gofrontend/backend.h
+++ b/gcc/go/gofrontend/backend.h
@@ -262,6 +262,10 @@ class Backend
virtual Bexpression*
complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag) = 0;
+ // Return an expression that converts EXPR to TYPE.
+ virtual Bexpression*
+ convert_expression(Btype* type, Bexpression* expr, Location) = 0;
+
// Statements.
// Create an error statement. This is used for cases which should
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 67bec710df5..13d4c1c789a 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -995,23 +995,24 @@ Temporary_reference_expression::do_address_taken(bool)
tree
Temporary_reference_expression::do_get_tree(Translate_context* context)
{
+ Gogo* gogo = context->gogo();
Bvariable* bvar = this->statement_->get_backend_variable(context);
+ Bexpression* ret = gogo->backend()->var_expression(bvar, this->location());
- // The gcc backend can't represent the same set of recursive types
+ // The backend can't always represent the same set of recursive types
// that the Go frontend can. In some cases this means that a
// temporary variable won't have the right backend type. Correct
// that here by adding a type cast. We need to use base() to push
// the circularity down one level.
- tree ret = var_to_tree(bvar);
+ Type* stype = this->statement_->type();
if (!this->is_lvalue_
- && POINTER_TYPE_P(TREE_TYPE(ret))
- && VOID_TYPE_P(TREE_TYPE(TREE_TYPE(ret))))
+ && stype->has_pointer()
+ && stype->deref()->is_void_type())
{
- Btype* type_btype = this->type()->base()->get_backend(context->gogo());
- tree type_tree = type_to_tree(type_btype);
- ret = fold_convert_loc(this->location().gcc_location(), type_tree, ret);
+ Btype* btype = this->type()->base()->get_backend(gogo);
+ ret = gogo->backend()->convert_expression(btype, ret, this->location());
}
- return ret;
+ return expr_to_tree(ret);
}
// Ast dump for temporary reference.