| 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'); |
| 11 #import('../source_map_builder.dart'); | 11 #import('../source_map_builder.dart'); |
| 12 #import('../elements/elements.dart'); | 12 #import('../elements/elements.dart'); |
| 13 #import('../js_backend/js_backend.dart'); | 13 #import('../js_backend/js_backend.dart'); |
| 14 #import('../native_handler.dart', prefix: 'native'); | 14 #import('../native_handler.dart', prefix: 'native'); |
| 15 #import('../runtime_types.dart'); |
| 15 #import('../scanner/scannerlib.dart'); | 16 #import('../scanner/scannerlib.dart'); |
| 16 #import('../tree/tree.dart'); | 17 #import('../tree/tree.dart'); |
| 17 #import('../universe/universe.dart'); | 18 #import('../universe/universe.dart'); |
| 18 #import('../util/util.dart'); | 19 #import('../util/util.dart'); |
| 19 #import('../util/characters.dart'); | 20 #import('../util/characters.dart'); |
| 20 | 21 |
| 21 #source('bailout.dart'); | 22 #source('bailout.dart'); |
| 22 #source('builder.dart'); | 23 #source('builder.dart'); |
| 23 #source('codegen.dart'); | 24 #source('codegen.dart'); |
| 24 #source('codegen_helpers.dart'); | 25 #source('codegen_helpers.dart'); |
| 25 #source('js_names.dart'); | 26 #source('js_names.dart'); |
| 26 #source('nodes.dart'); | 27 #source('nodes.dart'); |
| 27 #source('optimize.dart'); | 28 #source('optimize.dart'); |
| 28 #source('types.dart'); | 29 #source('types.dart'); |
| 29 #source('types_propagation.dart'); | 30 #source('types_propagation.dart'); |
| 30 #source('validate.dart'); | 31 #source('validate.dart'); |
| 31 #source('variable_allocator.dart'); | 32 #source('variable_allocator.dart'); |
| 32 #source('value_range_analyzer.dart'); | 33 #source('value_range_analyzer.dart'); |
| 33 #source('value_set.dart'); | 34 #source('value_set.dart'); |
| 34 | |
| 35 class RuntimeTypeInformation { | |
| 36 bool hasTypeArguments(DartType type) { | |
| 37 if (type is InterfaceType) { | |
| 38 InterfaceType interfaceType = type; | |
| 39 return !interfaceType.arguments.isEmpty(); | |
| 40 } | |
| 41 return false; | |
| 42 } | |
| 43 | |
| 44 /** | |
| 45 * Map type variables to strings calling [:stringify:] and joins the results | |
| 46 * to a single string separated by commas. | |
| 47 * The argument [:hasValue:] is used to treat variables that will not receive | |
| 48 * a value at the use site of the code that is generated with this function. | |
| 49 */ | |
| 50 static String stringifyTypeVariables(Link collection, | |
| 51 int numberOfInputs, | |
| 52 stringify(TypeVariableType variable, | |
| 53 bool hasValue)) { | |
| 54 int currentVariable = 0; | |
| 55 bool isFirst = true; | |
| 56 StringBuffer buffer = new StringBuffer(); | |
| 57 collection.forEach((TypeVariableType variable) { | |
| 58 if (!isFirst) buffer.add(", "); | |
| 59 bool hasValue = currentVariable < numberOfInputs; | |
| 60 buffer.add(stringify(variable, hasValue)); | |
| 61 isFirst = false; | |
| 62 currentVariable++; | |
| 63 }); | |
| 64 return buffer.toString(); | |
| 65 } | |
| 66 | |
| 67 /** | |
| 68 * Generate a string representation template for this element, using '#' to | |
| 69 * denote the place for the type argument input. If there are more type | |
| 70 * variables than [numberOfInputs], 'Dynamic' is used as the value for these | |
| 71 * arguments. | |
| 72 */ | |
| 73 static String generateRuntimeTypeString(ClassElement element, | |
| 74 int numberOfInputs) { | |
| 75 String elementName = element.name.slowToString(); | |
| 76 if (element.typeVariables.isEmpty()) return "'$elementName'"; | |
| 77 String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "Dynamic"; | |
| 78 String arguments = stringifyTypeVariables(element.typeVariables, | |
| 79 numberOfInputs, | |
| 80 stringify); | |
| 81 return "'$elementName<$arguments>'"; | |
| 82 } | |
| 83 | |
| 84 /** | |
| 85 * Generate a string template for the runtime type fields that contain the | |
| 86 * type descriptions of the reified type arguments, using '#' to denote the | |
| 87 * place for the type argument value, or [:null:] if there are more than | |
| 88 * [numberOfInputs] type variables. | |
| 89 */ | |
| 90 static String generateTypeVariableString(ClassElement element, | |
| 91 int numberOfInputs) { | |
| 92 String stringify(TypeVariableType variable, bool hasValue) { | |
| 93 return "'${variable.name.slowToString()}': #"; | |
| 94 } | |
| 95 return stringifyTypeVariables(element.typeVariables, numberOfInputs, | |
| 96 stringify); | |
| 97 } | |
| 98 } | |
| OLD | NEW |