OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library code_generator_dependencies; | 5 library code_generator_dependencies; |
6 | 6 |
7 import '../js_backend.dart'; | 7 import '../js_backend.dart'; |
8 import '../../common/registry.dart' show | 8 import '../../common/registry.dart' show |
9 Registry; | 9 Registry; |
10 import '../../common/codegen.dart' show | |
11 CodegenRegistry; | |
12 import '../../compiler.dart' show | 10 import '../../compiler.dart' show |
13 Compiler; | 11 Compiler; |
14 import '../../constants/values.dart'; | 12 import '../../constants/values.dart'; |
15 import '../../dart_types.dart' show | 13 import '../../dart_types.dart' show |
16 DartType, | 14 DartType, |
17 TypeVariableType, | 15 TypeVariableType, |
18 InterfaceType; | 16 InterfaceType; |
19 import '../../diagnostics/diagnostic_listener.dart' show | 17 import '../../diagnostics/diagnostic_listener.dart' show |
20 DiagnosticReporter; | 18 DiagnosticReporter; |
21 import '../../diagnostics/spannable.dart' show | 19 import '../../diagnostics/spannable.dart' show |
22 CURRENT_ELEMENT_SPANNABLE; | 20 CURRENT_ELEMENT_SPANNABLE; |
23 import '../../enqueue.dart' show | 21 import '../../enqueue.dart' show |
24 CodegenEnqueuer; | 22 CodegenEnqueuer; |
25 import '../../elements/elements.dart'; | 23 import '../../elements/elements.dart'; |
26 import '../../js_emitter/js_emitter.dart'; | 24 import '../../js_emitter/js_emitter.dart'; |
27 import '../../js/js.dart' as js; | 25 import '../../js/js.dart' as js; |
28 import '../../native/native.dart' show NativeBehavior; | |
29 import '../../universe/selector.dart' show | 26 import '../../universe/selector.dart' show |
30 Selector; | 27 Selector; |
31 import '../../world.dart' show | 28 import '../../world.dart' show |
32 ClassWorld; | 29 ClassWorld; |
33 | 30 |
34 | 31 |
35 /// Encapsulates the dependencies of the function-compiler to the compiler, | 32 /// Encapsulates the dependencies of the function-compiler to the compiler, |
36 /// backend and emitter. | 33 /// backend and emitter. |
37 // TODO(sigurdm): Should be refactored when we have a better feeling for the | 34 // TODO(sigurdm): Should be refactored when we have a better feeling for the |
38 // interface. | 35 // interface. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 125 } |
129 | 126 |
130 bool isInterceptorClass(ClassElement element) { | 127 bool isInterceptorClass(ClassElement element) { |
131 return element.isSubclassOf(_backend.jsInterceptorClass); | 128 return element.isSubclassOf(_backend.jsInterceptorClass); |
132 } | 129 } |
133 | 130 |
134 Set<ClassElement> getInterceptedClassesOn(Selector selector) { | 131 Set<ClassElement> getInterceptedClassesOn(Selector selector) { |
135 return _backend.getInterceptedClassesOn(selector.name); | 132 return _backend.getInterceptedClassesOn(selector.name); |
136 } | 133 } |
137 | 134 |
138 Set<ClassElement> get interceptedClasses { | |
139 return _backend.interceptedClasses; | |
140 } | |
141 | |
142 void registerSpecializedGetInterceptor(Set<ClassElement> classes) { | 135 void registerSpecializedGetInterceptor(Set<ClassElement> classes) { |
143 _backend.registerSpecializedGetInterceptor(classes); | 136 _backend.registerSpecializedGetInterceptor(classes); |
144 } | 137 } |
145 | 138 |
146 js.Expression constructorAccess(ClassElement element) { | 139 js.Expression constructorAccess(ClassElement element) { |
147 return _backend.emitter.constructorAccess(element); | 140 return _backend.emitter.constructorAccess(element); |
148 } | 141 } |
149 | 142 |
150 js.Name instanceFieldPropertyName(Element field) { | 143 js.Name instanceFieldPropertyName(Element field) { |
151 return _namer.instanceFieldPropertyName(field); | 144 return _namer.instanceFieldPropertyName(field); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 ClassWorld classWorld = _compiler.world; | 227 ClassWorld classWorld = _compiler.world; |
235 if (classWorld.isUsedAsMixin(cls)) return true; | 228 if (classWorld.isUsedAsMixin(cls)) return true; |
236 | 229 |
237 Iterable<ClassElement> subclasses = _compiler.world.strictSubclassesOf(cls); | 230 Iterable<ClassElement> subclasses = _compiler.world.strictSubclassesOf(cls); |
238 return subclasses.any((ClassElement subclass) { | 231 return subclasses.any((ClassElement subclass) { |
239 return !_backend.rti.isTrivialSubstitution(subclass, cls); | 232 return !_backend.rti.isTrivialSubstitution(subclass, cls); |
240 }); | 233 }); |
241 } | 234 } |
242 | 235 |
243 js.Expression generateTypeRepresentation(DartType dartType, | 236 js.Expression generateTypeRepresentation(DartType dartType, |
244 List<js.Expression> arguments, | 237 List<js.Expression> arguments) { |
245 CodegenRegistry registry) { | |
246 int variableIndex = 0; | 238 int variableIndex = 0; |
247 js.Expression representation = _backend.rti.getTypeRepresentation( | 239 js.Expression representation = _backend.rti.getTypeRepresentation( |
248 dartType, | 240 dartType, |
249 (_) => arguments[variableIndex++]); | 241 (_) => arguments[variableIndex++]); |
250 assert(variableIndex == arguments.length); | 242 assert(variableIndex == arguments.length); |
251 // Representation contains JavaScript Arrays. | |
252 registry.registerInstantiatedClass(_backend.jsArrayClass); | |
253 return representation; | 243 return representation; |
254 } | 244 } |
255 | 245 |
256 void registerIsCheck(DartType type, Registry registry) { | 246 void registerIsCheck(DartType type, Registry registry) { |
257 _enqueuer.registerIsCheck(type); | 247 _enqueuer.registerIsCheck(type); |
258 _backend.registerIsCheckForCodegen(type, _enqueuer, registry); | 248 _backend.registerIsCheckForCodegen(type, _enqueuer, registry); |
259 } | 249 } |
260 | 250 |
261 js.Name getTypeTestTag(DartType type) { | 251 js.Name getTypeTestTag(DartType type) { |
262 return _backend.namer.operatorIsType(type); | 252 return _backend.namer.operatorIsType(type); |
263 } | 253 } |
264 | 254 |
265 js.Name getTypeSubstitutionTag(ClassElement element) { | 255 js.Name getTypeSubstitutionTag(ClassElement element) { |
266 return _backend.namer.substitutionName(element); | 256 return _backend.namer.substitutionName(element); |
267 } | 257 } |
268 | 258 |
269 bool operatorEqHandlesNullArgument(FunctionElement element) { | 259 bool operatorEqHandlesNullArgument(FunctionElement element) { |
270 return _backend.operatorEqHandlesNullArgument(element); | 260 return _backend.operatorEqHandlesNullArgument(element); |
271 } | 261 } |
272 | 262 |
273 bool hasStrictSubtype(ClassElement element) { | 263 bool hasStrictSubtype(ClassElement element) { |
274 return _compiler.world.hasAnyStrictSubtype(element); | 264 return _compiler.world.hasAnyStrictSubtype(element); |
275 } | 265 } |
276 | 266 |
277 ClassElement get jsFixedArrayClass => _backend.jsFixedArrayClass; | |
278 ClassElement get jsExtendableArrayClass => _backend.jsExtendableArrayClass; | 267 ClassElement get jsExtendableArrayClass => _backend.jsExtendableArrayClass; |
279 ClassElement get jsUnmodifiableArrayClass => | |
280 _backend.jsUnmodifiableArrayClass; | |
281 ClassElement get jsMutableArrayClass => _backend.jsMutableArrayClass; | 268 ClassElement get jsMutableArrayClass => _backend.jsMutableArrayClass; |
282 | 269 |
283 bool isStringClass(ClassElement classElement) => | 270 bool isStringClass(ClassElement classElement) => |
284 classElement == _backend.jsStringClass || | 271 classElement == _backend.jsStringClass || |
285 classElement == _compiler.stringClass; | 272 classElement == _compiler.stringClass; |
286 | 273 |
287 bool isBoolClass(ClassElement classElement) => | 274 bool isBoolClass(ClassElement classElement) => |
288 classElement == _backend.jsBoolClass || | 275 classElement == _backend.jsBoolClass || |
289 classElement == _compiler.boolClass; | 276 classElement == _compiler.boolClass; |
290 | |
291 // TODO(sra): Should this be part of CodegenRegistry? | |
292 void registerNativeBehavior(NativeBehavior nativeBehavior, node) { | |
293 if (nativeBehavior == null) return; | |
294 _enqueuer.nativeEnqueuer.registerNativeBehavior(nativeBehavior, node); | |
295 } | |
296 } | 277 } |
OLD | NEW |