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..d11f405106a8783fa546bc9201248a5afd7b3672 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,73 @@ 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. |
ngeoffray
2012/12/06 23:21:45
unqoted -> unquoted
karlklose
2012/12/07 07:46:35
Done.
|
+ String getNameAsString(Element element) { |
+ JavaScriptBackend backend = compiler.backend; |
+ Namer namer = backend.namer; |
ngeoffray
2012/12/06 23:21:45
Why this local variable 'namer'?
karlklose
2012/12/07 07:46:35
Done, removed.
|
+ 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) { |
+ 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; |
+ Link<TypeVariableType> variables = interface.element.typeVariables; |
+ if (variables.isEmpty) return name; |
+ List<String> arguments = []; |
+ variables.forEach((_) => arguments.add('dynamic')); |
+ return '$name<${Strings.join(arguments, ', ')}>'; |
+ } |
+ |
+ String getTypeRepresentation(DartType type, void onVariable(variable)) { |
StringBuffer builder = new StringBuffer(); |
- void build(DartType t) { |
- 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) { |
- 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)); |
+ void build(DartType part) { |
+ if (part is TypeVariableType) { |
+ builder.add('#'); |
+ onVariable(part); |
+ } else { |
+ bool hasArguments = part is InterfaceType && !part.isRaw; |
+ Element element = part.element; |
+ if (hasArguments) { |
+ builder.add('['); |
} |
- 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; |
ngeoffray
2012/12/06 23:21:45
Since the method is called getSomething, I would p
karlklose
2012/12/07 07:46:35
I changed it to use a string representation (like
|
+ cls.ensureResolved(compiler); |
+ compiler.codegenWorld.instantiatedClasses.add(cls); |
+ } |
+ builder.add(getJsName(element)); |
+ if (!hasArguments) return; |
+ InterfaceType interface = part; |
+ for (DartType argument in interface.typeArguments) { |
+ builder.add(', '); |
+ build(argument); |
+ } |
+ builder.add(']'); |
} |
} |
- |
build(type); |
return builder.toString(); |
} |