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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.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: Addressed comments. 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 ClassEmitter extends CodeEmitterHelper { 7 class ClassEmitter extends CodeEmitterHelper {
8
ahe 2013/10/15 14:56:31 Extra line.
zarah 2013/10/16 07:00:47 Done.
8 /** 9 /**
9 * Documentation wanted -- johnniwinther 10 * Documentation wanted -- johnniwinther
10 * 11 *
11 * Invariant: [classElement] must be a declaration element. 12 * Invariant: [classElement] must be a declaration element.
12 */ 13 */
13 void generateClass(ClassElement classElement, CodeBuffer buffer) { 14 void generateClass(ClassElement classElement, CodeBuffer buffer) {
14 final onlyForRti = 15 final onlyForRti =
15 task.typeTestEmitter.rtiNeededClasses.contains(classElement); 16 task.typeTestEmitter.rtiNeededClasses.contains(classElement);
16 17
17 assert(invariant(classElement, classElement.isDeclaration)); 18 assert(invariant(classElement, classElement.isDeclaration));
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 ClassBuilder builder, 285 ClassBuilder builder,
285 CodeBuffer buffer) { 286 CodeBuffer buffer) {
286 var metadata = task.buildMetadataFunction(classElement); 287 var metadata = task.buildMetadataFunction(classElement);
287 if (metadata != null) { 288 if (metadata != null) {
288 builder.addProperty("@", metadata); 289 builder.addProperty("@", metadata);
289 } 290 }
290 291
291 if (backend.isNeededForReflection(classElement)) { 292 if (backend.isNeededForReflection(classElement)) {
292 Link typeVars = classElement.typeVariables; 293 Link typeVars = classElement.typeVariables;
293 List properties = []; 294 List properties = [];
294 for (TypeVariableType typeVar in typeVars) { 295 if (task.typeVariableHandler.typeVariablesOf(classElement) != null) {
295 properties.add(js.string(typeVar.name.slowToString())); 296 properties = task.typeVariableHandler.typeVariablesOf(classElement)
296 properties.add(js.toExpression(task.reifyType(typeVar.element.bound))); 297 .map((s) => js.toExpression(s));
ahe 2013/10/15 14:56:31 "(s) => js.toExpression(s)" is equivalent to "js.t
zarah 2013/10/16 07:00:47 Done.
297 } 298 }
298 299
299 ClassElement superclass = classElement.superclass; 300 ClassElement superclass = classElement.superclass;
300 bool hasSuper = superclass != null; 301 bool hasSuper = superclass != null;
301 if ((!properties.isEmpty && !hasSuper) || 302 if ((!properties.isEmpty && !hasSuper) ||
302 (hasSuper && superclass.typeVariables != typeVars)) { 303 (hasSuper && superclass.typeVariables != typeVars)) {
303 builder.addProperty('<>', new jsAst.ArrayInitializer.from(properties)); 304 builder.addProperty('<>', new jsAst.ArrayInitializer.from(properties));
304 } 305 }
305 } 306 }
306 List<CodeBuffer> classBuffers = task.elementBuffers[classElement]; 307 List<CodeBuffer> classBuffers = task.elementBuffers[classElement];
(...skipping 26 matching lines...) Expand all
333 } 334 }
334 335
335 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. 336 // TODO(ahe): This method (generateClass) should return a jsAst.Expression.
336 if (!buffer.isEmpty) { 337 if (!buffer.isEmpty) {
337 buffer.write(',$n$n'); 338 buffer.write(',$n$n');
338 } 339 }
339 buffer.write('$className:$_'); 340 buffer.write('$className:$_');
340 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); 341 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler));
341 String reflectionName = task.getReflectionName(classElement, className); 342 String reflectionName = task.getReflectionName(classElement, className);
342 if (reflectionName != null) { 343 if (reflectionName != null) {
343 List<int> interfaces = <int>[]; 344 if (!backend.isNeededForReflection(classElement)) {
344 for (DartType interface in classElement.interfaces) { 345 buffer.write(',$n$n"+$reflectionName": 0');
345 interfaces.add(task.reifyType(interface)); 346 } else {
347 List<int> interfaces = <int>[];
348 for (DartType interface in classElement.interfaces) {
349 interfaces.add(task.reifyType(interface));
350 }
351 buffer.write(',$n$n"+$reflectionName": $interfaces');
346 } 352 }
347 buffer.write(',$n$n"+$reflectionName": $interfaces');
348 } 353 }
349 } 354 }
350 355
351 /** 356 /**
352 * Calls [addField] for each of the fields of [element]. 357 * Calls [addField] for each of the fields of [element].
353 * 358 *
354 * [element] must be a [ClassElement] or a [LibraryElement]. 359 * [element] must be a [ClassElement] or a [LibraryElement].
355 * 360 *
356 * If [element] is a [ClassElement], the static fields of the class are 361 * If [element] is a [ClassElement], the static fields of the class are
357 * visited if [visitStatics] is true and the instance fields are visited if 362 * visited if [visitStatics] is true and the instance fields are visited if
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 ? new Selector.getter(member.name, member.getLibrary()) 589 ? new Selector.getter(member.name, member.getLibrary())
585 : new Selector.setter(member.name, member.getLibrary()); 590 : new Selector.setter(member.name, member.getLibrary());
586 String reflectionName = task.getReflectionName(selector, name); 591 String reflectionName = task.getReflectionName(selector, name);
587 if (reflectionName != null) { 592 if (reflectionName != null) {
588 var reflectable = 593 var reflectable =
589 js(backend.isAccessibleByReflection(member) ? '1' : '0'); 594 js(backend.isAccessibleByReflection(member) ? '1' : '0');
590 builder.addProperty('+$reflectionName', reflectable); 595 builder.addProperty('+$reflectionName', reflectable);
591 } 596 }
592 } 597 }
593 } 598 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698