Bound_method_expression::Method_value_thunks
Bound_method_expression::method_value_thunks;
-// Find or create the thunk for METHOD.
+// Find or create the thunk for FN.
Named_object*
Bound_method_expression::create_thunk(Gogo* gogo, const Method* method,
gogo->add_statement(s);
Block* b = gogo->finish_block(loc);
gogo->add_block(b, loc);
+
+ // This is called after lowering but before determine_types.
gogo->lower_block(new_no, b);
- gogo->flatten_block(new_no, b);
+
gogo->finish_function(loc);
ins.first->second = new_no;
return new_no;
}
+// Look up a thunk for FN.
+
+Named_object*
+Bound_method_expression::lookup_thunk(Named_object* fn)
+{
+ Method_value_thunks::const_iterator p =
+ Bound_method_expression::method_value_thunks.find(fn);
+ if (p == Bound_method_expression::method_value_thunks.end())
+ return NULL;
+ return p->second;
+}
+
// Return an expression to check *REF for nil while dereferencing
// according to FIELD_INDEXES. Update *REF to build up the field
// reference. This is a static function so that we don't have to
{
Location loc = this->location();
- Named_object* thunk = Bound_method_expression::create_thunk(gogo,
- this->method_,
- this->function_);
- if (thunk->is_erroneous())
+ Named_object* thunk = Bound_method_expression::lookup_thunk(this->function_);
+
+ // The thunk should have been created during the
+ // create_function_descriptors pass.
+ if (thunk == NULL || thunk->is_erroneous())
{
go_assert(saw_errors());
return Expression::make_error(loc);
gogo->add_statement(s);
Block* b = gogo->finish_block(loc);
gogo->add_block(b, loc);
+
+ // This is called after lowering but before determine_types.
gogo->lower_block(new_no, b);
- gogo->flatten_block(new_no, b);
+
gogo->finish_function(loc);
ins.first->second->push_back(std::make_pair(name, new_no));
return new_no;
}
+// Lookup a thunk to call method NAME on TYPE.
+
+Named_object*
+Interface_field_reference_expression::lookup_thunk(Interface_type* type,
+ const std::string& name)
+{
+ Interface_method_thunks::const_iterator p =
+ Interface_field_reference_expression::interface_method_thunks.find(type);
+ if (p == Interface_field_reference_expression::interface_method_thunks.end())
+ return NULL;
+ for (Method_thunks::const_iterator pm = p->second->begin();
+ pm != p->second->end();
+ ++pm)
+ if (pm->first == name)
+ return pm->second;
+ return NULL;
+}
+
// Get the backend representation for a method value.
Bexpression*
}
Named_object* thunk =
- Interface_field_reference_expression::create_thunk(context->gogo(),
- type, this->name_);
- if (thunk->is_erroneous())
+ Interface_field_reference_expression::lookup_thunk(type, this->name_);
+
+ // The thunk should have been created during the
+ // create_function_descriptors pass.
+ if (thunk == NULL || thunk->is_erroneous())
{
go_assert(saw_errors());
return context->backend()->error_expression();