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 runtime_types; | 5 library runtime_types; |
6 | 6 |
7 import 'dart2jslib.dart'; | 7 import 'dart2jslib.dart'; |
8 import 'elements/elements.dart'; | 8 import 'elements/elements.dart'; |
9 import 'tree/tree.dart'; | 9 import 'tree/tree.dart'; |
10 import 'universe/universe.dart'; | 10 import 'universe/universe.dart'; |
(...skipping 15 matching lines...) Expand all Loading... |
26 name = '$guess@$id'; | 26 name = '$guess@$id'; |
27 id++; | 27 id++; |
28 } | 28 } |
29 usedNames[name] = element; | 29 usedNames[name] = element; |
30 return name; | 30 return name; |
31 } | 31 } |
32 | 32 |
33 bool hasTypeArguments(DartType type) { | 33 bool hasTypeArguments(DartType type) { |
34 if (type is InterfaceType) { | 34 if (type is InterfaceType) { |
35 InterfaceType interfaceType = type; | 35 InterfaceType interfaceType = type; |
36 return !interfaceType.arguments.isEmpty(); | 36 return !interfaceType.arguments.isEmpty; |
37 } | 37 } |
38 return false; | 38 return false; |
39 } | 39 } |
40 | 40 |
41 /** | 41 /** |
42 * Map type variables to strings calling [:stringify:] and joins the results | 42 * Map type variables to strings calling [:stringify:] and joins the results |
43 * to a single string separated by commas. | 43 * to a single string separated by commas. |
44 * The argument [:hasValue:] is used to treat variables that will not receive | 44 * The argument [:hasValue:] is used to treat variables that will not receive |
45 * a value at the use site of the code that is generated with this function. | 45 * a value at the use site of the code that is generated with this function. |
46 */ | 46 */ |
(...skipping 15 matching lines...) Expand all Loading... |
62 } | 62 } |
63 | 63 |
64 /** | 64 /** |
65 * Generate a string representation template for this element, using '#' to | 65 * Generate a string representation template for this element, using '#' to |
66 * denote the place for the type argument input. If there are more type | 66 * denote the place for the type argument input. If there are more type |
67 * variables than [numberOfInputs], 'Dynamic' is used as the value for these | 67 * variables than [numberOfInputs], 'Dynamic' is used as the value for these |
68 * arguments. | 68 * arguments. |
69 */ | 69 */ |
70 String generateRuntimeTypeString(ClassElement element, int numberOfInputs) { | 70 String generateRuntimeTypeString(ClassElement element, int numberOfInputs) { |
71 String elementName = getName(element); | 71 String elementName = getName(element); |
72 if (element.typeVariables.isEmpty()) return "'$elementName'"; | 72 if (element.typeVariables.isEmpty) return "'$elementName'"; |
73 String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "Dynamic"; | 73 String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "Dynamic"; |
74 String arguments = stringifyTypeVariables(element.typeVariables, | 74 String arguments = stringifyTypeVariables(element.typeVariables, |
75 numberOfInputs, | 75 numberOfInputs, |
76 stringify); | 76 stringify); |
77 return "'$elementName<$arguments>'"; | 77 return "'$elementName<$arguments>'"; |
78 } | 78 } |
79 | 79 |
80 /** | 80 /** |
81 * Generate a string template for the runtime type fields that contain the | 81 * Generate a string template for the runtime type fields that contain the |
82 * type descriptions of the reified type arguments, using '#' to denote the | 82 * type descriptions of the reified type arguments, using '#' to denote the |
83 * place for the type argument value, or [:null:] if there are more than | 83 * place for the type argument value, or [:null:] if there are more than |
84 * [numberOfInputs] type variables. | 84 * [numberOfInputs] type variables. |
85 */ | 85 */ |
86 static String generateTypeVariableString(ClassElement element, | 86 static String generateTypeVariableString(ClassElement element, |
87 int numberOfInputs) { | 87 int numberOfInputs) { |
88 String stringify(TypeVariableType variable, bool hasValue) { | 88 String stringify(TypeVariableType variable, bool hasValue) { |
89 return "'${variable.name.slowToString()}': #"; | 89 return "'${variable.name.slowToString()}': #"; |
90 } | 90 } |
91 return stringifyTypeVariables(element.typeVariables, numberOfInputs, | 91 return stringifyTypeVariables(element.typeVariables, numberOfInputs, |
92 stringify); | 92 stringify); |
93 } | 93 } |
94 } | 94 } |
OLD | NEW |