| 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 '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
| 8 import '../elements/resolution_types.dart'; | 8 import '../elements/resolution_types.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../io/source_information.dart'; | 10 import '../io/source_information.dart'; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 /// | 28 /// |
| 29 /// [directLocals] is iterated, so it is "insertion ordered" to make the | 29 /// [directLocals] is iterated, so it is "insertion ordered" to make the |
| 30 /// iteration order a function only of insertions and not a function of | 30 /// iteration order a function only of insertions and not a function of |
| 31 /// e.g. Element hash codes. I'd prefer to use a SortedMap but some elements | 31 /// e.g. Element hash codes. I'd prefer to use a SortedMap but some elements |
| 32 /// don't have source locations for [Elements.compareByPosition]. | 32 /// don't have source locations for [Elements.compareByPosition]. |
| 33 Map<Local, HInstruction> directLocals = new Map<Local, HInstruction>(); | 33 Map<Local, HInstruction> directLocals = new Map<Local, HInstruction>(); |
| 34 Map<Local, CapturedVariable> redirectionMapping = | 34 Map<Local, CapturedVariable> redirectionMapping = |
| 35 new Map<Local, CapturedVariable>(); | 35 new Map<Local, CapturedVariable>(); |
| 36 final GraphBuilder builder; | 36 final GraphBuilder builder; |
| 37 ClosureClassMap closureData; | 37 ClosureClassMap closureData; |
| 38 Map<TypeVariableType, TypeVariableLocal> typeVariableLocals = | 38 Map<ResolutionTypeVariableType, TypeVariableLocal> typeVariableLocals = |
| 39 new Map<TypeVariableType, TypeVariableLocal>(); | 39 new Map<ResolutionTypeVariableType, TypeVariableLocal>(); |
| 40 final ExecutableElement executableContext; | 40 final ExecutableElement executableContext; |
| 41 | 41 |
| 42 /// The class that defines the current type environment or null if no type | 42 /// The class that defines the current type environment or null if no type |
| 43 /// variables are in scope. | 43 /// variables are in scope. |
| 44 ClassElement get contextClass => executableContext.contextClass; | 44 ClassElement get contextClass => executableContext.contextClass; |
| 45 | 45 |
| 46 /// The type of the current instance, if concrete. | 46 /// The type of the current instance, if concrete. |
| 47 /// | 47 /// |
| 48 /// This allows for handling fixed type argument in case of inlining. For | 48 /// This allows for handling fixed type argument in case of inlining. For |
| 49 /// instance, checking `'foo'` against `String` instead of `T` in `main`: | 49 /// instance, checking `'foo'` against `String` instead of `T` in `main`: |
| 50 /// | 50 /// |
| 51 /// class Foo<T> { | 51 /// class Foo<T> { |
| 52 /// T field; | 52 /// T field; |
| 53 /// Foo(this.field); | 53 /// Foo(this.field); |
| 54 /// } | 54 /// } |
| 55 /// main() { | 55 /// main() { |
| 56 /// new Foo<String>('foo'); | 56 /// new Foo<String>('foo'); |
| 57 /// } | 57 /// } |
| 58 /// | 58 /// |
| 59 /// [instanceType] is not used if it contains type variables, since these | 59 /// [instanceType] is not used if it contains type variables, since these |
| 60 /// might not be in scope or from the current instance. | 60 /// might not be in scope or from the current instance. |
| 61 /// | 61 /// |
| 62 final InterfaceType instanceType; | 62 final ResolutionInterfaceType instanceType; |
| 63 | 63 |
| 64 final Compiler _compiler; | 64 final Compiler _compiler; |
| 65 | 65 |
| 66 LocalsHandler(this.builder, this.executableContext, | 66 LocalsHandler(this.builder, this.executableContext, |
| 67 InterfaceType instanceType, this._compiler) | 67 ResolutionInterfaceType instanceType, this._compiler) |
| 68 : this.instanceType = | 68 : this.instanceType = |
| 69 instanceType == null || instanceType.containsTypeVariables | 69 instanceType == null || instanceType.containsTypeVariables |
| 70 ? null | 70 ? null |
| 71 : instanceType; | 71 : instanceType; |
| 72 | 72 |
| 73 ClosedWorld get closedWorld => builder.closedWorld; | 73 ClosedWorld get closedWorld => builder.closedWorld; |
| 74 | 74 |
| 75 CommonMasks get commonMasks => closedWorld.commonMasks; | 75 CommonMasks get commonMasks => closedWorld.commonMasks; |
| 76 | 76 |
| 77 GlobalTypeInferenceResults get _globalInferenceResults => | 77 GlobalTypeInferenceResults get _globalInferenceResults => |
| 78 _compiler.globalInference.results; | 78 _compiler.globalInference.results; |
| 79 | 79 |
| 80 /// Substituted type variables occurring in [type] into the context of | 80 /// Substituted type variables occurring in [type] into the context of |
| 81 /// [contextClass]. | 81 /// [contextClass]. |
| 82 DartType substInContext(DartType type) { | 82 ResolutionDartType substInContext(ResolutionDartType type) { |
| 83 if (contextClass != null) { | 83 if (contextClass != null) { |
| 84 ClassElement typeContext = Types.getClassContext(type); | 84 ClassElement typeContext = Types.getClassContext(type); |
| 85 if (typeContext != null) { | 85 if (typeContext != null) { |
| 86 type = type.substByContext(contextClass.asInstanceOf(typeContext)); | 86 type = type.substByContext(contextClass.asInstanceOf(typeContext)); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 if (instanceType != null) { | 89 if (instanceType != null) { |
| 90 type = type.substByContext(instanceType); | 90 type = type.substByContext(instanceType); |
| 91 } | 91 } |
| 92 return type; | 92 return type; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 378 } |
| 379 | 379 |
| 380 return activationVariables.putIfAbsent(local, () { | 380 return activationVariables.putIfAbsent(local, () { |
| 381 HLocalValue localValue = new HLocalValue(local, commonMasks.nonNullType) | 381 HLocalValue localValue = new HLocalValue(local, commonMasks.nonNullType) |
| 382 ..sourceInformation = sourceInformation; | 382 ..sourceInformation = sourceInformation; |
| 383 builder.graph.entry.addAtExit(localValue); | 383 builder.graph.entry.addAtExit(localValue); |
| 384 return localValue; | 384 return localValue; |
| 385 }); | 385 }); |
| 386 } | 386 } |
| 387 | 387 |
| 388 Local getTypeVariableAsLocal(TypeVariableType type) { | 388 Local getTypeVariableAsLocal(ResolutionTypeVariableType type) { |
| 389 return typeVariableLocals.putIfAbsent(type, () { | 389 return typeVariableLocals.putIfAbsent(type, () { |
| 390 return new TypeVariableLocal(type, executableContext); | 390 return new TypeVariableLocal(type, executableContext); |
| 391 }); | 391 }); |
| 392 } | 392 } |
| 393 | 393 |
| 394 /// Sets the [element] to [value]. If the element is boxed or stored in a | 394 /// Sets the [element] to [value]. If the element is boxed or stored in a |
| 395 /// closure then the method generates code to set the value. | 395 /// closure then the method generates code to set the value. |
| 396 void updateLocal(Local local, HInstruction value, | 396 void updateLocal(Local local, HInstruction value, |
| 397 {SourceInformation sourceInformation}) { | 397 {SourceInformation sourceInformation}) { |
| 398 if (value is HRef) { | 398 if (value is HRef) { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 final ExecutableElement executableContext; | 662 final ExecutableElement executableContext; |
| 663 | 663 |
| 664 // Avoid slow Object.hashCode. | 664 // Avoid slow Object.hashCode. |
| 665 final int hashCode = _nextHashCode = (_nextHashCode + 1).toUnsigned(30); | 665 final int hashCode = _nextHashCode = (_nextHashCode + 1).toUnsigned(30); |
| 666 static int _nextHashCode = 0; | 666 static int _nextHashCode = 0; |
| 667 | 667 |
| 668 SyntheticLocal(this.name, this.executableContext); | 668 SyntheticLocal(this.name, this.executableContext); |
| 669 | 669 |
| 670 toString() => 'SyntheticLocal($name)'; | 670 toString() => 'SyntheticLocal($name)'; |
| 671 } | 671 } |
| OLD | NEW |