| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('ssa'); | 5 #library('ssa'); |
| 6 | 6 |
| 7 #import('../closure.dart'); | 7 #import('../closure.dart'); |
| 8 #import('../js/js.dart', prefix: 'js'); | 8 #import('../js/js.dart', prefix: 'js'); |
| 9 #import('../leg.dart'); | 9 #import('../leg.dart'); |
| 10 #import('../source_file.dart'); | 10 #import('../source_file.dart'); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #source('value_set.dart'); | 32 #source('value_set.dart'); |
| 33 | 33 |
| 34 class RuntimeTypeInformation { | 34 class RuntimeTypeInformation { |
| 35 bool hasTypeArguments(DartType type) { | 35 bool hasTypeArguments(DartType type) { |
| 36 if (type is InterfaceType) { | 36 if (type is InterfaceType) { |
| 37 InterfaceType interfaceType = type; | 37 InterfaceType interfaceType = type; |
| 38 return !interfaceType.arguments.isEmpty(); | 38 return !interfaceType.arguments.isEmpty(); |
| 39 } | 39 } |
| 40 return false; | 40 return false; |
| 41 } | 41 } |
| 42 | |
| 43 /** | |
| 44 * Map type variables to strings calling [:stringify:] and joins the results | |
| 45 * to a single string separated by commas. | |
| 46 * The argument [:hasValue:] is used to treat variables that will not receive | |
| 47 * a value at the use site of the code that is generated with this function. | |
| 48 */ | |
| 49 static String stringifyTypeVariables(Link collection, | |
| 50 int numberOfInputs, | |
| 51 stringify(TypeVariableType variable, | |
| 52 bool hasValue)) { | |
| 53 int currentVariable = 0; | |
| 54 bool isFirst = true; | |
| 55 StringBuffer buffer = new StringBuffer(); | |
| 56 collection.forEach((TypeVariableType variable) { | |
| 57 if (!isFirst) buffer.add(", "); | |
| 58 bool hasValue = currentVariable < numberOfInputs; | |
| 59 buffer.add(stringify(variable, hasValue)); | |
| 60 isFirst = false; | |
| 61 currentVariable++; | |
| 62 }); | |
| 63 return buffer.toString(); | |
| 64 } | |
| 65 | |
| 66 /** | |
| 67 * Generate a string representation template for this element, using '#' to | |
| 68 * denote the place for the type argument input. If there are more type | |
| 69 * variables than [numberOfInputs], 'Dynamic' is used as the value for these | |
| 70 * arguments. | |
| 71 */ | |
| 72 static String generateRuntimeTypeString(ClassElement element, | |
| 73 int numberOfInputs) { | |
| 74 String elementName = element.name.slowToString(); | |
| 75 if (element.typeVariables.isEmpty()) return "'$elementName'"; | |
| 76 String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "Dynamic"; | |
| 77 String arguments = stringifyTypeVariables(element.typeVariables, | |
| 78 numberOfInputs, | |
| 79 stringify); | |
| 80 return "'$elementName<$arguments>'"; | |
| 81 } | |
| 82 | |
| 83 /** | |
| 84 * Generate a string template for the runtime type fields that contain the | |
| 85 * type descriptions of the reified type arguments, using '#' to denote the | |
| 86 * place for the type argument value, or [:null:] if there are more than | |
| 87 * [numberOfInputs] type variables. | |
| 88 */ | |
| 89 static String generateTypeVariableString(ClassElement element, | |
| 90 int numberOfInputs) { | |
| 91 String stringify(TypeVariableType variable, bool hasValue) { | |
| 92 String value = hasValue ? "#" : "null"; | |
| 93 return "'${variable.name.slowToString()}': $value"; | |
| 94 } | |
| 95 return stringifyTypeVariables(element.typeVariables, numberOfInputs, | |
| 96 stringify); | |
| 97 } | |
| 98 } | 42 } |
| OLD | NEW |