| 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 '../../dart2jslib.dart'; | 8 import '../../dart2jslib.dart'; |
| 9 import '../../js_emitter/js_emitter.dart'; | 9 import '../../js_emitter/js_emitter.dart'; |
| 10 import '../../js/js.dart' as js; | 10 import '../../js/js.dart' as js; |
| 11 import '../../constants/values.dart'; | 11 import '../../constants/values.dart'; |
| 12 import '../../elements/elements.dart'; | 12 import '../../elements/elements.dart'; |
| 13 import '../../constants/expressions.dart'; | 13 import '../../constants/expressions.dart'; |
| 14 import '../../dart_types.dart' show DartType, TypeVariableType; | 14 import '../../dart_types.dart' show DartType, TypeVariableType, InterfaceType; |
| 15 | 15 |
| 16 /// Encapsulates the dependencies of the function-compiler to the compiler, | 16 /// Encapsulates the dependencies of the function-compiler to the compiler, |
| 17 /// backend and emitter. | 17 /// backend and emitter. |
| 18 // TODO(sigurdm): Should be refactored when we have a better feeling for the | 18 // TODO(sigurdm): Should be refactored when we have a better feeling for the |
| 19 // interface. | 19 // interface. |
| 20 class Glue { | 20 class Glue { |
| 21 final Compiler _compiler; | 21 final Compiler _compiler; |
| 22 | 22 |
| 23 CodegenEnqueuer get _enqueuer => _compiler.enqueuer.codegen; |
| 24 |
| 25 FunctionElement get getInterceptorMethod => _backend.getInterceptorMethod; |
| 26 |
| 23 JavaScriptBackend get _backend => _compiler.backend; | 27 JavaScriptBackend get _backend => _compiler.backend; |
| 24 | 28 |
| 25 CodeEmitterTask get _emitter => _backend.emitter; | 29 CodeEmitterTask get _emitter => _backend.emitter; |
| 30 |
| 26 Namer get _namer => _backend.namer; | 31 Namer get _namer => _backend.namer; |
| 27 | 32 |
| 28 Glue(this._compiler); | 33 Glue(this._compiler); |
| 29 | 34 |
| 30 js.Expression constantReference(ConstantValue value) { | 35 js.Expression constantReference(ConstantValue value) { |
| 31 return _emitter.constantReference(value); | 36 return _emitter.constantReference(value); |
| 32 } | 37 } |
| 33 | 38 |
| 34 Element getStringConversion() { | 39 Element getStringConversion() { |
| 35 return _backend.getStringInterpolationHelper(); | 40 return _backend.getStringInterpolationHelper(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 64 ConstructorElement get mapLiteralConstructorEmpty { | 69 ConstructorElement get mapLiteralConstructorEmpty { |
| 65 return _backend.mapLiteralConstructorEmpty; | 70 return _backend.mapLiteralConstructorEmpty; |
| 66 } | 71 } |
| 67 | 72 |
| 68 FunctionElement get identicalFunction => _compiler.identicalFunction; | 73 FunctionElement get identicalFunction => _compiler.identicalFunction; |
| 69 | 74 |
| 70 String invocationName(Selector selector) { | 75 String invocationName(Selector selector) { |
| 71 return _namer.invocationName(selector); | 76 return _namer.invocationName(selector); |
| 72 } | 77 } |
| 73 | 78 |
| 74 FunctionElement get getInterceptorMethod => _backend.getInterceptorMethod; | |
| 75 | |
| 76 void registerUseInterceptorInCodegen() { | 79 void registerUseInterceptorInCodegen() { |
| 77 _backend.registerUseInterceptor(_compiler.enqueuer.codegen); | 80 _backend.registerUseInterceptor(_enqueuer); |
| 78 } | 81 } |
| 79 | 82 |
| 80 bool isInterceptedSelector(Selector selector) { | 83 bool isInterceptedSelector(Selector selector) { |
| 81 return _backend.isInterceptedSelector(selector); | 84 return _backend.isInterceptedSelector(selector); |
| 82 } | 85 } |
| 83 | 86 |
| 84 bool isInterceptedMethod(Element element) { | 87 bool isInterceptedMethod(Element element) { |
| 85 return _backend.isInterceptedMethod(element); | 88 return _backend.isInterceptedMethod(element); |
| 86 } | 89 } |
| 87 | 90 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 145 } |
| 143 | 146 |
| 144 FunctionElement getTypeArgumentWithSubstitution() { | 147 FunctionElement getTypeArgumentWithSubstitution() { |
| 145 return _backend.getGetRuntimeTypeArgument(); | 148 return _backend.getGetRuntimeTypeArgument(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 FunctionElement getTypeArgumentByIndex() { | 151 FunctionElement getTypeArgumentByIndex() { |
| 149 return _backend.getGetTypeArgumentByIndex(); | 152 return _backend.getGetTypeArgumentByIndex(); |
| 150 } | 153 } |
| 151 | 154 |
| 155 FunctionElement getAddRuntimeTypeInformation() { |
| 156 return _backend.getSetRuntimeTypeInfo(); |
| 157 } |
| 158 |
| 152 js.Expression getSubstitutionName(ClassElement cls) { | 159 js.Expression getSubstitutionName(ClassElement cls) { |
| 153 return js.string(_namer.substitutionName(cls)); | 160 return js.string(_namer.substitutionName(cls)); |
| 154 } | 161 } |
| 155 | 162 |
| 156 int getTypeVariableIndex(TypeVariableType variable) { | 163 int getTypeVariableIndex(TypeVariableType variable) { |
| 157 return RuntimeTypes.getTypeVariableIndex(variable.element); | 164 return RuntimeTypes.getTypeVariableIndex(variable.element); |
| 158 } | 165 } |
| 159 | 166 |
| 160 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { | 167 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { |
| 161 ClassWorld classWorld = _compiler.world; | 168 ClassWorld classWorld = _compiler.world; |
| 162 if (classWorld.isUsedAsMixin(cls)) return true; | 169 if (classWorld.isUsedAsMixin(cls)) return true; |
| 163 | 170 |
| 164 Iterable<ClassElement> subclasses = _compiler.world.strictSubclassesOf(cls); | 171 Iterable<ClassElement> subclasses = _compiler.world.strictSubclassesOf(cls); |
| 165 return subclasses.any((ClassElement subclass) { | 172 return subclasses.any((ClassElement subclass) { |
| 166 return !_backend.rti.isTrivialSubstitution(subclass, cls); | 173 return !_backend.rti.isTrivialSubstitution(subclass, cls); |
| 167 }); | 174 }); |
| 168 } | 175 } |
| 169 | 176 |
| 170 FunctionElement getAddRuntimeTypeInformation() { | |
| 171 return _backend.getSetRuntimeTypeInfo(); | |
| 172 } | |
| 173 | |
| 174 js.Expression generateTypeRepresentation(DartType dartType, | 177 js.Expression generateTypeRepresentation(DartType dartType, |
| 175 List<js.Expression> arguments) { | 178 List<js.Expression> arguments) { |
| 176 int variableIndex = 0; | 179 int variableIndex = 0; |
| 177 js.Expression representation = _backend.rti.getTypeRepresentation( | 180 js.Expression representation = _backend.rti.getTypeRepresentation( |
| 178 dartType, | 181 dartType, |
| 179 (_) => arguments[variableIndex++]); | 182 (_) => arguments[variableIndex++]); |
| 180 assert(variableIndex == arguments.length); | 183 assert(variableIndex == arguments.length); |
| 181 return representation; | 184 return representation; |
| 182 } | 185 } |
| 186 |
| 187 bool isNativePrimitiveType(DartType type) { |
| 188 if (type is! InterfaceType) return false; |
| 189 return _backend.isNativePrimitiveType(type.element); |
| 190 } |
| 191 |
| 192 void registerIsCheck(DartType type, Registry registry) { |
| 193 _enqueuer.registerIsCheck(type, registry); |
| 194 _backend.registerIsCheckForCodegen(type, _enqueuer, registry); |
| 195 } |
| 196 |
| 197 bool isIntClass(ClassElement cls) => cls == _compiler.intClass; |
| 198 |
| 199 bool isStringClass(ClassElement cls) => cls == _compiler.stringClass; |
| 200 |
| 201 bool isBoolClass(ClassElement cls) => cls == _compiler.boolClass; |
| 202 |
| 203 bool isNumClass(ClassElement cls) => cls == _compiler.numClass; |
| 204 |
| 205 bool isDoubleClass(ClassElement cls) => cls == _compiler.doubleClass; |
| 206 |
| 207 String getTypeTestTag(DartType type) { |
| 208 return _backend.namer.operatorIsType(type); |
| 209 } |
| 183 } | 210 } |
| OLD | NEW |