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

Unified 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: Address more comments. 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 side-by-side diff with in-line comments
Download patch
Index: lib/compiler/implementation/ssa/ssa.dart
diff --git a/lib/compiler/implementation/ssa/ssa.dart b/lib/compiler/implementation/ssa/ssa.dart
index 7eaec79d40738eed6174894cb48c30da875f33e7..0ef3ad86d8e7685c37f277094265ef277587eaa9 100644
--- a/lib/compiler/implementation/ssa/ssa.dart
+++ b/lib/compiler/implementation/ssa/ssa.dart
@@ -39,4 +39,57 @@ class RuntimeTypeInformation {
}
return false;
}
+
+ 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.
+ int numberOfInputs,
+ stringify(TypeVariableType variable,
+ bool hasValue)) {
+ int currentVariable = 0;
+ bool isFirst = true;
+ StringBuffer buffer = new StringBuffer();
+ collection.forEach((TypeVariableType variable) {
+ if (!isFirst) buffer.add(", ");
+ bool hasValue = currentVariable < numberOfInputs;
+ buffer.add(stringify(variable, hasValue));
+ isFirst = false;
+ currentVariable++;
+ });
+ return buffer.toString();
+ }
+
+ /**
+ * Generate a string representation template for this element, using '#' to
+ * denote the place for the type argument input. If there are more type
+ * variables than [numberOfInputs], 'Dynamic' is used as the value for these
+ * arguments.
+ */
+ static String generateRuntimeTypeString(ClassElement element,
+ int numberOfInputs) {
+ String elementName = element.name.slowToString();
+ if (element.typeVariables.isEmpty()) return "'$elementName'";
+ 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
+ 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?
+ }
+ String arguments = forEachTypeVariable(element.typeVariables,
+ numberOfInputs,
+ stringify);
+ return "'$elementName<$arguments>'";
+ }
+
+ /**
+ * Generate a string template for the runtime type fields that contain the
+ * type descriptions of the reified type arguments, using '#' to denote the
+ * place for the type argument value, or [:null:] if there are more than
+ * [numberOfInputs] type variables.
+ */
+ static String generateTypeVariableString(ClassElement element,
+ int numberOfInputs) {
+ StringBuffer buffer = new StringBuffer();
ngeoffray 2012/09/17 15:31:14 This is unused.
karlklose 2012/09/19 06:40:45 Done, removed.
+ String result = forEachTypeVariable(element.typeVariables, numberOfInputs,
+ (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.
+ String value = hasValue ? "#" : "null";
+ return "'${variable.name.slowToString()}': $value";
+ });
+ return result;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698