OLD | NEW |
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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
9 * compiled. | 9 * compiled. |
10 */ | 10 */ |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 lib.forEachExport((Element e) { | 104 lib.forEachExport((Element e) { |
105 if (e.isFunction()) world.addToWorkList(e); | 105 if (e.isFunction()) world.addToWorkList(e); |
106 }); | 106 }); |
107 } | 107 } |
108 | 108 |
109 // TODO(karlklose): get rid of this and add a factory constructor to [List] | 109 // TODO(karlklose): get rid of this and add a factory constructor to [List] |
110 // that creates an instance of JSArray to make the dependency visible in from | 110 // that creates an instance of JSArray to make the dependency visible in from |
111 // the source code. | 111 // the source code. |
112 void addBackendRtiDependencies(World world); | 112 void addBackendRtiDependencies(World world); |
113 | 113 |
114 void enqueueHelpers(ResolutionEnqueuer world); | 114 void enqueueHelpers(ResolutionEnqueuer world, TreeElements elements); |
115 void codegen(CodegenWorkItem work); | 115 void codegen(CodegenWorkItem work); |
116 | 116 |
117 // The backend determines the native resolution enqueuer, with a no-op | 117 // The backend determines the native resolution enqueuer, with a no-op |
118 // default, so tools like dart2dart can ignore the native classes. | 118 // default, so tools like dart2dart can ignore the native classes. |
119 native.NativeEnqueuer nativeResolutionEnqueuer(world) { | 119 native.NativeEnqueuer nativeResolutionEnqueuer(world) { |
120 return new native.NativeEnqueuer(); | 120 return new native.NativeEnqueuer(); |
121 } | 121 } |
122 native.NativeEnqueuer nativeCodegenEnqueuer(world) { | 122 native.NativeEnqueuer nativeCodegenEnqueuer(world) { |
123 return new native.NativeEnqueuer(); | 123 return new native.NativeEnqueuer(); |
124 } | 124 } |
125 | 125 |
126 void assembleProgram(); | 126 void assembleProgram(); |
127 List<CompilerTask> get tasks; | 127 List<CompilerTask> get tasks; |
128 | 128 |
129 // TODO(ahe,karlklose): rename this? | 129 // TODO(ahe,karlklose): rename this? |
130 void dumpInferredTypes() {} | 130 void dumpInferredTypes() {} |
131 | 131 |
132 ItemCompilationContext createItemCompilationContext() { | 132 ItemCompilationContext createItemCompilationContext() { |
133 return new ItemCompilationContext(); | 133 return new ItemCompilationContext(); |
134 } | 134 } |
135 | 135 |
136 // The following methods are hooks for the backend to register its | 136 // The following methods are hooks for the backend to register its |
137 // helper methods. | 137 // helper methods. |
138 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} | 138 void registerInstantiatedClass(ClassElement cls, |
139 void registerStringInterpolation() {} | 139 Enqueuer enqueuer, |
140 void registerCatchStatement() {} | 140 TreeElements elements) {} |
141 void registerThrow() {} | 141 void registerStringInterpolation(TreeElements elements) {} |
142 void registerLazyField() {} | 142 void registerCatchStatement(TreeElements elements) {} |
143 void registerTypeLiteral() {} | 143 void registerThrow(TreeElements elements) {} |
144 void registerStackTraceInCatch() {} | 144 void registerLazyField(TreeElements elements) {} |
145 void registerIsCheck(DartType type, Enqueuer enqueuer) {} | 145 void registerTypeLiteral(TreeElements elements) {} |
146 void registerAsCheck(DartType type) {} | 146 void registerStackTraceInCatch(TreeElements elements) {} |
147 void registerThrowNoSuchMethod() {} | 147 void registerIsCheck(DartType type, |
148 void registerThrowRuntimeError() {} | 148 Enqueuer enqueuer, |
149 void registerAbstractClassInstantiation() {} | 149 TreeElements elements) {} |
150 void registerFallThroughError() {} | 150 void registerAsCheck(DartType type, TreeElements elements) {} |
151 void registerSuperNoSuchMethod() {} | 151 void registerThrowNoSuchMethod(TreeElements elements) {} |
152 void registerConstantMap() {} | 152 void registerThrowRuntimeError(TreeElements elements) {} |
153 void registerRuntimeType() {} | 153 void registerAbstractClassInstantiation(TreeElements elements) {} |
| 154 void registerFallThroughError(TreeElements elements) {} |
| 155 void registerSuperNoSuchMethod(TreeElements elements) {} |
| 156 void registerConstantMap(TreeElements elements) {} |
| 157 void registerRuntimeType(TreeElements elements) {} |
154 | 158 |
155 bool isNullImplementation(ClassElement cls) { | 159 bool isNullImplementation(ClassElement cls) { |
156 return cls == compiler.nullClass; | 160 return cls == compiler.nullClass; |
157 } | 161 } |
158 } | 162 } |
159 | 163 |
160 /** | 164 /** |
161 * Key class used in [TokenMap] in which the hash code for a token is based | 165 * Key class used in [TokenMap] in which the hash code for a token is based |
162 * on the [charOffset]. | 166 * on the [charOffset]. |
163 */ | 167 */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 int nextFreeClassId = 0; | 206 int nextFreeClassId = 0; |
203 World world; | 207 World world; |
204 String assembledCode; | 208 String assembledCode; |
205 Types types; | 209 Types types; |
206 | 210 |
207 /** | 211 /** |
208 * Map from token to the first preceeding comment token. | 212 * Map from token to the first preceeding comment token. |
209 */ | 213 */ |
210 final TokenMap commentMap = new TokenMap(); | 214 final TokenMap commentMap = new TokenMap(); |
211 | 215 |
| 216 /** |
| 217 * Records global dependencies, that is, dependencies that don't |
| 218 * correspond to a particular element. |
| 219 * |
| 220 * We should get rid of this and ensure that all dependencies are |
| 221 * associated with a particular element. |
| 222 */ |
| 223 final TreeElements globalDependencies = new TreeElementMapping(null); |
| 224 |
212 final bool enableMinification; | 225 final bool enableMinification; |
213 final bool enableTypeAssertions; | 226 final bool enableTypeAssertions; |
214 final bool enableUserAssertions; | 227 final bool enableUserAssertions; |
215 final bool enableConcreteTypeInference; | 228 final bool enableConcreteTypeInference; |
216 /** | 229 /** |
217 * The maximum size of a concrete type before it widens to dynamic during | 230 * The maximum size of a concrete type before it widens to dynamic during |
218 * concrete type inference. | 231 * concrete type inference. |
219 */ | 232 */ |
220 final int maxConcreteTypeSize; | 233 final int maxConcreteTypeSize; |
221 final bool analyzeAll; | 234 final bool analyzeAll; |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 reportFatalError('main is not a function', main); | 683 reportFatalError('main is not a function', main); |
671 } | 684 } |
672 FunctionElement mainMethod = main; | 685 FunctionElement mainMethod = main; |
673 FunctionSignature parameters = mainMethod.computeSignature(this); | 686 FunctionSignature parameters = mainMethod.computeSignature(this); |
674 parameters.forEachParameter((Element parameter) { | 687 parameters.forEachParameter((Element parameter) { |
675 reportFatalError('main cannot have parameters', parameter); | 688 reportFatalError('main cannot have parameters', parameter); |
676 }); | 689 }); |
677 } | 690 } |
678 } | 691 } |
679 | 692 |
680 deferredLoadTask.registerMainApp(mainApp); | |
681 | |
682 log('Resolving...'); | 693 log('Resolving...'); |
683 phase = PHASE_RESOLVING; | 694 phase = PHASE_RESOLVING; |
684 if (analyzeAll) { | 695 if (analyzeAll) { |
685 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib)); | 696 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib)); |
686 } | 697 } |
687 backend.enqueueHelpers(enqueuer.resolution); | 698 // Elements required by enqueueHelpers are global dependencies |
| 699 // that are not pulled in by a particular element. |
| 700 backend.enqueueHelpers(enqueuer.resolution, globalDependencies); |
688 processQueue(enqueuer.resolution, main); | 701 processQueue(enqueuer.resolution, main); |
689 enqueuer.resolution.logSummary(log); | 702 enqueuer.resolution.logSummary(log); |
690 | 703 |
691 if (compilationFailed) return; | 704 if (compilationFailed) return; |
692 if (analyzeOnly) return; | 705 if (analyzeOnly) return; |
693 assert(main != null); | 706 assert(main != null); |
694 | 707 |
695 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution | 708 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution |
696 // should know this. | 709 // should know this. |
697 world.populate(); | 710 world.populate(); |
698 | 711 |
| 712 deferredLoadTask.onResolutionComplete(main); |
| 713 |
699 log('Inferring types...'); | 714 log('Inferring types...'); |
700 typesTask.onResolutionComplete(main); | 715 typesTask.onResolutionComplete(main); |
701 | 716 |
702 log('Compiling...'); | 717 log('Compiling...'); |
703 phase = PHASE_COMPILING; | 718 phase = PHASE_COMPILING; |
704 // TODO(johnniwinther): Move these to [CodegenEnqueuer]. | 719 // TODO(johnniwinther): Move these to [CodegenEnqueuer]. |
705 if (hasIsolateSupport()) { | 720 if (hasIsolateSupport()) { |
706 enqueuer.codegen.addToWorkList( | 721 enqueuer.codegen.addToWorkList( |
707 isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE)); | 722 isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE)); |
708 } | 723 } |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 | 1186 |
1172 void close() {} | 1187 void close() {} |
1173 | 1188 |
1174 toString() => name; | 1189 toString() => name; |
1175 | 1190 |
1176 /// Convenience method for getting an [api.CompilerOutputProvider]. | 1191 /// Convenience method for getting an [api.CompilerOutputProvider]. |
1177 static NullSink outputProvider(String name, String extension) { | 1192 static NullSink outputProvider(String name, String extension) { |
1178 return new NullSink('$name.$extension'); | 1193 return new NullSink('$name.$extension'); |
1179 } | 1194 } |
1180 } | 1195 } |
OLD | NEW |