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 '../backend_helpers.dart' show |
| 8 BackendHelpers; |
7 import '../js_backend.dart'; | 9 import '../js_backend.dart'; |
8 | 10 |
9 import '../../common.dart'; | 11 import '../../common.dart'; |
10 import '../../common/registry.dart' show | 12 import '../../common/registry.dart' show |
11 Registry; | 13 Registry; |
12 import '../../common/codegen.dart' show | 14 import '../../common/codegen.dart' show |
13 CodegenRegistry; | 15 CodegenRegistry; |
14 import '../../compiler.dart' show | 16 import '../../compiler.dart' show |
15 Compiler; | 17 Compiler; |
16 import '../../constants/values.dart'; | 18 import '../../constants/values.dart'; |
(...skipping 15 matching lines...) Expand all Loading... |
32 | 34 |
33 /// Encapsulates the dependencies of the function-compiler to the compiler, | 35 /// Encapsulates the dependencies of the function-compiler to the compiler, |
34 /// backend and emitter. | 36 /// backend and emitter. |
35 // TODO(sigurdm): Should be refactored when we have a better feeling for the | 37 // TODO(sigurdm): Should be refactored when we have a better feeling for the |
36 // interface. | 38 // interface. |
37 class Glue { | 39 class Glue { |
38 final Compiler _compiler; | 40 final Compiler _compiler; |
39 | 41 |
40 CodegenEnqueuer get _enqueuer => _compiler.enqueuer.codegen; | 42 CodegenEnqueuer get _enqueuer => _compiler.enqueuer.codegen; |
41 | 43 |
42 FunctionElement get getInterceptorMethod => _backend.getInterceptorMethod; | 44 FunctionElement get getInterceptorMethod => _helpers.getInterceptorMethod; |
43 | 45 |
44 JavaScriptBackend get _backend => _compiler.backend; | 46 JavaScriptBackend get _backend => _compiler.backend; |
45 | 47 |
| 48 BackendHelpers get _helpers => _backend.helpers; |
| 49 |
46 CodeEmitterTask get _emitter => _backend.emitter; | 50 CodeEmitterTask get _emitter => _backend.emitter; |
47 | 51 |
48 Namer get _namer => _backend.namer; | 52 Namer get _namer => _backend.namer; |
49 | 53 |
50 Glue(this._compiler); | 54 Glue(this._compiler); |
51 | 55 |
52 ClassWorld get classWorld => _compiler.world; | 56 ClassWorld get classWorld => _compiler.world; |
53 | 57 |
54 DiagnosticReporter get reporter => _compiler.reporter; | 58 DiagnosticReporter get reporter => _compiler.reporter; |
55 | 59 |
(...skipping 29 matching lines...) Expand all Loading... |
85 return _backend.constants.lazyStatics.contains(element); | 89 return _backend.constants.lazyStatics.contains(element); |
86 } | 90 } |
87 | 91 |
88 String safeVariableName(String name) { | 92 String safeVariableName(String name) { |
89 return _namer.safeVariableName(name); | 93 return _namer.safeVariableName(name); |
90 } | 94 } |
91 | 95 |
92 ClassElement get listClass => _compiler.coreClasses.listClass; | 96 ClassElement get listClass => _compiler.coreClasses.listClass; |
93 | 97 |
94 ConstructorElement get mapLiteralConstructor { | 98 ConstructorElement get mapLiteralConstructor { |
95 return _backend.mapLiteralConstructor; | 99 return _helpers.mapLiteralConstructor; |
96 } | 100 } |
97 | 101 |
98 ConstructorElement get mapLiteralConstructorEmpty { | 102 ConstructorElement get mapLiteralConstructorEmpty { |
99 return _backend.mapLiteralConstructorEmpty; | 103 return _helpers.mapLiteralConstructorEmpty; |
100 } | 104 } |
101 | 105 |
102 FunctionElement get identicalFunction => _compiler.identicalFunction; | 106 FunctionElement get identicalFunction => _compiler.identicalFunction; |
103 | 107 |
104 js.Name invocationName(Selector selector) { | 108 js.Name invocationName(Selector selector) { |
105 return _namer.invocationName(selector); | 109 return _namer.invocationName(selector); |
106 } | 110 } |
107 | 111 |
108 FunctionElement get createInvocationMirrorMethod { | 112 FunctionElement get createInvocationMirrorMethod { |
109 return _backend.helpers.createInvocationMirror; | 113 return _helpers.createInvocationMirror; |
110 } | 114 } |
111 | 115 |
112 void registerUseInterceptorInCodegen() { | 116 void registerUseInterceptorInCodegen() { |
113 _backend.registerUseInterceptor(_enqueuer); | 117 _backend.registerUseInterceptor(_enqueuer); |
114 } | 118 } |
115 | 119 |
116 bool isInterceptedSelector(Selector selector) { | 120 bool isInterceptedSelector(Selector selector) { |
117 return _backend.isInterceptedSelector(selector); | 121 return _backend.isInterceptedSelector(selector); |
118 } | 122 } |
119 | 123 |
120 bool isInterceptedMethod(Element element) { | 124 bool isInterceptedMethod(Element element) { |
121 return _backend.isInterceptedMethod(element); | 125 return _backend.isInterceptedMethod(element); |
122 } | 126 } |
123 | 127 |
124 bool isInterceptorClass(ClassElement element) { | 128 bool isInterceptorClass(ClassElement element) { |
125 return element.isSubclassOf(_backend.jsInterceptorClass); | 129 return element.isSubclassOf(_helpers.jsInterceptorClass); |
126 } | 130 } |
127 | 131 |
128 Set<ClassElement> getInterceptedClassesOn(Selector selector) { | 132 Set<ClassElement> getInterceptedClassesOn(Selector selector) { |
129 return _backend.getInterceptedClassesOn(selector.name); | 133 return _backend.getInterceptedClassesOn(selector.name); |
130 } | 134 } |
131 | 135 |
132 Set<ClassElement> get interceptedClasses { | 136 Set<ClassElement> get interceptedClasses { |
133 return _backend.interceptedClasses; | 137 return _backend.interceptedClasses; |
134 } | 138 } |
135 | 139 |
(...skipping 18 matching lines...) Expand all Loading... |
154 return _emitter.prototypeAccess(e, | 158 return _emitter.prototypeAccess(e, |
155 hasBeenInstantiated: hasBeenInstantiated); | 159 hasBeenInstantiated: hasBeenInstantiated); |
156 } | 160 } |
157 | 161 |
158 js.Name getInterceptorName(Set<ClassElement> interceptedClasses) { | 162 js.Name getInterceptorName(Set<ClassElement> interceptedClasses) { |
159 return _backend.namer.nameForGetInterceptor(interceptedClasses); | 163 return _backend.namer.nameForGetInterceptor(interceptedClasses); |
160 } | 164 } |
161 | 165 |
162 js.Expression getInterceptorLibrary() { | 166 js.Expression getInterceptorLibrary() { |
163 return new js.VariableUse( | 167 return new js.VariableUse( |
164 _backend.namer.globalObjectFor(_backend.interceptorsLibrary)); | 168 _backend.namer.globalObjectFor(_helpers.interceptorsLibrary)); |
165 } | 169 } |
166 | 170 |
167 FunctionElement getWrapExceptionHelper() { | 171 FunctionElement getWrapExceptionHelper() { |
168 return _backend.helpers.wrapExceptionHelper; | 172 return _helpers.wrapExceptionHelper; |
169 } | 173 } |
170 | 174 |
171 FunctionElement getExceptionUnwrapper() { | 175 FunctionElement getExceptionUnwrapper() { |
172 return _backend.helpers.exceptionUnwrapper; | 176 return _helpers.exceptionUnwrapper; |
173 } | 177 } |
174 | 178 |
175 FunctionElement getTraceFromException() { | 179 FunctionElement getTraceFromException() { |
176 return _backend.helpers.traceFromException; | 180 return _helpers.traceFromException; |
177 } | 181 } |
178 | 182 |
179 FunctionElement getCreateRuntimeType() { | 183 FunctionElement getCreateRuntimeType() { |
180 return _backend.helpers.createRuntimeType; | 184 return _helpers.createRuntimeType; |
181 } | 185 } |
182 | 186 |
183 FunctionElement getRuntimeTypeToString() { | 187 FunctionElement getRuntimeTypeToString() { |
184 return _backend.helpers.runtimeTypeToString; | 188 return _helpers.runtimeTypeToString; |
185 } | 189 } |
186 | 190 |
187 FunctionElement getRuntimeTypeArgument() { | 191 FunctionElement getRuntimeTypeArgument() { |
188 return _backend.helpers.getRuntimeTypeArgument; | 192 return _helpers.getRuntimeTypeArgument; |
189 } | 193 } |
190 | 194 |
191 FunctionElement getTypeArgumentByIndex() { | 195 FunctionElement getTypeArgumentByIndex() { |
192 return _backend.helpers.getTypeArgumentByIndex; | 196 return _helpers.getTypeArgumentByIndex; |
193 } | 197 } |
194 | 198 |
195 FunctionElement getAddRuntimeTypeInformation() { | 199 FunctionElement getAddRuntimeTypeInformation() { |
196 return _backend.helpers.setRuntimeTypeInfo; | 200 return _helpers.setRuntimeTypeInfo; |
197 } | 201 } |
198 | 202 |
199 /// checkSubtype(value, $isT, typeArgs, $asT) | 203 /// checkSubtype(value, $isT, typeArgs, $asT) |
200 FunctionElement getCheckSubtype() { | 204 FunctionElement getCheckSubtype() { |
201 return _backend.helpers.checkSubtype; | 205 return _helpers.checkSubtype; |
202 } | 206 } |
203 | 207 |
204 /// subtypeCast(value, $isT, typeArgs, $asT) | 208 /// subtypeCast(value, $isT, typeArgs, $asT) |
205 FunctionElement getSubtypeCast() { | 209 FunctionElement getSubtypeCast() { |
206 return _backend.helpers.subtypeCast; | 210 return _helpers.subtypeCast; |
207 } | 211 } |
208 | 212 |
209 /// checkSubtypeOfRuntime(value, runtimeType) | 213 /// checkSubtypeOfRuntime(value, runtimeType) |
210 FunctionElement getCheckSubtypeOfRuntimeType() { | 214 FunctionElement getCheckSubtypeOfRuntimeType() { |
211 return _backend.helpers.checkSubtypeOfRuntimeType; | 215 return _helpers.checkSubtypeOfRuntimeType; |
212 } | 216 } |
213 | 217 |
214 /// subtypeOfRuntimeTypeCast(value, runtimeType) | 218 /// subtypeOfRuntimeTypeCast(value, runtimeType) |
215 FunctionElement getSubtypeOfRuntimeTypeCast() { | 219 FunctionElement getSubtypeOfRuntimeTypeCast() { |
216 return _backend.helpers.subtypeOfRuntimeTypeCast; | 220 return _helpers.subtypeOfRuntimeTypeCast; |
217 } | 221 } |
218 | 222 |
219 js.Expression getRuntimeTypeName(ClassElement cls) { | 223 js.Expression getRuntimeTypeName(ClassElement cls) { |
220 return js.quoteName(_namer.runtimeTypeName(cls)); | 224 return js.quoteName(_namer.runtimeTypeName(cls)); |
221 } | 225 } |
222 | 226 |
223 int getTypeVariableIndex(TypeVariableType variable) { | 227 int getTypeVariableIndex(TypeVariableType variable) { |
224 return variable.element.index; | 228 return variable.element.index; |
225 } | 229 } |
226 | 230 |
227 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { | 231 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { |
228 ClassWorld classWorld = _compiler.world; | 232 ClassWorld classWorld = _compiler.world; |
229 if (classWorld.isUsedAsMixin(cls)) return true; | 233 if (classWorld.isUsedAsMixin(cls)) return true; |
230 | 234 |
231 Iterable<ClassElement> subclasses = _compiler.world.strictSubclassesOf(cls); | 235 Iterable<ClassElement> subclasses = _compiler.world.strictSubclassesOf(cls); |
232 return subclasses.any((ClassElement subclass) { | 236 return subclasses.any((ClassElement subclass) { |
233 return !_backend.rti.isTrivialSubstitution(subclass, cls); | 237 return !_backend.rti.isTrivialSubstitution(subclass, cls); |
234 }); | 238 }); |
235 } | 239 } |
236 | 240 |
237 js.Expression generateTypeRepresentation(DartType dartType, | 241 js.Expression generateTypeRepresentation(DartType dartType, |
238 List<js.Expression> arguments, | 242 List<js.Expression> arguments, |
239 CodegenRegistry registry) { | 243 CodegenRegistry registry) { |
240 int variableIndex = 0; | 244 int variableIndex = 0; |
241 js.Expression representation = _backend.rtiEncoder.getTypeRepresentation( | 245 js.Expression representation = _backend.rtiEncoder.getTypeRepresentation( |
242 dartType, | 246 dartType, |
243 (_) => arguments[variableIndex++]); | 247 (_) => arguments[variableIndex++]); |
244 assert(variableIndex == arguments.length); | 248 assert(variableIndex == arguments.length); |
245 // Representation contains JavaScript Arrays. | 249 // Representation contains JavaScript Arrays. |
246 registry.registerInstantiatedClass(_backend.jsArrayClass); | 250 registry.registerInstantiatedClass(_helpers.jsArrayClass); |
247 return representation; | 251 return representation; |
248 } | 252 } |
249 | 253 |
250 void registerIsCheck(DartType type, Registry registry) { | 254 void registerIsCheck(DartType type, Registry registry) { |
251 _enqueuer.registerIsCheck(type); | 255 _enqueuer.registerIsCheck(type); |
252 _backend.registerIsCheckForCodegen(type, _enqueuer, registry); | 256 _backend.registerIsCheckForCodegen(type, _enqueuer, registry); |
253 } | 257 } |
254 | 258 |
255 js.Name getTypeTestTag(DartType type) { | 259 js.Name getTypeTestTag(DartType type) { |
256 return _backend.namer.operatorIsType(type); | 260 return _backend.namer.operatorIsType(type); |
257 } | 261 } |
258 | 262 |
259 js.Name getTypeSubstitutionTag(ClassElement element) { | 263 js.Name getTypeSubstitutionTag(ClassElement element) { |
260 return _backend.namer.substitutionName(element); | 264 return _backend.namer.substitutionName(element); |
261 } | 265 } |
262 | 266 |
263 bool operatorEqHandlesNullArgument(FunctionElement element) { | 267 bool operatorEqHandlesNullArgument(FunctionElement element) { |
264 return _backend.operatorEqHandlesNullArgument(element); | 268 return _backend.operatorEqHandlesNullArgument(element); |
265 } | 269 } |
266 | 270 |
267 bool hasStrictSubtype(ClassElement element) { | 271 bool hasStrictSubtype(ClassElement element) { |
268 return _compiler.world.hasAnyStrictSubtype(element); | 272 return _compiler.world.hasAnyStrictSubtype(element); |
269 } | 273 } |
270 | 274 |
271 ClassElement get jsFixedArrayClass => _backend.jsFixedArrayClass; | 275 ClassElement get jsFixedArrayClass => _helpers.jsFixedArrayClass; |
272 ClassElement get jsExtendableArrayClass => _backend.jsExtendableArrayClass; | 276 ClassElement get jsExtendableArrayClass => _helpers.jsExtendableArrayClass; |
273 ClassElement get jsUnmodifiableArrayClass => | 277 ClassElement get jsUnmodifiableArrayClass => |
274 _backend.jsUnmodifiableArrayClass; | 278 _helpers.jsUnmodifiableArrayClass; |
275 ClassElement get jsMutableArrayClass => _backend.jsMutableArrayClass; | 279 ClassElement get jsMutableArrayClass => _helpers.jsMutableArrayClass; |
276 | 280 |
277 bool isStringClass(ClassElement classElement) => | 281 bool isStringClass(ClassElement classElement) => |
278 classElement == _backend.jsStringClass || | 282 classElement == _helpers.jsStringClass || |
279 classElement == _compiler.coreClasses.stringClass; | 283 classElement == _compiler.coreClasses.stringClass; |
280 | 284 |
281 bool isBoolClass(ClassElement classElement) => | 285 bool isBoolClass(ClassElement classElement) => |
282 classElement == _backend.jsBoolClass || | 286 classElement == _helpers.jsBoolClass || |
283 classElement == _compiler.coreClasses.boolClass; | 287 classElement == _compiler.coreClasses.boolClass; |
284 | 288 |
285 // TODO(sra): Should this be part of CodegenRegistry? | 289 // TODO(sra): Should this be part of CodegenRegistry? |
286 void registerNativeBehavior(NativeBehavior nativeBehavior, node) { | 290 void registerNativeBehavior(NativeBehavior nativeBehavior, node) { |
287 if (nativeBehavior == null) return; | 291 if (nativeBehavior == null) return; |
288 _enqueuer.nativeEnqueuer.registerNativeBehavior(nativeBehavior, node); | 292 _enqueuer.nativeEnqueuer.registerNativeBehavior(nativeBehavior, node); |
289 } | 293 } |
290 | 294 |
291 ConstantValue getDefaultParameterValue(ParameterElement elem) { | 295 ConstantValue getDefaultParameterValue(ParameterElement elem) { |
292 return _backend.constants.getConstantValueForVariable(elem); | 296 return _backend.constants.getConstantValueForVariable(elem); |
293 } | 297 } |
294 } | 298 } |
OLD | NEW |