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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart

Issue 26472002: Add TypeVariable object on runtime to support reflection on type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
index 8d0c6a9bdcd39808fd44a6ceef4e6769a9975993..30c525401903b899cb09ff9f1b05256c3565340b 100644
--- a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
@@ -47,6 +47,7 @@ class CodeEmitterTask extends CompilerTask {
Set<ClassElement> instantiatedClasses;
JavaScriptBackend get backend => compiler.backend;
+ TypeVariableConstantHandler get typeVarHandler => backend.typeVarHandler;
String get _ => space;
String get space => compiler.enableMinification ? "" : " ";
@@ -1714,10 +1715,9 @@ class CodeEmitterTask extends CompilerTask {
if (backend.isNeededForReflection(classElement)) {
Link typeVars = classElement.typeVariables;
List properties = [];
- for (TypeVariableType typeVar in typeVars) {
- properties.add(js.string(typeVar.name.slowToString()));
- properties.add(js.toExpression(reifyType(typeVar.element.bound)));
- }
+ if (typeVarHandler.typeVars[classElement] != null)
karlklose 2013/10/14 10:54:43 Use a {} block even for one statement unless it is
ahe 2013/10/14 13:07:07 Please keep abstractions in place. typeVarHandler
zarah 2013/10/15 14:20:02 Done.
zarah 2013/10/15 14:20:02 Done.
+ properties.addAll(typeVarHandler.typeVars[classElement]
+ .map((s) => js.toExpression(s)));
ahe 2013/10/14 13:07:07 This should probably be: properties = typeVarHand
zarah 2013/10/15 14:20:02 Done.
ClassElement superclass = classElement.superclass;
bool hasSuper = superclass != null;
@@ -1763,11 +1763,15 @@ class CodeEmitterTask extends CompilerTask {
buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler));
String reflectionName = getReflectionName(classElement, className);
if (reflectionName != null) {
- List<int> interfaces = <int>[];
- for (DartType interface in classElement.interfaces) {
- interfaces.add(reifyType(interface));
+ if (!backend.isNeededForReflection(classElement)) {
+ buffer.write(',$n$n"+$reflectionName": 0');
+ } else {
+ List<int> interfaces = <int>[];
+ for (DartType interface in classElement.interfaces) {
+ interfaces.add(reifyType(interface));
+ }
+ buffer.write(',$n$n"+$reflectionName": $interfaces');
}
- buffer.write(',$n$n"+$reflectionName": $interfaces');
}
}
@@ -3050,9 +3054,13 @@ class CodeEmitterTask extends CompilerTask {
}
int reifyType(DartType type) {
- // TODO(ahe): Handle type variables correctly instead of using "#".
- String representation = backend.rti.getTypeRepresentation(type, (_) {});
- return addGlobalMetadata(representation.replaceAll('#', 'null'));
+ jsAst.Expression representation =
+ backend.rti.getTypeRepresentation(type, (variable) {
+ return js.toExpression(typeVarHandler.reifyTypeVar(variable));
+ });
ahe 2013/10/14 13:07:07 Weird indentation.
zarah 2013/10/15 14:20:02 Done.
+
+ return addGlobalMetadata(
+ jsAst.prettyPrint(representation, compiler).getText());
}
int reifyName(SourceString name) {

Powered by Google App Engine
This is Rietveld 408576698