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

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

Issue 10942028: Support class and typedef literals as expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address Peter's comments. Created 8 years, 1 month 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 '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';
11 import 'util/util.dart'; 11 import 'util/util.dart';
12 12
13 class RuntimeTypeInformation { 13 class RuntimeTypeInformation {
14
15 static final SourceString CACHE_HELPER_NAME =
16 const SourceString('getOrCreateCachedRuntimeType');
ahe 2012/11/05 09:47:05 How about moving this to compiler.dart?
17
14 /** 18 /**
15 * Names used for elements in runtime type information. This map is kept to 19 * Names used for elements in runtime type information. This map is kept to
16 * detect elements with the same name and use a different name instead. 20 * detect elements with the same name and use a different name instead.
17 */ 21 */
18 final Map<String, Element> usedNames = new Map<String, Element>(); 22 final Map<String, Element> usedNames = new Map<String, Element>();
19 23
20 /** Get a unique name for the element. */ 24 /** Get a unique name for the element. */
21 String getName(Element element) { 25 String getName(Element element) {
22 String guess = element.name.slowToString(); 26 String guess = element.name.slowToString();
23 String name = guess; 27 String name = guess;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 buffer.add(stringify(variable, hasValue)); 61 buffer.add(stringify(variable, hasValue));
58 isFirst = false; 62 isFirst = false;
59 currentVariable++; 63 currentVariable++;
60 }); 64 });
61 return buffer.toString(); 65 return buffer.toString();
62 } 66 }
63 67
64 /** 68 /**
65 * Generate a string representation template for this element, using '#' to 69 * Generate a string representation template for this element, using '#' to
66 * denote the place for the type argument input. If there are more type 70 * 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 71 * variables than [numberOfInputs], 'dynamic' is used as the value for these
68 * arguments. 72 * arguments.
69 */ 73 */
70 String generateRuntimeTypeString(ClassElement element, int numberOfInputs) { 74 String generateRuntimeTypeString(ClassElement element, int numberOfInputs) {
71 String elementName = getName(element); 75 String elementName = getName(element);
72 if (element.typeVariables.isEmpty) return "'$elementName'"; 76 if (element.typeVariables.isEmpty) return "$elementName";
73 String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "Dynamic"; 77 String stringify(_, bool hasValue) => hasValue ? "' + # + '" : "dynamic";
74 String arguments = stringifyTypeVariables(element.typeVariables, 78 String arguments = stringifyTypeVariables(element.typeVariables,
75 numberOfInputs, 79 numberOfInputs,
76 stringify); 80 stringify);
77 return "'$elementName<$arguments>'"; 81 return "$elementName<$arguments>";
78 } 82 }
79 83
80 /** 84 /**
81 * Generate a string template for the runtime type fields that contain the 85 * Generate a string template for the runtime type fields that contain the
82 * type descriptions of the reified type arguments, using '#' to denote the 86 * 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 87 * place for the type argument value, or [:null:] if there are more than
84 * [numberOfInputs] type variables. 88 * [numberOfInputs] type variables.
85 */ 89 */
86 static String generateTypeVariableString(ClassElement element, 90 static String generateTypeVariableString(ClassElement element,
87 int numberOfInputs) { 91 int numberOfInputs) {
88 String stringify(TypeVariableType variable, bool hasValue) { 92 String stringify(TypeVariableType variable, bool hasValue) {
89 return "'${variable.name.slowToString()}': #"; 93 return "'${variable.name.slowToString()}': #";
90 } 94 }
91 return stringifyTypeVariables(element.typeVariables, numberOfInputs, 95 return stringifyTypeVariables(element.typeVariables, numberOfInputs,
92 stringify); 96 stringify);
93 } 97 }
94 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698