compiler: Use backend interface for expressions.

* go-gcc.cc (Gcc_backend::nil_pointer_expression): New method.
	(Gcc_backend::boolean_constant_expression): New method.
	(Gcc_backend::zero_expression): Use this->make_expression rather
	than tree_to_expr.
	(Gcc_backend::var_expression): Likewise.
	(Gcc_backend::integer_constant_expression): Likewise.
	(Gcc_backend::float_constant_expression): Likewise.
	(Gcc_backend::complex_constant_expression): Likewise.
	(Gcc_backend::struct_field_expression): Likewise.
	(tree_to_type, tree_to_expr, tree_to_stat): Remove functions.
	(tree_to_function, tree_to_block): Remove functions.
	(type_to_tree, expr_to_tree, stat_to_tree): Remove functions.
	(block_to_tree, var_to_tree, function_to_tree): Remove functions.

From-SVN: r210122
This commit is contained in:
Chris Manghane 2014-05-06 19:28:03 +00:00 committed by Ian Lance Taylor
parent 3379b71f51
commit 6f7e0b570a
10 changed files with 554 additions and 718 deletions

View File

@ -1,3 +1,19 @@
2014-05-06 Chris Manghane <cmang@google.com>
* go-gcc.cc (Gcc_backend::nil_pointer_expression): New method.
(Gcc_backend::boolean_constant_expression): New method.
(Gcc_backend::zero_expression): Use this->make_expression rather
than tree_to_expr.
(Gcc_backend::var_expression): Likewise.
(Gcc_backend::integer_constant_expression): Likewise.
(Gcc_backend::float_constant_expression): Likewise.
(Gcc_backend::complex_constant_expression): Likewise.
(Gcc_backend::struct_field_expression): Likewise.
(tree_to_type, tree_to_expr, tree_to_stat): Remove functions.
(tree_to_function, tree_to_block): Remove functions.
(type_to_tree, expr_to_tree, stat_to_tree): Remove functions.
(block_to_tree, var_to_tree, function_to_tree): Remove functions.
2014-05-06 Kenneth Zadeck <zadeck@naturalbridge.com>
Mike Stump <mikestump@comcast.net>
Richard Sandiford <rdsandiford@googlemail.com>

View File

@ -225,6 +225,10 @@ class Gcc_backend : public Backend
error_expression()
{ return this->make_expression(error_mark_node); }
Bexpression*
nil_pointer_expression()
{ return this->make_expression(null_pointer_node); }
Bexpression*
var_expression(Bvariable* var, Location);
@ -247,6 +251,9 @@ class Gcc_backend : public Backend
Bexpression*
string_constant_expression(const std::string& val);
Bexpression*
boolean_constant_expression(bool val);
Bexpression*
real_part_expression(Bexpression* bcomplex, Location);
@ -1129,7 +1136,7 @@ Gcc_backend::zero_expression(Btype* btype)
ret = error_mark_node;
else
ret = build_zero_cst(t);
return tree_to_expr(ret);
return this->make_expression(ret);
}
// An expression that references a variable.
@ -1140,7 +1147,7 @@ Gcc_backend::var_expression(Bvariable* var, Location)
tree ret = var->get_tree();
if (ret == error_mark_node)
return this->error_expression();
return tree_to_expr(ret);
return this->make_expression(ret);
}
// An expression that indirectly references an expression.
@ -1201,7 +1208,7 @@ Gcc_backend::integer_constant_expression(Btype* btype, mpz_t val)
return this->error_expression();
tree ret = double_int_to_tree(t, mpz_get_double_int(t, val, true));
return tree_to_expr(ret);
return this->make_expression(ret);
}
// Return a typed value as a constant floating-point number.
@ -1219,7 +1226,7 @@ Gcc_backend::float_constant_expression(Btype* btype, mpfr_t val)
REAL_VALUE_TYPE r2;
real_convert(&r2, TYPE_MODE(t), &r1);
ret = build_real(t, r2);
return tree_to_expr(ret);
return this->make_expression(ret);
}
// Return a typed real and imaginary value as a constant complex number.
@ -1244,7 +1251,7 @@ Gcc_backend::complex_constant_expression(Btype* btype, mpfr_t real, mpfr_t imag)
ret = build_complex(t, build_real(TREE_TYPE(t), r2),
build_real(TREE_TYPE(t), r4));
return tree_to_expr(ret);
return this->make_expression(ret);
}
// Make a constant string expression.
@ -1264,6 +1271,15 @@ Gcc_backend::string_constant_expression(const std::string& val)
return this->make_expression(string_val);
}
// Make a constant boolean expression.
Bexpression*
Gcc_backend::boolean_constant_expression(bool val)
{
tree bool_cst = val ? boolean_true_node : boolean_false_node;
return this->make_expression(bool_cst);
}
// Return the real part of a complex expression.
Bexpression*
@ -1407,7 +1423,7 @@ Gcc_backend::struct_field_expression(Bexpression* bstruct, size_t index,
NULL_TREE);
if (TREE_CONSTANT(struct_tree))
TREE_CONSTANT(ret) = 1;
return tree_to_expr(ret);
return this->make_expression(ret);
}
// Return an expression that executes BSTAT before BEXPR.
@ -2923,73 +2939,3 @@ go_get_backend()
{
return new Gcc_backend();
}
// FIXME: Temporary functions while converting to the new backend
// interface.
Btype*
tree_to_type(tree t)
{
return new Btype(t);
}
Bexpression*
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)
{
return new Bfunction(t);
}
Bblock*
tree_to_block(tree t)
{
gcc_assert(TREE_CODE(t) == BIND_EXPR);
return new Bblock(t);
}
tree
type_to_tree(Btype* bt)
{
return bt->get_tree();
}
tree
expr_to_tree(Bexpression* be)
{
return be->get_tree();
}
tree
stat_to_tree(Bstatement* bs)
{
return bs->get_tree();
}
tree
block_to_tree(Bblock* bb)
{
return bb->get_tree();
}
tree
var_to_tree(Bvariable* bv)
{
return bv->get_tree();
}
tree
function_to_tree(Bfunction* bf)
{
return bf->get_tree();
}

View File

@ -247,6 +247,10 @@ class Backend
virtual Bexpression*
error_expression() = 0;
// Create a nil pointer expression.
virtual Bexpression*
nil_pointer_expression() = 0;
// Create a reference to a variable.
virtual Bexpression*
var_expression(Bvariable* var, Location) = 0;
@ -281,6 +285,10 @@ class Backend
virtual Bexpression*
string_constant_expression(const std::string& val) = 0;
// Return an expression for the boolean value VAL.
virtual Bexpression*
boolean_constant_expression(bool val) = 0;
// Return an expression for the real part of BCOMPLEX.
virtual Bexpression*
real_part_expression(Bexpression* bcomplex, Location) = 0;
@ -687,19 +695,4 @@ class Backend
extern Backend* go_get_backend();
// FIXME: Temporary helper functions while converting to new backend
// interface.
extern Btype* tree_to_type(tree);
extern Bexpression* tree_to_expr(tree);
extern Bstatement* tree_to_stat(tree);
extern Bfunction* tree_to_function(tree);
extern Bblock* tree_to_block(tree);
extern tree type_to_tree(Btype*);
extern tree expr_to_tree(Bexpression*);
extern tree stat_to_tree(Bstatement*);
extern tree block_to_tree(Bblock*);
extern tree var_to_tree(Bvariable*);
extern tree function_to_tree(Bfunction*);
#endif // !defined(GO_BACKEND_H)

File diff suppressed because it is too large Load Diff

View File

@ -747,9 +747,9 @@ class Expression
return this->do_must_eval_subexpressions_in_order(skip);
}
// Return the tree for this expression.
tree
get_tree(Translate_context*);
// Return the backend representation for this expression.
Bexpression*
get_backend(Translate_context*);
// Return an expression handling any conversions which must be done during
// assignment.
@ -883,9 +883,9 @@ class Expression
do_must_eval_subexpressions_in_order(int* /* skip */) const
{ return false; }
// Child class implements conversion to tree.
virtual tree
do_get_tree(Translate_context*) = 0;
// Child class implements conversion to backend representation.
virtual Bexpression*
do_get_backend(Translate_context*) = 0;
// Child class implements export.
virtual void
@ -1068,8 +1068,8 @@ class Parser_expression : public Expression
do_check_types(Gogo*)
{ go_unreachable(); }
tree
do_get_tree(Translate_context*)
Bexpression*
do_get_backend(Translate_context*)
{ go_unreachable(); }
};
@ -1109,8 +1109,8 @@ class Var_expression : public Expression
void
do_address_taken(bool);
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -1161,8 +1161,8 @@ class Temporary_reference_expression : public Expression
void
do_address_taken(bool);
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -1221,8 +1221,8 @@ class Set_and_use_temporary_expression : public Expression
void
do_address_taken(bool);
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -1277,8 +1277,8 @@ class String_expression : public Expression
do_copy()
{ return this; }
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
// Write string literal to a string dump.
static void
@ -1410,8 +1410,8 @@ class Unary_expression : public Expression
do_is_addressable() const
{ return this->op_ == OPERATOR_MULT; }
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_export(Export*) const;
@ -1534,8 +1534,8 @@ class Binary_expression : public Expression
this->right_->copy(), this->location());
}
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_export(Export*) const;
@ -1715,8 +1715,8 @@ class Call_expression : public Expression
bool
do_must_eval_in_order() const;
virtual tree
do_get_tree(Translate_context*);
virtual Bexpression*
do_get_backend(Translate_context*);
virtual bool
do_is_recover_call() const;
@ -1834,8 +1834,8 @@ class Func_expression : public Expression
this->location());
}
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -1881,8 +1881,8 @@ class Func_descriptor_expression : public Expression
do_is_addressable() const
{ return true; }
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context* context) const;
@ -2124,8 +2124,8 @@ class Map_index_expression : public Expression
// A map index expression is an lvalue but it is not addressable.
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -2210,8 +2210,8 @@ class Bound_method_expression : public Expression
this->function_, this->location());
}
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -2313,8 +2313,8 @@ class Field_reference_expression : public Expression
do_issue_nil_check()
{ this->expr_->issue_nil_check(); }
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -2392,8 +2392,8 @@ class Interface_field_reference_expression : public Expression
this->location());
}
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -2458,8 +2458,8 @@ class Type_guard_expression : public Expression
this->location());
}
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
@ -2518,8 +2518,8 @@ class Receive_expression : public Expression
do_must_eval_in_order() const
{ return true; }
tree
do_get_tree(Translate_context*);
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;

View File

@ -729,7 +729,7 @@ Gogo::register_gc_vars(const std::vector<Named_object*>& var_gc,
builtin_loc, 1, root_addr);
Translate_context context(this, NULL, NULL, NULL);
Bexpression* bcall = tree_to_expr(register_roots->get_tree(&context));
Bexpression* bcall = register_roots->get_backend(&context);
init_stmts.push_back(this->backend()->expression_statement(bcall));
}
@ -4065,8 +4065,8 @@ Build_method_tables::type(Type* type)
if ((*p)->implements_interface(Type::make_pointer_type(nt),
NULL))
{
nt->interface_method_table(*p, false)->get_tree(&context);
nt->interface_method_table(*p, true)->get_tree(&context);
nt->interface_method_table(*p, false)->get_backend(&context);
nt->interface_method_table(*p, true)->get_backend(&context);
}
}
else
@ -4074,8 +4074,8 @@ Build_method_tables::type(Type* type)
if ((*p)->implements_interface(Type::make_pointer_type(st),
NULL))
{
st->interface_method_table(*p, false)->get_tree(&context);
st->interface_method_table(*p, true)->get_tree(&context);
st->interface_method_table(*p, false)->get_backend(&context);
st->interface_method_table(*p, true)->get_backend(&context);
}
}
}
@ -4916,7 +4916,7 @@ Function_declaration::build_backend_descriptor(Gogo* gogo)
if (this->descriptor_ != NULL)
{
Translate_context context(gogo, NULL, NULL, NULL);
this->descriptor_->get_tree(&context);
this->descriptor_->get_backend(&context);
}
}
@ -4975,7 +4975,7 @@ Function::build(Gogo* gogo, Named_object* named_function)
parm_ref = Expression::make_unary(OPERATOR_MULT, parm_ref, loc);
if ((*p)->var_value()->is_in_heap())
parm_ref = Expression::make_heap_expression(parm_ref, loc);
var_inits.push_back(tree_to_expr(parm_ref->get_tree(&context)));
var_inits.push_back(parm_ref->get_backend(&context));
}
else if ((*p)->var_value()->is_in_heap())
{
@ -4992,7 +4992,7 @@ Function::build(Gogo* gogo, Named_object* named_function)
Expression* var_ref =
Expression::make_var_reference(parm_no, loc);
var_ref = Expression::make_heap_expression(var_ref, loc);
var_inits.push_back(tree_to_expr(var_ref->get_tree(&context)));
var_inits.push_back(var_ref->get_backend(&context));
}
param_vars.push_back(parm_bvar);
}
@ -5008,10 +5008,8 @@ Function::build(Gogo* gogo, Named_object* named_function)
init = gogo->backend()->zero_expression(btype);
}
else
{
Expression* alloc = Expression::make_allocation(type, loc);
init = tree_to_expr(alloc->get_tree(&context));
}
init = Expression::make_allocation(type,
loc)->get_backend(&context);
vars.push_back(bvar);
var_inits.push_back(init);
@ -5034,7 +5032,7 @@ Function::build(Gogo* gogo, Named_object* named_function)
Expression* closure =
Runtime::make_call(Runtime::GET_CLOSURE, this->location_, 0);
var_inits.push_back(tree_to_expr(closure->get_tree(&context)));
var_inits.push_back(closure->get_backend(&context));
}
if (this->block_ != NULL)
@ -5115,7 +5113,7 @@ Function::build(Gogo* gogo, Named_object* named_function)
if (this->descriptor_ != NULL)
{
Translate_context context(gogo, NULL, NULL, NULL);
this->descriptor_->get_tree(&context);
this->descriptor_->get_backend(&context);
}
}
@ -5138,7 +5136,7 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function,
Expression* call = Runtime::make_call(Runtime::CHECK_DEFER, end_loc, 1,
this->defer_stack(end_loc));
Translate_context context(gogo, named_function, NULL, NULL);
Bexpression* defer = tree_to_expr(call->get_tree(&context));
Bexpression* defer = call->get_backend(&context);
stmts.push_back(gogo->backend()->expression_statement(defer));
Bstatement* ret_bstmt = this->return_value(gogo, named_function, end_loc);
@ -5150,11 +5148,11 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function,
call = Runtime::make_call(Runtime::CHECK_DEFER, end_loc, 1,
this->defer_stack(end_loc));
defer = tree_to_expr(call->get_tree(&context));
defer = call->get_backend(&context);
call = Runtime::make_call(Runtime::UNDEFER, end_loc, 1,
this->defer_stack(end_loc));
Bexpression* undefer = tree_to_expr(call->get_tree(&context));
Bexpression* undefer = call->get_backend(&context);
Bstatement* function_defer =
gogo->backend()->function_defer_statement(this->fndecl_, undefer, defer,
end_loc);
@ -5170,13 +5168,12 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function,
// variable to true if we are returning from this function.
ret_bstmt = this->return_value(gogo, named_function, end_loc);
Bexpression* nil =
tree_to_expr(Expression::make_nil(end_loc)->get_tree(&context));
Bexpression* nil = Expression::make_nil(end_loc)->get_backend(&context);
Bexpression* ret =
gogo->backend()->compound_expression(ret_bstmt, nil, end_loc);
Expression* ref =
Expression::make_temporary_reference(this->defer_stack_, end_loc);
Bexpression* bref = tree_to_expr(ref->get_tree(&context));
Bexpression* bref = ref->get_backend(&context);
ret = gogo->backend()->conditional_expression(NULL, bref, ret, NULL,
end_loc);
stmts.push_back(gogo->backend()->expression_statement(ret));
@ -5982,7 +5979,7 @@ Variable::get_init(Gogo* gogo, Named_object* function)
{
Translate_context context(gogo, function, NULL, NULL);
Expression* init = Expression::make_cast(this->type(), this->init_, loc);
return tree_to_expr(init->get_tree(&context));
return init->get_backend(&context);
}
}
@ -6008,8 +6005,7 @@ Variable::get_init_block(Gogo* gogo, Named_object* function,
{
if (var_decl == NULL)
{
Bexpression* init_bexpr =
tree_to_expr(this->init_->get_tree(&context));
Bexpression* init_bexpr = this->init_->get_backend(&context);
decl_init = gogo->backend()->expression_statement(init_bexpr);
}
else
@ -6017,7 +6013,7 @@ Variable::get_init_block(Gogo* gogo, Named_object* function,
Location loc = this->location();
Expression* val_expr =
Expression::make_cast(this->type(), this->init_, loc);
Bexpression* val = tree_to_expr(val_expr->get_tree(&context));
Bexpression* val = val_expr->get_backend(&context);
Bexpression* var_ref = gogo->backend()->var_expression(var_decl, loc);
decl_init = gogo->backend()->assignment_statement(var_ref, val, loc);
}
@ -6241,8 +6237,7 @@ Named_constant::get_backend(Gogo* gogo, Named_object* const_no)
Location loc = this->location();
Expression* const_ref = Expression::make_const_reference(const_no, loc);
Bexpression* const_decl =
tree_to_expr(const_ref->get_tree(&subcontext));
Bexpression* const_decl = const_ref->get_backend(&subcontext);
if (type != NULL && type->is_numeric_type())
{
Btype* btype = type->get_backend(gogo);

View File

@ -1096,7 +1096,7 @@ class Function
Bstatement*
return_value(Gogo*, Named_object*, Location) const;
// Get a tree for the variable holding the defer stack.
// Get an expression for the variable holding the defer stack.
Expression*
defer_stack(Location);

View File

@ -291,12 +291,12 @@ Variable_declaration_statement::do_get_backend(Translate_context* context)
{
Expression* e = Expression::make_temporary_reference(temp, loc);
e = Expression::make_unary(OPERATOR_MULT, e, loc);
Bexpression* be = tree_to_expr(e->get_tree(context));
Bexpression* be = e->get_backend(context);
set = context->backend()->assignment_statement(be, binit, loc);
}
Expression* ref = Expression::make_temporary_reference(temp, loc);
Bexpression* bref = tree_to_expr(ref->get_tree(context));
Bexpression* bref = ref->get_backend(context);
Bstatement* sinit = context->backend()->init_statement(bvar, bref);
std::vector<Bstatement*> stats;
@ -443,13 +443,13 @@ Temporary_statement::do_get_backend(Translate_context* context)
if (this->init_ == NULL)
binit = NULL;
else if (this->type_ == NULL)
binit = tree_to_expr(this->init_->get_tree(context));
binit = this->init_->get_backend(context);
else
{
Expression* init = Expression::make_cast(this->type_, this->init_,
this->location());
context->gogo()->lower_expression(context->function(), NULL, &init);
binit = tree_to_expr(init->get_tree(context));
binit = init->get_backend(context);
}
Bstatement* statement;
@ -633,18 +633,16 @@ Assignment_statement::do_get_backend(Translate_context* context)
{
if (this->lhs_->is_sink_expression())
{
tree rhs_tree = this->rhs_->get_tree(context);
return context->backend()->expression_statement(tree_to_expr(rhs_tree));
Bexpression* rhs = this->rhs_->get_backend(context);
return context->backend()->expression_statement(rhs);
}
tree lhs_tree = this->lhs_->get_tree(context);
Expression* rhs =
Bexpression* lhs = this->lhs_->get_backend(context);
Expression* conv =
Expression::convert_for_assignment(context->gogo(), this->lhs_->type(),
this->rhs_, this->location());
tree rhs_tree = rhs->get_tree(context);
return context->backend()->assignment_statement(tree_to_expr(lhs_tree),
tree_to_expr(rhs_tree),
this->location());
Bexpression* rhs = conv->get_backend(context);
return context->backend()->assignment_statement(lhs, rhs, this->location());
}
// Dump the AST representation for an assignment statement.
@ -1748,8 +1746,8 @@ Expression_statement::do_may_fall_through() const
Bstatement*
Expression_statement::do_get_backend(Translate_context* context)
{
tree expr_tree = this->expr_->get_tree(context);
return context->backend()->expression_statement(tree_to_expr(expr_tree));
Bexpression* bexpr = this->expr_->get_backend(context);
return context->backend()->expression_statement(bexpr);
}
// Dump the AST representation for an expression statement
@ -2537,9 +2535,8 @@ Go_statement::do_get_backend(Translate_context* context)
Expression* call = Runtime::make_call(Runtime::GO, this->location(), 2,
fn, arg);
tree call_tree = call->get_tree(context);
Bexpression* call_bexpr = tree_to_expr(call_tree);
return context->backend()->expression_statement(call_bexpr);
Bexpression* bcall = call->get_backend(context);
return context->backend()->expression_statement(bcall);
}
// Dump the AST representation for go statement.
@ -2576,9 +2573,8 @@ Defer_statement::do_get_backend(Translate_context* context)
Expression* call = Runtime::make_call(Runtime::DEFER, loc, 3,
ds, fn, arg);
tree call_tree = call->get_tree(context);
Bexpression* call_bexpr = tree_to_expr(call_tree);
return context->backend()->expression_statement(call_bexpr);
Bexpression* bcall = call->get_backend(context);
return context->backend()->expression_statement(bcall);
}
// Dump the AST representation for defer statement.
@ -2785,7 +2781,7 @@ Return_statement::do_get_backend(Translate_context* context)
p++)
{
Expression* vr = Expression::make_var_reference(*p, loc);
retvals.push_back(tree_to_expr(vr->get_tree(context)));
retvals.push_back(vr->get_backend(context));
}
}
@ -3201,14 +3197,13 @@ If_statement::do_get_backend(Translate_context* context)
{
go_assert(this->cond_->type()->is_boolean_type()
|| this->cond_->type()->is_error());
tree cond_tree = this->cond_->get_tree(context);
Bexpression* cond_expr = tree_to_expr(cond_tree);
Bexpression* cond = this->cond_->get_backend(context);
Bblock* then_block = this->then_block_->get_backend(context);
Bblock* else_block = (this->else_block_ == NULL
? NULL
: this->else_block_->get_backend(context));
return context->backend()->if_statement(cond_expr, then_block,
else_block, this->location());
return context->backend()->if_statement(cond, then_block, else_block,
this->location());
}
// Dump the AST representation for an if statement
@ -3485,10 +3480,7 @@ Case_clauses::Case_clause::get_backend(Translate_context* context,
error_at(this->location_, "duplicate case in switch");
e = Expression::make_error(this->location_);
}
tree case_tree = e->get_tree(context);
Bexpression* case_expr = tree_to_expr(case_tree);
cases->push_back(case_expr);
cases->push_back(e->get_backend(context));
}
}
@ -3783,8 +3775,7 @@ Constant_switch_statement::do_check_types(Gogo*)
Bstatement*
Constant_switch_statement::do_get_backend(Translate_context* context)
{
tree switch_val_tree = this->val_->get_tree(context);
Bexpression* switch_val_expr = tree_to_expr(switch_val_tree);
Bexpression* switch_val_expr = this->val_->get_backend(context);
Unnamed_label* break_label = this->break_label_;
if (break_label == NULL)
@ -4519,7 +4510,7 @@ Send_statement::do_get_backend(Translate_context* context)
Expression* call = Runtime::make_call(code, loc, 3, td, this->channel_, val);
context->gogo()->lower_expression(context->function(), NULL, &call);
Bexpression* bcall = tree_to_expr(call->get_tree(context));
Bexpression* bcall = call->get_backend(context);
Bstatement* s = context->backend()->expression_statement(bcall);
if (btemp == NULL)
@ -4948,7 +4939,7 @@ Select_clauses::get_backend(Translate_context* context,
Expression* index_expr = Expression::make_integer(&ival, int32_type,
location);
mpz_clear(ival);
cases[i].push_back(tree_to_expr(index_expr->get_tree(context)));
cases[i].push_back(index_expr->get_backend(context));
Bstatement* s = p->get_statements_backend(context);
Location gloc = (p->statements() == NULL
@ -4966,7 +4957,7 @@ Select_clauses::get_backend(Translate_context* context,
Expression* call = Runtime::make_call(Runtime::SELECTGO, location, 1,
selref);
context->gogo()->lower_expression(context->function(), NULL, &call);
Bexpression* bcall = tree_to_expr(call->get_tree(context));
Bexpression* bcall = call->get_backend(context);
if (count == 0)
return context->backend()->expression_statement(bcall);

View File

@ -6,12 +6,6 @@
#include "go-system.h"
#include "toplev.h"
#include "intl.h"
#include "tree.h"
#include "real.h"
#include "convert.h"
#include "go-c.h"
#include "gogo.h"
#include "operator.h"
@ -897,7 +891,7 @@ Type::hash_string(const std::string& s, unsigned int h)
Type::Type_btypes Type::type_btypes;
// Return a tree representing this type.
// Return the backend representation for this type.
Btype*
Type::get_backend(Gogo* gogo)
@ -952,7 +946,7 @@ Type::get_backend(Gogo* gogo)
// We have already created a backend representation for this
// type. This can happen when an unnamed type is defined using
// a named type which in turns uses an identical unnamed type.
// Use the tree we created earlier and ignore the one we just
// Use the representation we created earlier and ignore the one we just
// built.
if (this->btype_ == bt)
this->btype_ = ins.first->second.btype;
@ -1301,7 +1295,7 @@ Type::make_type_descriptor_var(Gogo* gogo)
Translate_context context(gogo, NULL, NULL, NULL);
context.set_is_const();
Bexpression* binitializer = tree_to_expr(initializer->get_tree(&context));
Bexpression* binitializer = initializer->get_backend(&context);
gogo->backend()->immutable_struct_set_init(this->type_descriptor_var_,
var_name, false, is_common,
@ -4936,7 +4930,7 @@ get_backend_struct_fields(Gogo* gogo, const Struct_field_list* fields,
go_assert(i == fields->size());
}
// Get the tree for a struct type.
// Get the backend representation for a struct type.
Btype*
Struct_type::do_get_backend(Gogo* gogo)
@ -5877,9 +5871,9 @@ get_backend_slice_fields(Gogo* gogo, Array_type* type, bool use_placeholder,
p->location = ploc;
}
// Get a tree for the type of this array. A fixed array is simply
// represented as ARRAY_TYPE with the appropriate index--i.e., it is
// just like an array in C. A slice is a struct with three
// Get the backend representation for the type of this array. A fixed array is
// simply represented as ARRAY_TYPE with the appropriate index--i.e., it is
// just like an array in C. An open array is a struct with three
// fields: a data pointer, the length, and the capacity.
Btype*
@ -5943,7 +5937,7 @@ Array_type::get_backend_length(Gogo* gogo)
// Make up a translation context for the array length
// expression. FIXME: This won't work in general.
Translate_context context(gogo, NULL, NULL, NULL);
this->blength_ = tree_to_expr(this->length_->get_tree(&context));
this->blength_ = this->length_->get_backend(&context);
Btype* ibtype = Type::lookup_integer_type("int")->get_backend(gogo);
this->blength_ =
@ -6466,7 +6460,7 @@ Map_type::map_descriptor(Gogo* gogo)
Translate_context context(gogo, NULL, NULL, NULL);
context.set_is_const();
Bexpression* binitializer = tree_to_expr(initializer->get_tree(&context));
Bexpression* binitializer = initializer->get_backend(&context);
gogo->backend()->immutable_struct_set_init(bvar, mangled_name, false, true,
map_descriptor_btype, bloc,
@ -6581,8 +6575,8 @@ Channel_type::is_identical(const Channel_type* t,
&& this->may_receive_ == t->may_receive_);
}
// Return the tree for a channel type. A channel is a pointer to a
// __go_channel struct. The __go_channel struct is defined in
// Return the backend representation for a channel type. A channel is a pointer
// to a __go_channel struct. The __go_channel struct is defined in
// libgo/runtime/channel.h.
Btype*
@ -7364,8 +7358,8 @@ get_backend_interface_fields(Gogo* gogo, Interface_type* type,
(*bfields)[1].location = Linemap::predeclared_location();
}
// Return a tree for an interface type. An interface is a pointer to
// a struct. The struct has three fields. The first field is a
// Return the backend representation for an interface type. An interface is a
// pointer to a struct. The struct has three fields. The first field is a
// pointer to the type descriptor for the dynamic type of the object.
// The second field is a pointer to a table of methods for the
// interface to be used with the object. The third field is the value
@ -8416,7 +8410,7 @@ Named_type::convert(Gogo* gogo)
this->verify();
// Convert all the dependencies. If they refer indirectly back to
// this type, they will pick up the intermediate tree we just
// this type, they will pick up the intermediate representation we just
// created.
for (std::vector<Named_type*>::const_iterator p = this->dependencies_.begin();
p != this->dependencies_.end();
@ -8612,7 +8606,7 @@ Named_type::create_placeholder(Gogo* gogo)
}
}
// Get a tree for a named type.
// Get the backend representation for a named type.
Btype*
Named_type::do_get_backend(Gogo* gogo)
@ -8648,7 +8642,7 @@ Named_type::do_get_backend(Gogo* gogo)
go_assert(bt != NULL);
// Complete the tree.
// Complete the backend representation.
Type* base = this->type_->base();
Btype* bt1;
switch (base->classification())

View File

@ -1168,9 +1168,6 @@ class Type
method_constructor(Gogo*, Type* method_type, const std::string& name,
const Method*, bool only_value_methods) const;
static tree
build_receive_return_type(tree type);
// Add all methods for TYPE to the list of methods for THIS.
static void
add_methods_for_type(const Type* type, const Method::Field_indexes*,
@ -2755,9 +2752,9 @@ class Interface_type : public Type
};
// The value we keep for a named type. This lets us get the right
// name when we convert to trees. Note that we don't actually keep
// name when we convert to backend. Note that we don't actually keep
// the name here; the name is in the Named_object which points to
// this. This object exists to hold a unique tree which represents
// this. This object exists to hold a unique backend representation for
// the type.
class Named_type : public Type