OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import '../closure.dart'; | 5 import '../closure.dart'; |
6 import '../common.dart'; | 6 import '../common.dart'; |
7 import '../common/codegen.dart' show CodegenRegistry; | 7 import '../common/codegen.dart' show CodegenRegistry; |
8 import '../compiler.dart'; | 8 import '../compiler.dart'; |
9 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 Element get sourceElement; | 208 Element get sourceElement; |
209 | 209 |
210 // TODO(karlklose): this is needed to avoid a bug where the resolved type is | 210 // TODO(karlklose): this is needed to avoid a bug where the resolved type is |
211 // not stored on a type annotation in the closure translator. Remove when | 211 // not stored on a type annotation in the closure translator. Remove when |
212 // fixed. | 212 // fixed. |
213 bool hasDirectLocal(Local local) { | 213 bool hasDirectLocal(Local local) { |
214 return !localsHandler.isAccessedDirectly(local) || | 214 return !localsHandler.isAccessedDirectly(local) || |
215 localsHandler.directLocals[local] != null; | 215 localsHandler.directLocals[local] != null; |
216 } | 216 } |
217 | 217 |
| 218 HInstruction callSetRuntimeTypeInfoWithTypeArguments( |
| 219 DartType type, List<HInstruction> rtiInputs, HInstruction newObject) { |
| 220 if (!backend.classNeedsRti(type.element)) { |
| 221 return newObject; |
| 222 } |
| 223 |
| 224 HInstruction typeInfo = new HTypeInfoExpression( |
| 225 TypeInfoExpressionKind.INSTANCE, |
| 226 (type.element as ClassElement).thisType, |
| 227 rtiInputs, |
| 228 backend.dynamicType); |
| 229 add(typeInfo); |
| 230 return callSetRuntimeTypeInfo(typeInfo, newObject); |
| 231 } |
| 232 |
| 233 HInstruction callSetRuntimeTypeInfo( |
| 234 HInstruction typeInfo, HInstruction newObject) { |
| 235 // Set the runtime type information on the object. |
| 236 Element typeInfoSetterElement = backend.helpers.setRuntimeTypeInfo; |
| 237 pushInvokeStatic(typeInfoSetterElement, <HInstruction>[newObject, typeInfo], |
| 238 typeMask: backend.dynamicType, |
| 239 sourceInformation: newObject.sourceInformation); |
| 240 |
| 241 // The new object will now be referenced through the |
| 242 // `setRuntimeTypeInfo` call. We therefore set the type of that |
| 243 // instruction to be of the object's type. |
| 244 assert(invariant(CURRENT_ELEMENT_SPANNABLE, |
| 245 stack.last is HInvokeStatic || stack.last == newObject, |
| 246 message: "Unexpected `stack.last`: Found ${stack.last}, " |
| 247 "expected ${newObject} or an HInvokeStatic. " |
| 248 "State: typeInfo=$typeInfo, stack=$stack.")); |
| 249 stack.last.instructionType = newObject.instructionType; |
| 250 return pop(); |
| 251 } |
| 252 |
| 253 void pushInvokeStatic(MethodElement element, List<HInstruction> arguments, |
| 254 {TypeMask typeMask, |
| 255 InterfaceType instanceType, |
| 256 SourceInformation sourceInformation, |
| 257 ast.Node location}); |
| 258 |
218 /// The element for which this SSA builder is being used. | 259 /// The element for which this SSA builder is being used. |
219 Element get targetElement; | 260 Element get targetElement; |
220 TypeBuilder get typeBuilder; | 261 TypeBuilder get typeBuilder; |
221 } | 262 } |
222 | 263 |
223 class ReifiedTypeRepresentationBuilder | 264 class ReifiedTypeRepresentationBuilder |
224 implements DartTypeVisitor<dynamic, GraphBuilder> { | 265 implements DartTypeVisitor<dynamic, GraphBuilder> { |
225 final ClosedWorld closedWorld; | 266 final ClosedWorld closedWorld; |
226 | 267 |
227 ReifiedTypeRepresentationBuilder(this.closedWorld); | 268 ReifiedTypeRepresentationBuilder(this.closedWorld); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 348 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
308 unaliased.accept(this, builder); | 349 unaliased.accept(this, builder); |
309 } | 350 } |
310 | 351 |
311 void visitDynamicType(DynamicType type, GraphBuilder builder) { | 352 void visitDynamicType(DynamicType type, GraphBuilder builder) { |
312 JavaScriptBackend backend = builder.compiler.backend; | 353 JavaScriptBackend backend = builder.compiler.backend; |
313 ClassElement cls = backend.helpers.DynamicRuntimeType; | 354 ClassElement cls = backend.helpers.DynamicRuntimeType; |
314 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld))); | 355 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld))); |
315 } | 356 } |
316 } | 357 } |
OLD | NEW |