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

Side by Side Diff: dart/lib/compiler/implementation/compiler.dart

Issue 10441014: Parameterize WorkItem.run. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 7 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
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 bool allowSpeculativeOptimization = true; 8 bool allowSpeculativeOptimization = true;
9 List<HTypeGuard> guards = const <HTypeGuard>[]; 9 List<HTypeGuard> guards = const <HTypeGuard>[];
10 10
11 WorkItem(this.element, this.resolutionTree); 11 WorkItem(this.element, this.resolutionTree);
12 12
13 bool isAnalyzed() => resolutionTree !== null; 13 bool isAnalyzed() => resolutionTree !== null;
14 14
15 int hashCode() => element.hashCode(); 15 String run(Compiler compiler, Enqueuer world) {
16 16 String code = world.universe.generatedCode[element];
17 String run(Compiler compiler) {
18 String code = compiler.codegenWorld.generatedCode[element];
19 if (code !== null) return code; 17 if (code !== null) return code;
20 try { 18 if (!isAnalyzed()) compiler.analyze(this);
21 if (!isAnalyzed()) compiler.analyze(this); 19 return compiler.codegen(this);
22 return compiler.codegen(this);
23 } catch (CompilerCancelledException ex) {
24 throw;
25 } catch (var ex) {
26 compiler.unhandledExceptionOnElement(element);
27 throw;
28 }
29 } 20 }
30 } 21 }
31 22
32 class Backend { 23 class Backend {
33 final Compiler compiler; 24 final Compiler compiler;
34 25
35 Backend(this.compiler); 26 Backend(this.compiler);
36 27
37 abstract String codegen(WorkItem work); 28 abstract String codegen(WorkItem work);
38 abstract void processNativeClasses(world, libraries); 29 abstract void processNativeClasses(world, libraries);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 ClassElement functionClass; 99 ClassElement functionClass;
109 ClassElement nullClass; 100 ClassElement nullClass;
110 ClassElement listClass; 101 ClassElement listClass;
111 102
112 Element get currentElement() => _currentElement; 103 Element get currentElement() => _currentElement;
113 withCurrentElement(Element element, f()) { 104 withCurrentElement(Element element, f()) {
114 Element old = currentElement; 105 Element old = currentElement;
115 _currentElement = element; 106 _currentElement = element;
116 try { 107 try {
117 return f(); 108 return f();
109 } catch (CompilerCancelledException ex) {
110 throw;
111 } catch (var ex) {
112 unhandledExceptionOnElement(element);
113 throw;
118 } finally { 114 } finally {
119 _currentElement = old; 115 _currentElement = old;
120 } 116 }
121 } 117 }
122 118
123 List<CompilerTask> tasks; 119 List<CompilerTask> tasks;
124 ScannerTask scanner; 120 ScannerTask scanner;
125 DietParserTask dietParser; 121 DietParserTask dietParser;
126 ParserTask parser; 122 ParserTask parser;
127 TreeValidatorTask validator; 123 TreeValidatorTask validator;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 "work list is not empty"); 367 "work list is not empty");
372 } 368 }
373 } 369 }
374 370
375 processQueue(Enqueuer world, Element main) { 371 processQueue(Enqueuer world, Element main) {
376 backend.processNativeClasses(world, libraries.getValues()); 372 backend.processNativeClasses(world, libraries.getValues());
377 world.addToWorkList(main); 373 world.addToWorkList(main);
378 codegenProgress.reset(); 374 codegenProgress.reset();
379 while (!world.queue.isEmpty()) { 375 while (!world.queue.isEmpty()) {
380 WorkItem work = world.queue.removeLast(); 376 WorkItem work = world.queue.removeLast();
381 withCurrentElement(work.element, () => work.run(this)); 377 withCurrentElement(work.element, () => work.run(this, world));
382 } 378 }
383 world.queueIsClosed = true; 379 world.queueIsClosed = true;
384 assert(world.checkNoEnqueuedInvokedInstanceMethods()); 380 assert(world.checkNoEnqueuedInvokedInstanceMethods());
385 world.registerFieldClosureInvocations(); 381 world.registerFieldClosureInvocations();
386 } 382 }
387 383
388 TreeElements analyzeElement(Element element) { 384 TreeElements analyzeElement(Element element) {
389 assert(parser !== null); 385 assert(parser !== null);
390 Node tree = parser.parse(element); 386 Node tree = parser.parse(element);
391 validator.validate(tree); 387 validator.validate(tree);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // invariant that endOffset > beginOffset, but for EOF the 574 // invariant that endOffset > beginOffset, but for EOF the
579 // charoffset of the next token may be [beginOffset]. This can 575 // charoffset of the next token may be [beginOffset]. This can
580 // also happen for synthetized tokens that are produced during 576 // also happen for synthetized tokens that are produced during
581 // error handling. 577 // error handling.
582 final endOffset = 578 final endOffset =
583 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); 579 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1);
584 assert(endOffset > beginOffset); 580 assert(endOffset > beginOffset);
585 return f(beginOffset, endOffset); 581 return f(beginOffset, endOffset);
586 } 582 }
587 } 583 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698