go_unreachable();
Bexpression* ret =
- context->backend()->var_expression(bvar, this->in_lvalue_pos_, loc);
+ context->backend()->var_expression(bvar, loc);
if (is_in_heap)
ret = context->backend()->indirect_expression(btype, ret, true, loc);
return ret;
{
Gogo* gogo = context->gogo();
Bvariable* bvar = this->statement_->get_backend_variable(context);
- Varexpr_context ve_ctxt = (this->is_lvalue_ ? VE_lvalue : VE_rvalue);
-
- Bexpression* ret = gogo->backend()->var_expression(bvar, ve_ctxt,
- this->location());
+ Bexpression* ret = gogo->backend()->var_expression(bvar, this->location());
// The backend can't always represent the same set of recursive types
// that the Go frontend can. In some cases this means that a
Location loc = this->location();
Gogo* gogo = context->gogo();
Bvariable* bvar = this->statement_->get_backend_variable(context);
- Bexpression* lvar_ref = gogo->backend()->var_expression(bvar, VE_lvalue, loc);
+ Bexpression* lvar_ref = gogo->backend()->var_expression(bvar, loc);
Named_object* fn = context->function();
go_assert(fn != NULL);
Bexpression* bexpr = this->expr_->get_backend(context);
Bstatement* set = gogo->backend()->assignment_statement(bfn, lvar_ref,
bexpr, loc);
- Bexpression* var_ref = gogo->backend()->var_expression(bvar, VE_rvalue, loc);
+ Bexpression* var_ref = gogo->backend()->var_expression(bvar, loc);
Bexpression* ret = gogo->backend()->compound_expression(set, var_ref, loc);
return ret;
}
gogo->backend()->temporary_variable(fn_ctx, context->bblock(), bt, NULL,
false, loc, &decl);
Bexpression* var_ref =
- gogo->backend()->var_expression(this->bvar_, VE_lvalue, loc);
+ gogo->backend()->var_expression(this->bvar_, loc);
var_ref = gogo->backend()->compound_expression(decl, var_ref, loc);
return var_ref;
}
- return gogo->backend()->var_expression(this->bvar_, VE_lvalue, loc);
+ return gogo->backend()->var_expression(this->bvar_, loc);
}
// Ast dump for sink expression.
Named_object* no = this->fn_;
Location loc = no->location();
if (this->dvar_ != NULL)
- return context->backend()->var_expression(this->dvar_, VE_rvalue, loc);
+ return context->backend()->var_expression(this->dvar_, loc);
Gogo* gogo = context->gogo();
std::string var_name(gogo->function_descriptor_name(no));
}
this->dvar_ = bvar;
- return gogo->backend()->var_expression(bvar, VE_rvalue, loc);
+ return gogo->backend()->var_expression(bvar, loc);
}
// Print a function descriptor expression.
Temporary_statement* temp = sut->temporary();
Bvariable* bvar = temp->get_backend_variable(context);
Bexpression* bvar_expr =
- gogo->backend()->var_expression(bvar, VE_lvalue, loc);
+ gogo->backend()->var_expression(bvar, loc);
Bexpression* bval = sut->expression()->get_backend(context);
Named_object* fn = context->function();
gogo->backend()->implicit_variable_set_init(implicit, var_name, btype,
true, copy_to_heap, false,
bexpr);
- bexpr = gogo->backend()->var_expression(implicit, VE_rvalue, loc);
+ bexpr = gogo->backend()->var_expression(implicit, loc);
// If we are not copying a slice initializer to the heap,
// then it can be changed by the program, so if it can
&& this->expr_->type()->has_pointer())
{
Bexpression* root =
- gogo->backend()->var_expression(implicit, VE_rvalue, loc);
+ gogo->backend()->var_expression(implicit, loc);
root = gogo->backend()->address_expression(root, loc);
Type* type = Type::make_pointer_type(this->expr_->type());
gogo->add_gc_root(Expression::make_backend(root, type, loc));
true, false, btype, loc);
gogo->backend()->immutable_struct_set_init(decl, var_name, true,
false, btype, loc, bexpr);
- bexpr = gogo->backend()->var_expression(decl, VE_rvalue, loc);
+ bexpr = gogo->backend()->var_expression(decl, loc);
}
go_assert(!this->create_temp_ || this->expr_->is_variable());
Bstatement* assn;
if (!etype->has_pointer())
{
- space = gogo->backend()->var_expression(space_temp, VE_lvalue, loc);
+ space = gogo->backend()->var_expression(space_temp, loc);
Bexpression* ref =
gogo->backend()->indirect_expression(expr_btype, space, true, loc);
assn = gogo->backend()->assignment_statement(fndecl, ref, bexpr, loc);
expr_btype, bexpr, true, loc,
&edecl);
Bexpression* btempref = gogo->backend()->var_expression(btemp,
- VE_lvalue, loc);
+ loc);
Bexpression* addr = gogo->backend()->address_expression(btempref, loc);
Expression* td = Expression::make_type_descriptor(etype, loc);
Type* etype_ptr = Type::make_pointer_type(etype);
- space = gogo->backend()->var_expression(space_temp, VE_rvalue, loc);
+ space = gogo->backend()->var_expression(space_temp, loc);
Expression* elhs = Expression::make_backend(space, etype_ptr, loc);
Expression* erhs = Expression::make_backend(addr, etype_ptr, loc);
Expression* call = Runtime::make_call(Runtime::TYPEDMEMMOVE, loc, 3,
assn = gogo->backend()->compound_statement(edecl, s);
}
decl = gogo->backend()->compound_statement(decl, assn);
- space = gogo->backend()->var_expression(space_temp, VE_rvalue, loc);
+ space = gogo->backend()->var_expression(space_temp, loc);
return gogo->backend()->compound_expression(decl, space, loc);
}
Bvariable* bvar = this->type_->gc_ptrmask_var(gogo, ptrsize, ptrdata);
Location bloc = Linemap::predeclared_location();
- Bexpression* bref = gogo->backend()->var_expression(bvar, VE_rvalue, bloc);
+ Bexpression* bref = gogo->backend()->var_expression(bvar, bloc);
Bexpression* baddr = gogo->backend()->address_expression(bref, bloc);
Type* uint8_type = Type::lookup_integer_type("uint8");
Gogo* gogo = context->gogo();
Location loc = Linemap::predeclared_location();
if (this->bvar_ != NULL)
- return gogo->backend()->var_expression(this->bvar_, VE_rvalue,
- this->location());
+ return gogo->backend()->var_expression(this->bvar_, this->location());
const Typed_identifier_list* interface_methods = this->itype_->methods();
go_assert(!interface_methods->empty());
this->bvar_ =
gogo->backend()->immutable_struct_reference(mangled_name, asm_name,
btype, loc);
- return gogo->backend()->var_expression(this->bvar_, VE_rvalue,
- this->location());
+ return gogo->backend()->var_expression(this->bvar_, this->location());
}
// The first element is the type descriptor.
!is_public, btype, loc);
gogo->backend()->immutable_struct_set_init(this->bvar_, mangled_name, false,
!is_public, btype, loc, ctor);
- return gogo->backend()->var_expression(this->bvar_, VE_lvalue, loc);
+ return gogo->backend()->var_expression(this->bvar_, loc);
}
void
return this;
}
-
-// Helper class to locate a root Var_expression within an expression
-// tree and mark it as being in an "lvalue" or assignment
-// context. Examples:
-//
-// x, y = 40, foo(w)
-// x[2] = bar(v)
-// x.z.w[blah(v + u)], y.another = 2, 3
-//
-// In the code above, vars "x" and "y" appear in lvalue / assignment
-// context, whereas the other vars "v", "u", etc are in rvalue context.
-//
-// Note: at the moment the Var_expression version of "do_copy()"
-// defaults to returning the original object, not a new object,
-// meaning that a given Var_expression can be referenced from more
-// than one place in the tree. This means that when we want to mark a
-// Var_expression as having lvalue semantics, we need to make a copy
-// of it. Example:
-//
-// mystruct.myfield += 42
-//
-// When this is lowered to eliminate the += operator, we get a tree
-//
-// mystruct.myfield = mystruct.field + 42
-//
-// in which the "mystruct" same Var_expression is referenced on both
-// LHS and RHS subtrees. This in turn means that if we try to mark the
-// LHS Var_expression the RHS Var_expression will also be marked. To
-// address this issue, the code below clones any var_expression before
-// applying an lvalue marking.
-//
-
-class Mark_lvalue_varexprs : public Traverse
-{
- public:
- Mark_lvalue_varexprs()
- : Traverse(traverse_expressions)
- { }
-
- protected:
- int
- expression(Expression**);
-
- private:
-};
-
-int Mark_lvalue_varexprs::expression(Expression** ppexpr)
-{
- Expression* e = *ppexpr;
-
- Var_expression* ve = e->var_expression();
- if (ve)
- {
- ve = new Var_expression(ve->named_object(), ve->location());
- ve->set_in_lvalue_pos();
- *ppexpr = ve;
- return TRAVERSE_EXIT;
- }
-
- Field_reference_expression* fre = e->field_reference_expression();
- if (fre != NULL)
- return TRAVERSE_CONTINUE;
-
- Array_index_expression* aie = e->array_index_expression();
- if (aie != NULL)
- {
- Mark_lvalue_varexprs mlve;
- aie->set_is_lvalue();
- aie->array()->traverse_subexpressions(&mlve);
- return TRAVERSE_EXIT;
- }
-
- Unary_expression* ue = e->unary_expression();
- if (ue && ue->op() == OPERATOR_MULT)
- return TRAVERSE_CONTINUE;
-
- Type_conversion_expression* ce = e->conversion_expression();
- if (ce)
- return TRAVERSE_CONTINUE;
-
- Temporary_reference_expression* tre =
- e->temporary_reference_expression();
- if (tre)
- {
- tre = new Temporary_reference_expression(tre->statement(),
- tre->location());
- *ppexpr = tre;
- tre->set_is_lvalue();
- return TRAVERSE_EXIT;
- }
-
- return TRAVERSE_EXIT;
-}
-
// Convert an assignment statement to the backend representation.
Bstatement*
return context->backend()->expression_statement(bfunction, rhs);
}
- Mark_lvalue_varexprs mlve;
- Expression::traverse(&this->lhs_, &mlve);
-
Bexpression* lhs = this->lhs_->get_backend(context);
Expression* conv =
Expression::convert_for_assignment(context->gogo(), this->lhs_->type(),