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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/resolver.h" 5 #include "vm/resolver.h"
6 6
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (FLAG_trace_resolving) { 107 if (FLAG_trace_resolving) {
108 OS::Print("ResolveDynamic '%s' for class %s\n", 108 OS::Print("ResolveDynamic '%s' for class %s\n",
109 function_name.ToCString(), 109 function_name.ToCString(),
110 String::Handle(cls.Name()).ToCString()); 110 String::Handle(cls.Name()).ToCString());
111 } 111 }
112 112
113 const bool is_getter = Field::IsGetterName(function_name); 113 const bool is_getter = Field::IsGetterName(function_name);
114 String& field_name = String::Handle(); 114 String& field_name = String::Handle();
115 if (is_getter) { 115 if (is_getter) {
116 field_name ^= Field::NameFromGetter(function_name); 116 field_name ^= Field::NameFromGetter(function_name);
117
118 if (field_name.CharAt(0) == '#') {
119 // Resolving a getter "get:#..." is a request to closurize an instance
120 // property of the receiver object. It can be of the form:
121 // - get:#id, which closurizes a method or getter id
122 // - get:#set:id, which closurizes a setter id
123 // - get:#operator, eg. get:#<<, which closurizes an operator method.
124 // If the property can be resolved, a method extractor function
125 // "get:#..." is created and injected into the receiver's class.
126 String& property_name = String::Handle(String::SubString(field_name, 1));
127 ASSERT(!Field::IsGetterName(property_name));
128
129 String& property_getter_name = String::Handle();
130 if (!Field::IsSetterName(property_name)) {
131 // If this is not a setter, we need to look for both the regular
132 // name and the getter name. (In the case of an operator, this
133 // code will also try to resolve for example get:<< and will fail,
134 // but that's harmless.)
135 property_getter_name = Field::GetterName(property_name);
136 }
137
138 Function& function = Function::Handle();
139 while (!cls.IsNull()) {
140 function = cls.LookupDynamicFunction(property_name);
141 if (!function.IsNull()) {
142 return CreateMethodExtractor(function_name, function);
143 }
144 if (!property_getter_name.IsNull()) {
145 function = cls.LookupDynamicFunction(property_getter_name);
146 if (!function.IsNull()) {
147 return CreateMethodExtractor(function_name, function);
148 }
149 }
150 cls = cls.SuperClass();
151 }
152 return Function::null();
153 }
117 } 154 }
118 155
119 // Now look for an instance function whose name matches function_name 156 // Now look for an instance function whose name matches function_name
120 // in the class. 157 // in the class.
121 Function& function = Function::Handle(); 158 Function& function = Function::Handle();
122 while (!cls.IsNull()) { 159 while (!cls.IsNull()) {
123 function ^= cls.LookupDynamicFunction(function_name); 160 function ^= cls.LookupDynamicFunction(function_name);
124 if (!function.IsNull()) { 161 if (!function.IsNull()) {
125 return function.raw(); 162 return function.raw();
126 } 163 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 OS::Print("ResolveStaticAllowPrivate error '%s': %s.\n", 288 OS::Print("ResolveStaticAllowPrivate error '%s': %s.\n",
252 function_name.ToCString(), 289 function_name.ToCString(),
253 error_message.ToCString()); 290 error_message.ToCString());
254 } 291 }
255 return Function::null(); 292 return Function::null();
256 } 293 }
257 return function.raw(); 294 return function.raw();
258 } 295 }
259 296
260 } // namespace dart 297 } // namespace dart
OLDNEW
« 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