Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: lib/compiler/implementation/runtime_types.dart

Issue 11086074: Give different runtime type representations to different types with the same name. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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('leg.dart'); 7 #import('leg.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');
11 #import('util/util.dart'); 11 #import('util/util.dart');
12 12
13 class RuntimeTypeInformation { 13 class RuntimeTypeInformation {
14 /**
15 * Names used for elements in runtime type information. This map is kept to
16 * detect elements with the same name and add a library prefix to them.
kasperl 2012/10/11 13:18:51 You're not really adding a library prefix to them.
karlklose 2012/10/11 13:29:42 Done.
17 */
18 final Map<String, Element> usedNames = new Map<String, Element>();
19
20 /** Get a unique name for the element. */
21 String getName(Element element) {
22 String guess = element.name.slowToString();
23 String name = guess;
24 int id = 0;
25 while (usedNames.containsKey(name) && usedNames[name] != element) {
26 name = '$guess@$id';
kasperl 2012/10/11 13:18:51 You need to increase id in here.
karlklose 2012/10/11 13:29:42 Done.
27 }
28 usedNames[name] = element;
29 return name;
30 }
31
14 bool hasTypeArguments(DartType type) { 32 bool hasTypeArguments(DartType type) {
15 if (type is InterfaceType) { 33 if (type is InterfaceType) {
16 InterfaceType interfaceType = type; 34 InterfaceType interfaceType = type;
17 return !interfaceType.arguments.isEmpty(); 35 return !interfaceType.arguments.isEmpty();
18 } 36 }
19 return false; 37 return false;
20 } 38 }
21 39
22 /** 40 /**
23 * Map type variables to strings calling [:stringify:] and joins the results 41 * Map type variables to strings calling [:stringify:] and joins the results
(...skipping 17 matching lines...) Expand all
41 }); 59 });
42 return buffer.toString(); 60 return buffer.toString();
43 } 61 }
44 62
45 /** 63 /**
46 * Generate a string representation template for this element, using '#' to 64 * Generate a string representation template for this element, using '#' to
47 * denote the place for the type argument input. If there are more type 65 * denote the place for the type argument input. If there are more type
48 * variables than [numberOfInputs], 'Dynamic' is used as the value for these 66 * variables than [numberOfInputs], 'Dynamic' is used as the value for these
49 * arguments. 67 * arguments.
50 */ 68 */
51 static String generateRuntimeTypeString(ClassElement element, 69 String generateRuntimeTypeString(ClassElement element, int numberOfInputs) {
52 int numberOfInputs) { 70 String elementName = getName(element);
53 String elementName = element.name.slowToString();
54 if (element.typeVariables.isEmpty()) return "'$elementName'"; 71 if (element.typeVariables.isEmpty()) return "'$elementName'";
55 String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "Dynamic"; 72 String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "Dynamic";
56 String arguments = stringifyTypeVariables(element.typeVariables, 73 String arguments = stringifyTypeVariables(element.typeVariables,
57 numberOfInputs, 74 numberOfInputs,
58 stringify); 75 stringify);
59 return "'$elementName<$arguments>'"; 76 return "'$elementName<$arguments>'";
60 } 77 }
61 78
62 /** 79 /**
63 * Generate a string template for the runtime type fields that contain the 80 * Generate a string template for the runtime type fields that contain the
64 * type descriptions of the reified type arguments, using '#' to denote the 81 * type descriptions of the reified type arguments, using '#' to denote the
65 * place for the type argument value, or [:null:] if there are more than 82 * place for the type argument value, or [:null:] if there are more than
66 * [numberOfInputs] type variables. 83 * [numberOfInputs] type variables.
67 */ 84 */
68 static String generateTypeVariableString(ClassElement element, 85 static String generateTypeVariableString(ClassElement element,
69 int numberOfInputs) { 86 int numberOfInputs) {
70 String stringify(TypeVariableType variable, bool hasValue) { 87 String stringify(TypeVariableType variable, bool hasValue) {
71 return "'${variable.name.slowToString()}': #"; 88 return "'${variable.name.slowToString()}': #";
72 } 89 }
73 return stringifyTypeVariables(element.typeVariables, numberOfInputs, 90 return stringifyTypeVariables(element.typeVariables, numberOfInputs,
74 stringify); 91 stringify);
75 } 92 }
76 } 93 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | tests/language/first_class_types_libraries_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698