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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/metadata_emitter.dart

Issue 27689002: Reapply "Add TypeVariable object on runtime to support reflection on type variables." and … (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix: include classes with members needed for reflection. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class MetadataEmitter extends CodeEmitterHelper { 7 class MetadataEmitter extends CodeEmitterHelper {
8 /// A list of JS expressions that represent metadata, parameter names and 8 /// A list of JS expressions that represent metadata, parameter names and
9 /// type, and return types. 9 /// type, and return types.
10 final List<String> globalMetadata = []; 10 final List<String> globalMetadata = [];
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if (value == null) { 63 if (value == null) {
64 compiler.reportInternalError( 64 compiler.reportInternalError(
65 annotation, 'Internal error: value is null'); 65 annotation, 'Internal error: value is null');
66 return -1; 66 return -1;
67 } 67 }
68 return addGlobalMetadata( 68 return addGlobalMetadata(
69 jsAst.prettyPrint(task.constantReference(value), compiler).getText()); 69 jsAst.prettyPrint(task.constantReference(value), compiler).getText());
70 } 70 }
71 71
72 int reifyType(DartType type) { 72 int reifyType(DartType type) {
73 // TODO(ahe): Handle type variables correctly instead of using "#". 73 jsAst.Expression representation =
74 String representation = backend.rti.getTypeRepresentation(type, (_) {}); 74 backend.rti.getTypeRepresentation(type, (variable) {
75 return addGlobalMetadata(representation.replaceAll('#', 'null')); 75 return js.toExpression(
76 task.typeVariableHandler.reifyTypeVariable(variable.element));
77 });
78
79 return addGlobalMetadata(
80 jsAst.prettyPrint(representation, compiler).getText());
76 } 81 }
77 82
78 int reifyName(SourceString name) { 83 int reifyName(SourceString name) {
79 return addGlobalMetadata('"${name.slowToString()}"'); 84 return addGlobalMetadata('"${name.slowToString()}"');
80 } 85 }
81 86
82 int addGlobalMetadata(String string) { 87 int addGlobalMetadata(String string) {
83 return globalMetadataMap.putIfAbsent(string, () { 88 return globalMetadataMap.putIfAbsent(string, () {
84 globalMetadata.add(string); 89 globalMetadata.add(string);
85 return globalMetadata.length - 1; 90 return globalMetadata.length - 1;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (link != null) { 138 if (link != null) {
134 for (; !link.isEmpty; link = link.tail) { 139 for (; !link.isEmpty; link = link.tail) {
135 metadata.add(reifyMetadata(link.head)); 140 metadata.add(reifyMetadata(link.head));
136 } 141 }
137 } 142 }
138 code.body.statements.add(js.string(metadata.join(',')).toStatement()); 143 code.body.statements.add(js.string(metadata.join(',')).toStatement());
139 return code; 144 return code;
140 }); 145 });
141 } 146 }
142 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698