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

Side by Side Diff: frog/leg/compiler.dart

Issue 9414010: Allow method-calls to getters (assuming they contain closures). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cosmetic changes (comments). Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | frog/leg/emitter.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class WorkItem { 5 class WorkItem {
6 final Element element; 6 final Element element;
7 TreeElements resolutionTree; 7 TreeElements resolutionTree;
8 Function run; 8 Function run;
9 Map<int, BailoutInfo> bailouts = null; 9 Map<int, BailoutInfo> bailouts = null;
10 bool allowSpeculativeOptimization = true; 10 bool allowSpeculativeOptimization = true;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 library.define(new ForeignElement( 179 library.define(new ForeignElement(
180 const SourceString('JS'), library), this); 180 const SourceString('JS'), library), this);
181 library.define(new ForeignElement( 181 library.define(new ForeignElement(
182 const SourceString('UNINTERCEPTED'), library), this); 182 const SourceString('UNINTERCEPTED'), library), this);
183 library.define(new ForeignElement( 183 library.define(new ForeignElement(
184 const SourceString('JS_HAS_EQUALS'), library), this); 184 const SourceString('JS_HAS_EQUALS'), library), this);
185 } 185 }
186 186
187 void enqueueInvokedInstanceMethods() { 187 void enqueueInvokedInstanceMethods() {
188 // TODO(floitsch): find a more efficient way of doing this. 188 // TODO(floitsch): find a more efficient way of doing this.
189
189 // Run through the classes and see if we need to compile methods. 190 // Run through the classes and see if we need to compile methods.
190 for (ClassElement classElement in universe.instantiatedClasses) { 191 for (ClassElement classElement in universe.instantiatedClasses) {
191 for (ClassElement currentClass = classElement; 192 for (ClassElement currentClass = classElement;
192 currentClass !== null; 193 currentClass !== null;
193 currentClass = currentClass.superclass) { 194 currentClass = currentClass.superclass) {
194 // TODO(floitsch): we don't need to add members that have been 195 // TODO(floitsch): we don't need to add members that have been
195 // overwritten by subclasses. 196 // overwritten by subclasses.
196 for (Element member in currentClass.members) { 197 for (Element member in currentClass.members) {
197 if (universe.generatedCode[member] !== null) continue; 198 if (universe.generatedCode[member] !== null) continue;
198 if (!member.isInstanceMember()) continue; 199 if (!member.isInstanceMember()) continue;
199 if (member.kind == ElementKind.FUNCTION) { 200 if (member.kind == ElementKind.FUNCTION) {
200 Set<Selector> selectors = universe.invokedNames[member.name]; 201 Set<Selector> selectors = universe.invokedNames[member.name];
201 if (selectors != null) { 202 if (selectors != null) {
202 for (Selector selector in selectors) { 203 for (Selector selector in selectors) {
203 if (selector.applies(this, member)) { 204 if (selector.applies(this, member)) {
204 addToWorklist(member); 205 addToWorklist(member);
205 break; 206 break;
206 } 207 }
207 } 208 }
208 } 209 }
209 // If there is a property access with the same name as a method we 210 // If there is a property access with the same name as a method we
210 // need to emit the method. 211 // need to emit the method.
211 if (universe.invokedGetters.contains(member.name)) { 212 if (universe.invokedGetters.contains(member.name)) {
212 addToWorklist(member); 213 addToWorklist(member);
213 } 214 }
214 } else if (member.kind == ElementKind.GETTER) { 215 } else if (member.kind == ElementKind.GETTER) {
215 if (universe.invokedGetters.contains(member.name)) { 216 if (universe.invokedGetters.contains(member.name)) {
216 addToWorklist(member); 217 addToWorklist(member);
217 } 218 }
219 // A method invocation like in o.foo(x, y) might actually be an
220 // invocation of the getter foo followed an invocation of the
ngeoffray 2012/02/17 10:19:26 followed by
floitsch 2012/02/17 13:19:32 Done.
221 // returned closure.
222 Set<Selector> invokedSelectors = universe.invokedNames[member.name];
223 if (invokedSelectors !== null && !invokedSelectors.isEmpty()) {
ngeoffray 2012/02/17 10:19:26 Please add a comment that you cannot know if the s
floitsch 2012/02/17 13:19:32 Done.
224 addToWorklist(member);
225 }
218 } else if (member.kind === ElementKind.SETTER) { 226 } else if (member.kind === ElementKind.SETTER) {
219 if (universe.invokedSetters.contains(member.name)) { 227 if (universe.invokedSetters.contains(member.name)) {
220 addToWorklist(member); 228 addToWorklist(member);
221 } 229 }
222 } 230 }
231
232 // Make sure that the closure understands a call with the given
233 // selector. For a method-invocation of the form o.foo(a: 499), we
234 // need to make sure that closures can handle the optional argument if
235 // there exists a field or getter 'foo'.
236 if (member.kind === ElementKind.GETTER ||
237 member.kind === ElementKind.FIELD) {
238 Set<Selector> invokedSelectors = universe.invokedNames[member.name];
239 if (invokedSelectors != null) {
240 for (Selector selector in invokedSelectors) {
241 registerDynamicInvocation(Namer.CLOSURE_INVOCATION_NAME,
242 selector);
243 }
244 }
245 }
223 } 246 }
224 } 247 }
225 } 248 }
226 } 249 }
227 250
228 void runCompiler(Script script) { 251 void runCompiler(Script script) {
229 scanBuiltinLibraries(); 252 scanBuiltinLibraries();
230 mainApp = new LibraryElement(script); 253 mainApp = new LibraryElement(script);
231 Element element; 254 Element element;
232 withCurrentElement(mainApp, () { 255 withCurrentElement(mainApp, () {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 397
375 class CompilerCancelledException implements Exception { 398 class CompilerCancelledException implements Exception {
376 final String reason; 399 final String reason;
377 CompilerCancelledException(this.reason); 400 CompilerCancelledException(this.reason);
378 401
379 String toString() { 402 String toString() {
380 String banner = 'compiler cancelled'; 403 String banner = 'compiler cancelled';
381 return (reason !== null) ? '$banner: $reason' : '$banner'; 404 return (reason !== null) ? '$banner: $reason' : '$banner';
382 } 405 }
383 } 406 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | frog/leg/emitter.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698