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

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

Issue 10908142: Add runtimeType() to Object which returns canonicalized instances of Type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Refactor. Created 8 years, 3 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('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 15 matching lines...) Expand all
26 #source('nodes.dart'); 26 #source('nodes.dart');
27 #source('optimize.dart'); 27 #source('optimize.dart');
28 #source('types.dart'); 28 #source('types.dart');
29 #source('types_propagation.dart'); 29 #source('types_propagation.dart');
30 #source('validate.dart'); 30 #source('validate.dart');
31 #source('variable_allocator.dart'); 31 #source('variable_allocator.dart');
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) {
kasperl 2012/09/14 12:35:37 Can this be a method call on type?
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 void foreach(Link collection,
kasperl 2012/09/14 12:35:37 forEach?
karlklose 2012/09/17 14:50:37 Changed the name.
44 int numberOfInputs,
45 f(bool isFirst, bool hasValue,
46 TypeVariableType variable)) {
47 int currentVariable = 0;
48 bool isFirst = true;
49 collection.forEach((TypeVariableType variable) {
50 f(isFirst, currentVariable < numberOfInputs, variable);
51 isFirst = false;
52 currentVariable++;
53 });
54 }
55
56 /**
57 * Generate a string representation template for this element, using '#' to
58 * denote the place for the type argument input. If there are more type
59 * variables than [numberOfInputs], 'Dynamic' is used as the value for these
60 * arguments.
61 */
62 static String generateRuntimeTypeString(ClassElement element,
63 int numberOfInputs) {
64 StringBuffer buffer = new StringBuffer(element.name.slowToString());
65 foreach(element.typeVariables, numberOfInputs,
66 (bool isFirst, bool hasValue, _) {
67 String value = hasValue ? "' + # + '" : "Dynamic";
68 buffer.add(isFirst ? "<$value" : ", $value");
kasperl 2012/09/14 12:35:37 If you remove the < here and move it out so you do
karlklose 2012/09/17 14:50:37 Done.
69 });
70 if (!element.typeVariables.isEmpty()) {
71 buffer.add(">");
72 }
73 return "'${buffer}'";
74 }
75
76 /**
77 * Generate a string template for the runtime type fields that contain the
78 * type descriptions of the reified type arguments, using '#' to denote the
79 * place for the type argument value, or [:null:] if there are more than
80 * [numberOfInputs] type variables.
81 */
82 static String generateTypeVariableString(ClassElement element,
83 int numberOfInputs) {
84 int currentVariable = 0;
kasperl 2012/09/14 12:35:37 Unused?
karlklose 2012/09/17 14:50:37 Done.
85 StringBuffer buffer = new StringBuffer();
86 foreach(element.typeVariables, numberOfInputs,
87 (bool isFirst, bool hasValue, variable) {
88 if (!isFirst) {
89 buffer.add(', ');
90 }
91 String value = hasValue ? "#" : "null";
92 buffer.add("'${variable.name.slowToString()}': $value");
93 });
94 return buffer.toString();
95 }
42 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698