Index: pkg/compiler/lib/src/js_backend/type_variable_handler.dart |
diff --git a/pkg/compiler/lib/src/js_backend/type_variable_handler.dart b/pkg/compiler/lib/src/js_backend/type_variable_handler.dart |
index 26e38a93dfebd0f99f0c6b6361cdb304bfc083da..4343b52ebfd1a80d6ad1992cce99079993993957 100644 |
--- a/pkg/compiler/lib/src/js_backend/type_variable_handler.dart |
+++ b/pkg/compiler/lib/src/js_backend/type_variable_handler.dart |
@@ -20,15 +20,15 @@ class TypeVariableHandler { |
* Maps a class element to a list with indices that point to type variables |
* constants for each of the class' type variables. |
*/ |
- Map<ClassElement, List<int>> _typeVariables = |
- new Map<ClassElement, List<int>>(); |
+ Map<ClassElement, List<jsAst.Expression>> _typeVariables = |
+ new Map<ClassElement, List<jsAst.Expression>>(); |
/** |
* Maps a TypeVariableType to the index pointing to the constant representing |
* the corresponding type variable at runtime. |
*/ |
- Map<TypeVariableElement, int> _typeVariableConstants = |
- new Map<TypeVariableElement, int>(); |
+ Map<TypeVariableElement, jsAst.Expression> _typeVariableConstants = |
+ new Map<TypeVariableElement, jsAst.Expression>(); |
TypeVariableHandler(this._compiler); |
@@ -60,14 +60,17 @@ class TypeVariableHandler { |
} |
} else { |
if (_backend.isAccessibleByReflection(cls)) { |
- _processTypeVariablesOf(cls); |
+ processTypeVariablesOf(cls); |
} |
} |
} |
- void _processTypeVariablesOf(ClassElement cls) { |
+ void processTypeVariablesOf(ClassElement cls) { |
+ // Do not process classes twice. |
+ if (_typeVariables.containsKey(cls)) return; |
+ |
InterfaceType typeVariableType = _typeVariableClass.thisType; |
- List<int> constants = <int>[]; |
+ List<jsAst.Expression> constants = <jsAst.Expression>[]; |
for (TypeVariableType currentTypeVariable in cls.typeVariables) { |
TypeVariableElement typeVariableElement = currentTypeVariable.element; |
@@ -82,10 +85,12 @@ class TypeVariableHandler { |
currentTypeVariable.name, |
_backend.constantSystem.createString( |
new DartString.literal(currentTypeVariable.name))); |
- int boundIndex = _metadataCollector.reifyType(typeVariableElement.bound); |
- ConstantExpression bound = new IntConstantExpression( |
- boundIndex, |
- _backend.constantSystem.createInt(boundIndex)); |
+ jsAst.Expression boundIndex = |
+ _metadataCollector.reifyType(typeVariableElement.bound); |
+ ConstantValue boundValue = |
+ new DummyConstantValue(DummyConstantKinds.typeVariableReference, |
+ boundIndex); |
+ ConstantExpression bound = new DummyConstantExpression(boundValue); |
ConstantExpression type = |
new TypeConstantExpression( |
_backend.constantSystem.createType( |
@@ -93,7 +98,6 @@ class TypeVariableHandler { |
cls.rawType); |
List<AstConstant> arguments = |
[wrapConstant(type), wrapConstant(name), wrapConstant(bound)]; |
- |
// TODO(johnniwinther): Support a less front-end specific creation of |
// constructed constants. |
AstConstant constant = |
@@ -126,17 +130,16 @@ class TypeVariableHandler { |
* entry in the list has already been reserved and the constant is added |
* there, otherwise a new entry for [c] is created. |
*/ |
- int _reifyTypeVariableConstant(ConstantValue c, TypeVariableElement variable) { |
+ jsAst.Expression _reifyTypeVariableConstant(ConstantValue c, |
+ TypeVariableElement variable) { |
jsAst.Expression name = _task.constantReference(c); |
- int index; |
+ jsAst.Expression result = _metadataCollector.reifyExpression(name); |
if (_typeVariableConstants.containsKey(variable)) { |
- index = _typeVariableConstants[variable]; |
- _metadataCollector.globalMetadata[index] = name; |
- } else { |
- index = _metadataCollector.addGlobalMetadata(name); |
- _typeVariableConstants[variable] = index; |
+ Placeholder placeholder = _typeVariableConstants[variable]; |
+ placeholder.bind(result); |
} |
- return index; |
+ _typeVariableConstants[variable] = result; |
+ return result; |
} |
/** |
@@ -149,21 +152,20 @@ class TypeVariableHandler { |
* [reifyTypeVariableConstant] will be called and the constant will be added |
* on the allocated entry. |
*/ |
- int reifyTypeVariable(TypeVariableElement variable) { |
+ jsAst.Expression reifyTypeVariable(TypeVariableElement variable) { |
if (_typeVariableConstants.containsKey(variable)) { |
return _typeVariableConstants[variable]; |
} |
- // TODO(15613): Remove quotes. |
- _metadataCollector.globalMetadata.add(js('"Placeholder for ${variable}"')); |
- return _typeVariableConstants[variable] = |
- _metadataCollector.globalMetadata.length - 1; |
+ Placeholder placeholder = |
+ _metadataCollector.getMetadataPlaceholder(variable); |
+ return _typeVariableConstants[variable] = placeholder; |
} |
- List<int> typeVariablesOf(ClassElement classElement) { |
- List<int> result = _typeVariables[classElement]; |
+ List<jsAst.Expression> typeVariablesOf(ClassElement classElement) { |
+ List<jsAst.Expression> result = _typeVariables[classElement]; |
if (result == null) { |
- result = const <int>[]; |
+ result = const <jsAst.Expression>[]; |
} |
return result; |
} |