Chromium Code Reviews| 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 static String forEachTypeVariable(Link collection, | |
|
ngeoffray
2012/09/17 15:31:14
Add a top-level comment on what this method does.
ngeoffray
2012/09/17 15:31:14
Link collection -> Link<TypeVariableType> collecti
kasperl
2012/09/18 06:06:12
Maybe change the name of this to stringifyTypeVari
karlklose
2012/09/19 06:40:45
Done.
| |
| 44 int numberOfInputs, | |
| 45 stringify(TypeVariableType variable, | |
| 46 bool hasValue)) { | |
| 47 int currentVariable = 0; | |
| 48 bool isFirst = true; | |
| 49 StringBuffer buffer = new StringBuffer(); | |
| 50 collection.forEach((TypeVariableType variable) { | |
| 51 if (!isFirst) buffer.add(", "); | |
| 52 bool hasValue = currentVariable < numberOfInputs; | |
| 53 buffer.add(stringify(variable, hasValue)); | |
| 54 isFirst = false; | |
| 55 currentVariable++; | |
| 56 }); | |
| 57 return buffer.toString(); | |
| 58 } | |
| 59 | |
| 60 /** | |
| 61 * Generate a string representation template for this element, using '#' to | |
| 62 * denote the place for the type argument input. If there are more type | |
| 63 * variables than [numberOfInputs], 'Dynamic' is used as the value for these | |
| 64 * arguments. | |
| 65 */ | |
| 66 static String generateRuntimeTypeString(ClassElement element, | |
| 67 int numberOfInputs) { | |
| 68 String elementName = element.name.slowToString(); | |
| 69 if (element.typeVariables.isEmpty()) return "'$elementName'"; | |
| 70 String stringify(_, hasValue) { | |
|
ngeoffray
2012/09/17 15:31:14
Please add types to the parameters.
karlklose
2012/09/19 06:40:45
Done.
karlklose
2012/09/19 06:40:45
I added it for the hasValue. I use '_' as a marker
| |
| 71 return hasValue ? "' + # + '" : "Dynamic"; | |
|
ngeoffray
2012/09/17 15:31:14
Use the => notation?
ngeoffray
2012/09/17 15:31:14
Why no ' + "Dynamic" + ' for the second case?
karlklose
2012/09/19 06:40:45
Done.
karlklose
2012/09/19 06:40:45
Done.
karlklose
2012/09/19 06:40:45
Which case do you mean?
| |
| 72 } | |
| 73 String arguments = forEachTypeVariable(element.typeVariables, | |
| 74 numberOfInputs, | |
| 75 stringify); | |
| 76 return "'$elementName<$arguments>'"; | |
| 77 } | |
| 78 | |
| 79 /** | |
| 80 * Generate a string template for the runtime type fields that contain the | |
| 81 * type descriptions of the reified type arguments, using '#' to denote the | |
| 82 * place for the type argument value, or [:null:] if there are more than | |
| 83 * [numberOfInputs] type variables. | |
| 84 */ | |
| 85 static String generateTypeVariableString(ClassElement element, | |
| 86 int numberOfInputs) { | |
| 87 StringBuffer buffer = new StringBuffer(); | |
|
ngeoffray
2012/09/17 15:31:14
This is unused.
karlklose
2012/09/19 06:40:45
Done, removed.
| |
| 88 String result = forEachTypeVariable(element.typeVariables, numberOfInputs, | |
| 89 (variable, bool hasValue) { | |
|
ngeoffray
2012/09/17 15:31:14
I find it easier to have this closure as a functio
karlklose
2012/09/19 06:40:45
Done.
| |
| 90 String value = hasValue ? "#" : "null"; | |
| 91 return "'${variable.name.slowToString()}': $value"; | |
| 92 }); | |
| 93 return result; | |
| 94 } | |
| 42 } | 95 } |
| OLD | NEW |