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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart

Issue 11448009: Represent runtime type information as nested lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor edits. Created 8 years 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: sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
index a4545e6e26259dd8e7aed34f008848a22bb26a45..781a4bf49a58375362e915f96e3421e3f36f6635 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
@@ -9,38 +9,72 @@ class RuntimeTypeInformation {
RuntimeTypeInformation(this.compiler);
- // TODO(karlklose): remove when using type representations.
- String getStringRepresentation(DartType type, {bool expandRawType: false}) {
+ bool isJsNative(Element element) {
+ return (element == compiler.intClass ||
+ element == compiler.boolClass ||
+ element == compiler.numClass ||
+ element == compiler.doubleClass ||
+ element == compiler.stringClass ||
+ element == compiler.listClass ||
+ element == compiler.objectClass ||
+ element == compiler.dynamicClass);
+ }
+
+ /// Return the unique name for the element as an unqoted string.
+ String getNameAsString(Element element) {
+ JavaScriptBackend backend = compiler.backend;
+ Namer namer = backend.namer;
+ return namer.getName(element);
+ }
+
+ /// Return the unique JS name for the element, which is a quoted string for
+ /// native classes and the isolate acccess to the constructor for classes.
+ String getJsName(Element element) {
kasperl 2012/12/06 09:51:04 I wonder if this should return a JS AST node inste
karlklose 2012/12/06 13:30:03 The problem is that getRawTypeRepresentation uses
+ JavaScriptBackend backend = compiler.backend;
+ Namer namer = backend.namer;
+ return isJsNative(element) ? "'${element.name.slowToString()}'"
+ : namer.isolateAccess(element);
+ }
+
+ String getRawTypeRepresentation(DartType type) {
+ String name = getNameAsString(type.element);
+ if (!type.element.isClass()) return name;
+ InterfaceType interface = type;
+ if (interface.element.typeVariables.isEmpty) return name;
kasperl 2012/12/06 09:51:04 Maybe cache interface.element.typeVariables in a l
karlklose 2012/12/06 13:30:03 Done.
+ List<String> arguments = [];
+ interface.element.typeVariables.forEach((_) => arguments.add('dynamic'));
kasperl 2012/12/06 09:51:04 If we had an repeated add, it would be clearer to
karlklose 2012/12/06 13:30:03 I agree. Currently, however, getting the length of
+ return '$name<${Strings.join(arguments, ', ')}>';
+ }
+
+ String getTypeRepresentation(DartType type, void onVariable(variable)) {
StringBuffer builder = new StringBuffer();
void build(DartType t) {
kasperl 2012/12/06 09:51:04 I'd prefer a longer name than t -- but I guess typ
karlklose 2012/12/06 13:30:03 I renamed it to part.
if (t is TypeVariableType) {
- builder.add(t.name.slowToString());
- return;
- }
- JavaScriptBackend backend = compiler.backend;
- builder.add(backend.namer.getName(t.element));
- if (t is InterfaceType) {
+ builder.add('#');
+ onVariable(t);
+ } else {
+ bool hasArguments = t is InterfaceType && !t.isRaw;
+ Element element = t.element;
+ if (hasArguments) {
+ builder.add('[');
+ }
+ if (element.isClass()) {
+ // TODO(karlklose): remove this and record classes that we need only
+ // for runtime types and emit structures for them.
+ ClassElement cls = element;
+ cls.ensureResolved(compiler);
+ compiler.codegenWorld.instantiatedClasses.add(cls);
+ }
+ builder.add(getJsName(element));
+ if (!hasArguments) return;
InterfaceType interface = t;
- ClassElement element = t.element;
- if (element.typeVariables.isEmpty) return;
- bool isRaw = interface.isRaw;
- if (isRaw && !expandRawType) return;
- builder.add('<');
- Iterable items = interface.typeArguments;
- var stringify = isRaw ? (_) => 'dynamic' : (type) => type.toString();
- bool first = true;
- for (var item in items) {
- if (first) {
- first = false;
- } else {
- builder.add(', ');
- }
- builder.add(stringify(item));
+ for (DartType argument in interface.typeArguments) {
+ builder.add(', ');
+ build(argument);
}
- builder.add('>');
+ builder.add(']');
}
}
-
build(type);
return builder.toString();
}

Powered by Google App Engine
This is Rietveld 408576698