Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/runtime_types.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/runtime_types.dart b/sdk/lib/_internal/compiler/implementation/runtime_types.dart |
| index c583cb13ed4d55d32a94f737c04792f3274c7282..683b7afe4c17071ffac74df20ddc2499c7bf5b8a 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/runtime_types.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/runtime_types.dart |
| @@ -11,30 +11,10 @@ import 'universe/universe.dart'; |
| import 'util/util.dart'; |
| class RuntimeTypeInformation { |
| - |
| static final SourceString CACHE_HELPER_NAME = |
| const SourceString('getOrCreateCachedRuntimeType'); |
| - /** |
| - * Names used for elements in runtime type information. This map is kept to |
| - * detect elements with the same name and use a different name instead. |
| - */ |
| - final Map<String, Element> usedNames = new Map<String, Element>(); |
| - |
| - /** Get a unique name for the element. */ |
| - String getName(Element element) { |
| - String guess = element.name.slowToString(); |
| - String name = guess; |
| - int id = 0; |
| - while (usedNames.containsKey(name) && usedNames[name] != element) { |
| - name = '$guess@$id'; |
| - id++; |
| - } |
| - usedNames[name] = element; |
| - return name; |
| - } |
| - |
| - bool hasTypeArguments(DartType type) { |
| + static bool hasTypeArguments(DartType type) { |
| if (type is InterfaceType) { |
| InterfaceType interfaceType = type; |
| return !interfaceType.arguments.isEmpty; |
| @@ -42,57 +22,26 @@ class RuntimeTypeInformation { |
| return false; |
| } |
| + static int getTypeVariableIndex(TypeVariableType variable) { |
| + ClassElement classElement = variable.element.getEnclosingClass(); |
| + Link<DartType> variables = classElement.typeVariables; |
| + for (int index = 0; !variables.isEmpty; |
| + index++, variables = variables.tail) { |
| + if (variables.head == variable) return index; |
| + } |
| + } |
| + |
| /** |
| - * Map type variables to strings calling [:stringify:] and joins the results |
| - * to a single string separated by commas. |
| - * The argument [:hasValue:] is used to treat variables that will not receive |
| - * a value at the use site of the code that is generated with this function. |
| + * Build the type argument string for raw usage of [classElement], that is, |
| + * using [:dynamic:] for each type argument. |
|
ngeoffray
2012/11/15 08:58:09
No need for ':'?
karlklose
2012/11/16 13:37:19
Done.
|
| */ |
| - static String stringifyTypeVariables(Link collection, |
| - int numberOfInputs, |
| - stringify(TypeVariableType variable, |
| - bool hasValue)) { |
| - int currentVariable = 0; |
| + static String buildRawArguments(ClassElement classElement) { |
| bool isFirst = true; |
| StringBuffer buffer = new StringBuffer(); |
| - collection.forEach((TypeVariableType variable) { |
| - if (!isFirst) buffer.add(", "); |
| - bool hasValue = currentVariable < numberOfInputs; |
| - buffer.add(stringify(variable, hasValue)); |
| - isFirst = false; |
| - currentVariable++; |
| + classElement.typeVariables.forEach((_) { |
| + if (!isFirst) buffer.add(', '); |
| + buffer.add('dynamic'); |
| }); |
| return buffer.toString(); |
| } |
| - |
| - /** |
| - * Generate a string representation template for this element, using '#' to |
| - * denote the place for the type argument input. If there are more type |
| - * variables than [numberOfInputs], 'dynamic' is used as the value for these |
| - * arguments. |
| - */ |
| - String generateRuntimeTypeString(ClassElement element, int numberOfInputs) { |
| - String elementName = getName(element); |
| - if (element.typeVariables.isEmpty) return "$elementName"; |
| - String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "dynamic"; |
| - String arguments = stringifyTypeVariables(element.typeVariables, |
| - numberOfInputs, |
| - stringify); |
| - return "$elementName<$arguments>"; |
| - } |
| - |
| - /** |
| - * Generate a string template for the runtime type fields that contain the |
| - * type descriptions of the reified type arguments, using '#' to denote the |
| - * place for the type argument value, or [:null:] if there are more than |
| - * [numberOfInputs] type variables. |
| - */ |
| - static String generateTypeVariableString(ClassElement element, |
| - int numberOfInputs) { |
| - String stringify(TypeVariableType variable, bool hasValue) { |
| - return "'${variable.name.slowToString()}': #"; |
| - } |
| - return stringifyTypeVariables(element.typeVariables, numberOfInputs, |
| - stringify); |
| - } |
| } |