Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(978)

Unified Diff: runtime/vm/resolver.cc

Issue 1234883005: Implement tear-off closure operator # (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address review comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/resolver.cc
diff --git a/runtime/vm/resolver.cc b/runtime/vm/resolver.cc
index 954f34076d069794050032ec65bd8c87f0e6a889..0eb295bca3a808bcc7f064b548dd163af7c87e51 100644
--- a/runtime/vm/resolver.cc
+++ b/runtime/vm/resolver.cc
@@ -114,6 +114,43 @@ RawFunction* Resolver::ResolveDynamicAnyArgs(
String& field_name = String::Handle();
if (is_getter) {
field_name ^= Field::NameFromGetter(function_name);
+
+ if (field_name.CharAt(0) == '#') {
+ // Resolving a getter "get:#..." is a request to closurize an instance
+ // property of the receiver object. It can be of the form:
+ // - get:#id, which closurizes a method or getter id
+ // - get:#set:id, which closurizes a setter id
+ // - get:#operator, eg. get:#<<, which closurizes an operator method.
+ // If the property can be resolved, a method extractor function
+ // "get:#..." is created and injected into the receiver's class.
+ String& property_name = String::Handle(String::SubString(field_name, 1));
+ ASSERT(!Field::IsGetterName(property_name));
+
+ String& property_getter_name = String::Handle();
+ if (!Field::IsSetterName(property_name)) {
+ // If this is not a setter, we need to look for both the regular
+ // name and the getter name. (In the case of an operator, this
+ // code will also try to resolve for example get:<< and will fail,
+ // but that's harmless.)
+ property_getter_name = Field::GetterName(property_name);
+ }
+
+ Function& function = Function::Handle();
+ while (!cls.IsNull()) {
+ function = cls.LookupDynamicFunction(property_name);
+ if (!function.IsNull()) {
+ return CreateMethodExtractor(function_name, function);
+ }
+ if (!property_getter_name.IsNull()) {
+ function = cls.LookupDynamicFunction(property_getter_name);
+ if (!function.IsNull()) {
+ return CreateMethodExtractor(function_name, function);
+ }
+ }
+ cls = cls.SuperClass();
+ }
+ return Function::null();
+ }
}
// Now look for an instance function whose name matches function_name
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698