| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library code_generator_dependencies; | |
| 6 | |
| 7 import '../../common.dart'; | |
| 8 import '../../common/codegen.dart' show CodegenRegistry; | |
| 9 import '../../compiler.dart' show Compiler; | |
| 10 import '../../constants/values.dart'; | |
| 11 import '../../dart_types.dart' show DartType, TypeVariableType; | |
| 12 import '../../elements/elements.dart'; | |
| 13 import '../../enqueue.dart' show CodegenEnqueuer; | |
| 14 import '../../js/js.dart' as js; | |
| 15 import '../../js_emitter/js_emitter.dart'; | |
| 16 import '../../native/native.dart' show NativeBehavior; | |
| 17 import '../../types/types.dart'; | |
| 18 import '../../universe/selector.dart' show Selector; | |
| 19 import '../../world.dart' show ClassWorld; | |
| 20 import '../backend_helpers.dart' show BackendHelpers; | |
| 21 import '../js_backend.dart'; | |
| 22 | |
| 23 /// Encapsulates the dependencies of the function-compiler to the compiler, | |
| 24 /// backend and emitter. | |
| 25 // TODO(sigurdm): Should be refactored when we have a better feeling for the | |
| 26 // interface. | |
| 27 class Glue { | |
| 28 final Compiler _compiler; | |
| 29 | |
| 30 CodegenEnqueuer get _enqueuer => _compiler.enqueuer.codegen; | |
| 31 | |
| 32 FunctionElement get getInterceptorMethod => _helpers.getInterceptorMethod; | |
| 33 | |
| 34 JavaScriptBackend get _backend => _compiler.backend; | |
| 35 | |
| 36 BackendHelpers get _helpers => _backend.helpers; | |
| 37 | |
| 38 CodeEmitterTask get _emitter => _backend.emitter; | |
| 39 | |
| 40 Namer get _namer => _backend.namer; | |
| 41 | |
| 42 Glue(this._compiler); | |
| 43 | |
| 44 ClassWorld get classWorld => _compiler.world; | |
| 45 | |
| 46 DiagnosticReporter get reporter => _compiler.reporter; | |
| 47 | |
| 48 js.Expression constantReference(ConstantValue value) { | |
| 49 return _emitter.constantReference(value); | |
| 50 } | |
| 51 | |
| 52 reportInternalError(String message) { | |
| 53 reporter.internalError(CURRENT_ELEMENT_SPANNABLE, message); | |
| 54 } | |
| 55 | |
| 56 bool isUsedAsMixin(ClassElement classElement) { | |
| 57 return classWorld.isUsedAsMixin(classElement); | |
| 58 } | |
| 59 | |
| 60 js.Expression staticFunctionAccess(FunctionElement element) { | |
| 61 return _backend.emitter.staticFunctionAccess(element); | |
| 62 } | |
| 63 | |
| 64 js.Expression isolateStaticClosureAccess(FunctionElement element) { | |
| 65 return _backend.emitter.isolateStaticClosureAccess(element); | |
| 66 } | |
| 67 | |
| 68 js.Expression staticFieldAccess(FieldElement element) { | |
| 69 return _backend.emitter.staticFieldAccess(element); | |
| 70 } | |
| 71 | |
| 72 js.Expression isolateLazyInitializerAccess(FieldElement element) { | |
| 73 return _backend.emitter.isolateLazyInitializerAccess(element); | |
| 74 } | |
| 75 | |
| 76 bool isLazilyInitialized(FieldElement element) { | |
| 77 return _backend.constants.lazyStatics.contains(element); | |
| 78 } | |
| 79 | |
| 80 String safeVariableName(String name) { | |
| 81 return _namer.safeVariableName(name); | |
| 82 } | |
| 83 | |
| 84 ClassElement get listClass => _compiler.coreClasses.listClass; | |
| 85 | |
| 86 ConstructorElement get mapLiteralConstructor { | |
| 87 return _helpers.mapLiteralConstructor; | |
| 88 } | |
| 89 | |
| 90 ConstructorElement get mapLiteralConstructorEmpty { | |
| 91 return _helpers.mapLiteralConstructorEmpty; | |
| 92 } | |
| 93 | |
| 94 FunctionElement get identicalFunction => _compiler.identicalFunction; | |
| 95 | |
| 96 js.Name invocationName(Selector selector) { | |
| 97 return _namer.invocationName(selector); | |
| 98 } | |
| 99 | |
| 100 FunctionElement get createInvocationMirrorMethod { | |
| 101 return _helpers.createInvocationMirror; | |
| 102 } | |
| 103 | |
| 104 bool isInterceptedSelector(Selector selector) { | |
| 105 return _backend.isInterceptedSelector(selector); | |
| 106 } | |
| 107 | |
| 108 bool isInterceptedMethod(Element element) { | |
| 109 return _backend.isInterceptedMethod(element); | |
| 110 } | |
| 111 | |
| 112 bool isInterceptorClass(ClassElement element) { | |
| 113 return element.isSubclassOf(_helpers.jsInterceptorClass); | |
| 114 } | |
| 115 | |
| 116 Set<ClassElement> getInterceptedClassesOn(Selector selector) { | |
| 117 return _backend.getInterceptedClassesOn(selector.name); | |
| 118 } | |
| 119 | |
| 120 Set<ClassElement> get interceptedClasses { | |
| 121 return _backend.interceptedClasses; | |
| 122 } | |
| 123 | |
| 124 void registerSpecializedGetInterceptor(Set<ClassElement> classes) { | |
| 125 _backend.registerSpecializedGetInterceptor(classes); | |
| 126 } | |
| 127 | |
| 128 js.Expression constructorAccess(ClassElement element) { | |
| 129 return _backend.emitter.constructorAccess(element); | |
| 130 } | |
| 131 | |
| 132 js.Name instanceFieldPropertyName(Element field) { | |
| 133 return _namer.instanceFieldPropertyName(field); | |
| 134 } | |
| 135 | |
| 136 js.Name instanceMethodName(FunctionElement element) { | |
| 137 return _namer.instanceMethodName(element); | |
| 138 } | |
| 139 | |
| 140 js.Expression prototypeAccess(ClassElement e, | |
| 141 {bool hasBeenInstantiated: false}) { | |
| 142 return _emitter.prototypeAccess(e, | |
| 143 hasBeenInstantiated: hasBeenInstantiated); | |
| 144 } | |
| 145 | |
| 146 js.Name getInterceptorName(Set<ClassElement> interceptedClasses) { | |
| 147 return _backend.namer.nameForGetInterceptor(interceptedClasses); | |
| 148 } | |
| 149 | |
| 150 js.Expression getInterceptorLibrary() { | |
| 151 return new js.VariableUse( | |
| 152 _backend.namer.globalObjectFor(_helpers.interceptorsLibrary)); | |
| 153 } | |
| 154 | |
| 155 FunctionElement getWrapExceptionHelper() { | |
| 156 return _helpers.wrapExceptionHelper; | |
| 157 } | |
| 158 | |
| 159 FunctionElement getExceptionUnwrapper() { | |
| 160 return _helpers.exceptionUnwrapper; | |
| 161 } | |
| 162 | |
| 163 FunctionElement getTraceFromException() { | |
| 164 return _helpers.traceFromException; | |
| 165 } | |
| 166 | |
| 167 FunctionElement getCreateRuntimeType() { | |
| 168 return _helpers.createRuntimeType; | |
| 169 } | |
| 170 | |
| 171 FunctionElement getRuntimeTypeToString() { | |
| 172 return _helpers.runtimeTypeToString; | |
| 173 } | |
| 174 | |
| 175 FunctionElement getRuntimeTypeArgument() { | |
| 176 return _helpers.getRuntimeTypeArgument; | |
| 177 } | |
| 178 | |
| 179 FunctionElement getTypeArgumentByIndex() { | |
| 180 return _helpers.getTypeArgumentByIndex; | |
| 181 } | |
| 182 | |
| 183 FunctionElement getAddRuntimeTypeInformation() { | |
| 184 return _helpers.setRuntimeTypeInfo; | |
| 185 } | |
| 186 | |
| 187 /// checkSubtype(value, $isT, typeArgs, $asT) | |
| 188 FunctionElement getCheckSubtype() { | |
| 189 return _helpers.checkSubtype; | |
| 190 } | |
| 191 | |
| 192 /// subtypeCast(value, $isT, typeArgs, $asT) | |
| 193 FunctionElement getSubtypeCast() { | |
| 194 return _helpers.subtypeCast; | |
| 195 } | |
| 196 | |
| 197 /// checkSubtypeOfRuntime(value, runtimeType) | |
| 198 FunctionElement getCheckSubtypeOfRuntimeType() { | |
| 199 return _helpers.checkSubtypeOfRuntimeType; | |
| 200 } | |
| 201 | |
| 202 /// subtypeOfRuntimeTypeCast(value, runtimeType) | |
| 203 FunctionElement getSubtypeOfRuntimeTypeCast() { | |
| 204 return _helpers.subtypeOfRuntimeTypeCast; | |
| 205 } | |
| 206 | |
| 207 js.Expression getRuntimeTypeName(ClassElement cls) { | |
| 208 return js.quoteName(_namer.runtimeTypeName(cls)); | |
| 209 } | |
| 210 | |
| 211 int getTypeVariableIndex(TypeVariableType variable) { | |
| 212 return variable.element.index; | |
| 213 } | |
| 214 | |
| 215 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { | |
| 216 ClassWorld classWorld = _compiler.world; | |
| 217 if (classWorld.isUsedAsMixin(cls)) return true; | |
| 218 | |
| 219 return _compiler.world.anyStrictSubclassOf(cls, (ClassElement subclass) { | |
| 220 return !_backend.rti.isTrivialSubstitution(subclass, cls); | |
| 221 }); | |
| 222 } | |
| 223 | |
| 224 js.Expression generateTypeRepresentation(DartType dartType, | |
| 225 List<js.Expression> arguments, CodegenRegistry registry) { | |
| 226 int variableIndex = 0; | |
| 227 js.Expression representation = _backend.rtiEncoder | |
| 228 .getTypeRepresentation(dartType, (_) => arguments[variableIndex++]); | |
| 229 assert(variableIndex == arguments.length); | |
| 230 // Representation contains JavaScript Arrays. | |
| 231 registry.registerInstantiatedClass(_helpers.jsArrayClass); | |
| 232 return representation; | |
| 233 } | |
| 234 | |
| 235 js.Name getTypeTestTag(DartType type) { | |
| 236 return _backend.namer.operatorIsType(type); | |
| 237 } | |
| 238 | |
| 239 js.Name getTypeSubstitutionTag(ClassElement element) { | |
| 240 return _backend.namer.substitutionName(element); | |
| 241 } | |
| 242 | |
| 243 bool operatorEqHandlesNullArgument(FunctionElement element) { | |
| 244 return _backend.operatorEqHandlesNullArgument(element); | |
| 245 } | |
| 246 | |
| 247 bool hasStrictSubtype(ClassElement element) { | |
| 248 return _compiler.world.hasAnyStrictSubtype(element); | |
| 249 } | |
| 250 | |
| 251 ClassElement get jsFixedArrayClass => _helpers.jsFixedArrayClass; | |
| 252 ClassElement get jsExtendableArrayClass => _helpers.jsExtendableArrayClass; | |
| 253 ClassElement get jsUnmodifiableArrayClass => | |
| 254 _helpers.jsUnmodifiableArrayClass; | |
| 255 ClassElement get jsMutableArrayClass => _helpers.jsMutableArrayClass; | |
| 256 | |
| 257 bool isStringClass(ClassElement classElement) => | |
| 258 classElement == _helpers.jsStringClass || | |
| 259 classElement == _compiler.coreClasses.stringClass; | |
| 260 | |
| 261 bool isBoolClass(ClassElement classElement) => | |
| 262 classElement == _helpers.jsBoolClass || | |
| 263 classElement == _compiler.coreClasses.boolClass; | |
| 264 | |
| 265 // TODO(sra,johnniwinther): Should this be part of CodegenRegistry? | |
| 266 void registerNativeBehavior(NativeBehavior nativeBehavior, node) { | |
| 267 if (nativeBehavior == null) return; | |
| 268 _enqueuer.nativeEnqueuer.registerNativeBehavior(nativeBehavior, node); | |
| 269 } | |
| 270 | |
| 271 ConstantValue getDefaultParameterValue(ParameterElement elem) { | |
| 272 return _backend.constants.getConstantValue(elem.constant); | |
| 273 } | |
| 274 | |
| 275 TypeMask extendMaskIfReachesAll(Selector selector, TypeMask mask) { | |
| 276 return _compiler.world.extendMaskIfReachesAll(selector, mask); | |
| 277 } | |
| 278 | |
| 279 FunctionElement get closureFromTearOff => _backend.helpers.closureFromTearOff; | |
| 280 | |
| 281 js.Name registerOneShotInterceptor(Selector selector) { | |
| 282 return _backend.registerOneShotInterceptor(selector); | |
| 283 } | |
| 284 | |
| 285 bool mayGenerateInstanceofCheck(DartType type) { | |
| 286 return _backend.mayGenerateInstanceofCheck(type); | |
| 287 } | |
| 288 | |
| 289 bool methodUsesReceiverArgument(FunctionElement function) { | |
| 290 assert(isInterceptedMethod(function)); | |
| 291 ClassElement class_ = function.enclosingClass.declaration; | |
| 292 return isInterceptorClass(class_) || isUsedAsMixin(class_); | |
| 293 } | |
| 294 } | |
| OLD | NEW |