Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart2js.ir_builder; | 5 library dart2js.ir_builder; |
| 6 | 6 |
| 7 import '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../constants/values.dart' show PrimitiveConstantValue; | 9 import '../constants/values.dart' show PrimitiveConstantValue; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 if (variable != other.index2variable[i]) return false; | 104 if (variable != other.index2variable[i]) return false; |
| 105 | 105 |
| 106 // The variable maps to the same index in both environments. | 106 // The variable maps to the same index in both environments. |
| 107 int index = variable2index[variable]; | 107 int index = variable2index[variable]; |
| 108 if (index == null || index != other.variable2index[variable]) { | 108 if (index == null || index != other.variable2index[variable]) { |
| 109 return false; | 109 return false; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 return true; | 112 return true; |
| 113 } | 113 } |
| 114 | |
| 115 bool contains(Local local) => variable2index.containsKey(local); | |
| 114 } | 116 } |
| 115 | 117 |
| 116 /// The abstract base class of objects that emit jumps to a continuation and | 118 /// The abstract base class of objects that emit jumps to a continuation and |
| 117 /// give a handle to the continuation and its environment. | 119 /// give a handle to the continuation and its environment. |
| 118 abstract class JumpCollector { | 120 abstract class JumpCollector { |
| 119 final JumpTarget target; | 121 final JumpTarget target; |
| 120 | 122 |
| 121 ir.Continuation _continuation = null; | 123 ir.Continuation _continuation = null; |
| 122 final Environment _continuationEnvironment; | 124 final Environment _continuationEnvironment; |
| 123 | 125 |
| (...skipping 2503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2627 } | 2629 } |
| 2628 } | 2630 } |
| 2629 | 2631 |
| 2630 /// Obtains the internal type representation of the type held in [variable]. | 2632 /// Obtains the internal type representation of the type held in [variable]. |
| 2631 /// | 2633 /// |
| 2632 /// The value of [variable] is taken from the current receiver object, or | 2634 /// The value of [variable] is taken from the current receiver object, or |
| 2633 /// if we are currently building a constructor field initializer, from the | 2635 /// if we are currently building a constructor field initializer, from the |
| 2634 /// corresponding type argument (field initializers are evaluated before the | 2636 /// corresponding type argument (field initializers are evaluated before the |
| 2635 /// receiver object is created). | 2637 /// receiver object is created). |
| 2636 ir.Primitive buildTypeVariableAccess(TypeVariableType variable) { | 2638 ir.Primitive buildTypeVariableAccess(TypeVariableType variable) { |
| 2637 ir.Parameter accessTypeArgumentParameter() { | 2639 // If the local exists in the environment, use that. |
| 2638 for (int i = 0; i < environment.length; i++) { | 2640 // This is put here when we are inside a constructor or field initializer, |
| 2639 Local local = environment.index2variable[i]; | 2641 // (or possibly a closure inside one of these). |
| 2640 if (local is TypeInformationParameter && | 2642 Local local = new TypeVariableLocal(variable, state.currentElement); |
| 2641 local.variable == variable.element) { | 2643 if (environment.contains(local)) { |
| 2642 return environment.index2value[i]; | 2644 return environment.lookup(local); |
| 2643 } | |
| 2644 } | |
| 2645 throw 'unable to find constructor parameter for type variable $variable.'; | |
| 2646 } | 2645 } |
| 2647 | 2646 |
| 2648 if (jsState.inInitializers) { | 2647 // If the type variable is not in a local, access it one the receiver. |
|
karlklose
2015/05/28 08:12:19
'access it one the receiver' -> 'read the value fr
asgerf
2015/05/28 09:34:21
Done.
| |
| 2649 return accessTypeArgumentParameter(); | 2648 ir.Primitive target = buildThis(); |
| 2650 } else { | 2649 return addPrimitive(new ir.ReadTypeVariable(variable, target)); |
| 2651 ir.Primitive target = buildThis(); | 2650 } |
| 2652 return addPrimitive(new ir.ReadTypeVariable(variable, target)); | 2651 |
| 2653 } | 2652 /// Make the given type variable accessible through the local environment |
| 2653 /// with the value of [binding]. | |
| 2654 void declareTypeVariable(TypeVariableType variable, DartType binding) { | |
| 2655 environment.extend( | |
| 2656 new TypeVariableLocal(variable, state.currentElement), | |
| 2657 buildTypeExpression(binding)); | |
| 2654 } | 2658 } |
| 2655 | 2659 |
| 2656 @override | 2660 @override |
| 2657 ir.Primitive buildReifyTypeVariable(TypeVariableType variable) { | 2661 ir.Primitive buildReifyTypeVariable(TypeVariableType variable) { |
| 2658 ir.Primitive typeArgument = buildTypeVariableAccess(variable); | 2662 ir.Primitive typeArgument = buildTypeVariableAccess(variable); |
| 2659 return addPrimitive(new ir.ReifyRuntimeType(typeArgument)); | 2663 return addPrimitive(new ir.ReifyRuntimeType(typeArgument)); |
| 2660 } | 2664 } |
| 2661 | 2665 |
| 2662 ir.Primitive buildInvocationMirror(Selector selector, | 2666 ir.Primitive buildInvocationMirror(Selector selector, |
| 2663 List<ir.Primitive> arguments) { | 2667 List<ir.Primitive> arguments) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2757 final DartType type; | 2761 final DartType type; |
| 2758 final LocalVariableElement exceptionVariable; | 2762 final LocalVariableElement exceptionVariable; |
| 2759 final LocalVariableElement stackTraceVariable; | 2763 final LocalVariableElement stackTraceVariable; |
| 2760 final SubbuildFunction buildCatchBlock; | 2764 final SubbuildFunction buildCatchBlock; |
| 2761 | 2765 |
| 2762 CatchClauseInfo({this.type, | 2766 CatchClauseInfo({this.type, |
| 2763 this.exceptionVariable, | 2767 this.exceptionVariable, |
| 2764 this.stackTraceVariable, | 2768 this.stackTraceVariable, |
| 2765 this.buildCatchBlock}); | 2769 this.buildCatchBlock}); |
| 2766 } | 2770 } |
| 2767 | |
| 2768 /// Synthetic parameter to a JavaScript factory method that takes the type | |
| 2769 /// argument given for the type variable [variable]. | |
| 2770 class TypeInformationParameter implements Local { | |
| 2771 final TypeVariableElement variable; | |
| 2772 final ExecutableElement executableContext; | |
| 2773 TypeInformationParameter(this.variable, this.executableContext); | |
| 2774 String get name => variable.name; | |
| 2775 } | |
| OLD | NEW |