diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-04-26 20:37:58 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-04-26 20:37:58 +0000 |
commit | b0c0971248103432dd623276227da9cd69a755cf (patch) | |
tree | 9037b628a43dc83bd08039aa7677c78fda77f011 /gcc/go/gofrontend/parse.cc | |
parent | b6ef185e33cfd9883120b940b102ebc8d3e37761 (diff) | |
download | gcc-b0c0971248103432dd623276227da9cd69a755cf.tar.gz |
compiler: Add Enclosed_var_expression.
Introduces an abstraction for a variable referenced in a closure.
This maintains the underlying expression which accesses a field within
a closure variable and gives easy access to the underlying
Named_object.
Reviewed-on: https://go-review.googlesource.com/22374
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235452 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/go/gofrontend/parse.cc')
-rw-r--r-- | gcc/go/gofrontend/parse.cc | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index 827eb0a120a..c96ae1dacec 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -2658,7 +2658,7 @@ Parse::enclosing_var_reference(Named_object* in_function, Named_object* var, ins.first->index(), location); e = Expression::make_unary(OPERATOR_MULT, e, location); - return e; + return Expression::make_enclosing_var_reference(e, var, location); } // CompositeLit = LiteralType LiteralValue . @@ -5791,24 +5791,10 @@ Parse::verify_not_sink(Expression* expr) // If this can not be a sink, and it is a variable, then we are // using the variable, not just assigning to it. - Var_expression* ve = expr->var_expression(); - if (ve != NULL) - this->mark_var_used(ve->named_object()); - else if (expr->deref()->field_reference_expression() != NULL - && this->gogo_->current_function() != NULL) - { - // We could be looking at a variable referenced from a closure. - // If so, we need to get the enclosed variable and mark it as used. - Function* this_function = this->gogo_->current_function()->func_value(); - Named_object* closure = this_function->closure_var(); - if (closure != NULL) - { - unsigned int var_index = - expr->deref()->field_reference_expression()->field_index(); - this->mark_var_used(this_function->enclosing_var(var_index - 1)); - } - } - + if (expr->var_expression() != NULL) + this->mark_var_used(expr->var_expression()->named_object()); + else if (expr->enclosed_var_expression() != NULL) + this->mark_var_used(expr->enclosed_var_expression()->variable()); return expr; } |