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

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

Issue 10584009: Refactor the collection of initializer list types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Moved data structures to backend Created 8 years, 6 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 | lib/compiler/implementation/enqueue.dart » ('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) 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 5
6 /** 6 /**
7 * If true, print a warning for each method that was resolved, but not 7 * If true, print a warning for each method that was resolved, but not
8 * compiled. 8 * compiled.
9 */ 9 */
10 final bool REPORT_EXCESS_RESOLUTION = false; 10 final bool REPORT_EXCESS_RESOLUTION = false;
(...skipping 16 matching lines...) Expand all
27 String run(Compiler compiler, Enqueuer world) { 27 String run(Compiler compiler, Enqueuer world) {
28 String code = world.universe.generatedCode[element]; 28 String code = world.universe.generatedCode[element];
29 if (code !== null) return code; 29 if (code !== null) return code;
30 resolutionTree = compiler.analyze(this, world); 30 resolutionTree = compiler.analyze(this, world);
31 return compiler.codegen(this, world); 31 return compiler.codegen(this, world);
32 } 32 }
33 } 33 }
34 34
35 class Backend { 35 class Backend {
36 final Compiler compiler; 36 final Compiler compiler;
37 final Map<Element, Map<SourceString, HType>> fieldInitializers;
karlklose 2012/06/19 15:07:40 Why not move these datastructures to the JavaScrip
38 final Map<Element, Map<SourceString, bool>> fieldIntegerSetters;
37 39
38 Backend(this.compiler); 40 Backend(this.compiler)
41 : fieldInitializers = new Map<Element, Map<SourceString, HType>>(),
42 fieldIntegerSetters = new Map<Element, Map<SourceString, bool>>();
39 43
40 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { 44 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) {
41 lib.forEachExport((Element e) { 45 lib.forEachExport((Element e) {
42 if (e.isFunction()) world.addToWorkList(e); 46 if (e.isFunction()) world.addToWorkList(e);
43 }); 47 });
44 } 48 }
45 49
46 abstract void enqueueHelpers(Enqueuer world); 50 abstract void enqueueHelpers(Enqueuer world);
47 abstract String codegen(WorkItem work); 51 abstract String codegen(WorkItem work);
48 abstract void processNativeClasses(Enqueuer world, 52 abstract void processNativeClasses(Enqueuer world,
49 Collection<LibraryElement> libraries); 53 Collection<LibraryElement> libraries);
50 abstract void assembleProgram(); 54 abstract void assembleProgram();
51 abstract List<CompilerTask> get tasks(); 55 abstract List<CompilerTask> get tasks();
56
57 void updateFieldInitializers(Type type,
58 SourceString name,
59 HType propagatedType) {
60 Map<SourceString, HType> fields =
61 fieldInitializers.putIfAbsent(
62 type.element, () => new Map<SourceString, HType>());
63 if (!fields.containsKey(name)) {
64 fields[name] = propagatedType;
65 } else {
66 if (fields[name] != propagatedType) fields[name] = HType.UNKNOWN;
67 }
68 }
69
70 bool couldHaveFieldSingleTypeInitializers(Type type,
71 SourceString name,
72 HType requestedType) {
73 if (type == null) return false;
74 // If there is no information on the initializer it might still be
75 // initialized to integers only.
76 if (!fieldInitializers.containsKey(type.element)) return true;
77 Map<SourceString, HType> fields = fieldInitializers[type.element];
78 HType propagatedType = fields[name];
79 if (propagatedType == null) return true;
80 return propagatedType == requestedType;
81 }
82
83 bool hasFieldSingleTypeInitializers(Type type,
84 SourceString name,
85 HType requestedType) {
86 if (type == null) return false;
87 if (!fieldInitializers.containsKey(type.element)) return false;
88 Map<SourceString, HType> fields = fieldInitializers[type.element];
89 HType propagatedType = fields[name];
90 if (propagatedType == null) return false;
91 return propagatedType == requestedType;
92 }
93
94 void updateFieldIntegerSetters(Type type, SourceString name, bool isInteger) {
95 Map<SourceString, bool> fields =
96 fieldIntegerSetters.putIfAbsent(
97 type.element, () => new Map<SourceString, bool>());
98 if (!fields.containsKey(name)) {
99 fields[name] = isInteger;
100 } else {
101 fields[name] = fields[name] && isInteger;
102 }
103 }
104
105 bool couldHaveFieldOnlyIntegerSetters(Type type, SourceString name) {
106 if (type == null) return false;
107 if (!fieldIntegerSetters.containsKey(type.element)) return true;
108 Map<SourceString, bool> fields = fieldIntegerSetters[type.element];
109 if (!fields.containsKey(name)) return false;
110 return fields[name];
111 }
112
113 bool hasFieldOnlyIntegerSetters(Type type, SourceString name) {
114 if (type == null) return false;
115 if (!fieldIntegerSetters.containsKey(type.element)) return true;
116 Map<SourceString, bool> fields = fieldIntegerSetters[type.element];
117 if (!fields.containsKey(name)) return false;
118 return fields[name];
119 }
52 } 120 }
53 121
54 class JavaScriptBackend extends Backend { 122 class JavaScriptBackend extends Backend {
55 SsaBuilderTask builder; 123 SsaBuilderTask builder;
56 SsaOptimizerTask optimizer; 124 SsaOptimizerTask optimizer;
57 SsaCodeGeneratorTask generator; 125 SsaCodeGeneratorTask generator;
58 CodeEmitterTask emitter; 126 CodeEmitterTask emitter;
59 127
60 List<CompilerTask> get tasks() { 128 List<CompilerTask> get tasks() {
61 return <CompilerTask>[builder, optimizer, generator, emitter]; 129 return <CompilerTask>[builder, optimizer, generator, emitter];
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 // invariant that endOffset > beginOffset, but for EOF the 832 // invariant that endOffset > beginOffset, but for EOF the
765 // charoffset of the next token may be [beginOffset]. This can 833 // charoffset of the next token may be [beginOffset]. This can
766 // also happen for synthetized tokens that are produced during 834 // also happen for synthetized tokens that are produced during
767 // error handling. 835 // error handling.
768 final endOffset = 836 final endOffset =
769 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); 837 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1);
770 assert(endOffset > beginOffset); 838 assert(endOffset > beginOffset);
771 return f(beginOffset, endOffset); 839 return f(beginOffset, endOffset);
772 } 840 }
773 } 841 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698