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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/class_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 ClassEmitter extends CodeEmitterHelper { 7 class ClassEmitter extends CodeEmitterHelper {
8 /** 8 /**
9 * Documentation wanted -- johnniwinther 9 * Documentation wanted -- johnniwinther
10 * 10 *
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 ClassElement classElement, 290 ClassElement classElement,
291 ClassBuilder builder, 291 ClassBuilder builder,
292 CodeBuffer buffer) { 292 CodeBuffer buffer) {
293 var metadata = task.metadataEmitter.buildMetadataFunction(classElement); 293 var metadata = task.metadataEmitter.buildMetadataFunction(classElement);
294 if (metadata != null) { 294 if (metadata != null) {
295 builder.addProperty("@", metadata); 295 builder.addProperty("@", metadata);
296 } 296 }
297 297
298 if (backend.isNeededForReflection(classElement)) { 298 if (backend.isNeededForReflection(classElement)) {
299 Link typeVars = classElement.typeVariables; 299 Link typeVars = classElement.typeVariables;
300 List properties = []; 300 Iterable properties = [];
301 for (TypeVariableType typeVar in typeVars) { 301 if (task.typeVariableHandler.typeVariablesOf(classElement) != null) {
302 properties.add(js.string(typeVar.name.slowToString())); 302 properties = task.typeVariableHandler.typeVariablesOf(classElement)
303 properties.add( 303 .map(js.toExpression);
304 js.toExpression(
305 task.metadataEmitter.reifyType(typeVar.element.bound)));
306 } 304 }
307 305
308 ClassElement superclass = classElement.superclass; 306 ClassElement superclass = classElement.superclass;
309 bool hasSuper = superclass != null; 307 bool hasSuper = superclass != null;
310 if ((!properties.isEmpty && !hasSuper) || 308 if ((!properties.isEmpty && !hasSuper) ||
311 (hasSuper && superclass.typeVariables != typeVars)) { 309 (hasSuper && superclass.typeVariables != typeVars)) {
312 builder.addProperty('<>', new jsAst.ArrayInitializer.from(properties)); 310 builder.addProperty('<>', new jsAst.ArrayInitializer.from(properties));
313 } 311 }
314 } 312 }
315 List<CodeBuffer> classBuffers = task.elementBuffers[classElement]; 313 List<CodeBuffer> classBuffers = task.elementBuffers[classElement];
(...skipping 26 matching lines...) Expand all
342 } 340 }
343 341
344 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. 342 // TODO(ahe): This method (generateClass) should return a jsAst.Expression.
345 if (!buffer.isEmpty) { 343 if (!buffer.isEmpty) {
346 buffer.write(',$n$n'); 344 buffer.write(',$n$n');
347 } 345 }
348 buffer.write('$className:$_'); 346 buffer.write('$className:$_');
349 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); 347 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler));
350 String reflectionName = task.getReflectionName(classElement, className); 348 String reflectionName = task.getReflectionName(classElement, className);
351 if (reflectionName != null) { 349 if (reflectionName != null) {
352 List<int> interfaces = <int>[]; 350 if (!backend.isNeededForReflection(classElement)) {
353 for (DartType interface in classElement.interfaces) { 351 buffer.write(',$n$n"+$reflectionName": 0');
354 interfaces.add(task.metadataEmitter.reifyType(interface)); 352 } else {
353 List<int> interfaces = <int>[];
354 for (DartType interface in classElement.interfaces) {
355 interfaces.add(task.metadataEmitter.reifyType(interface));
356 }
357 buffer.write(',$n$n"+$reflectionName": $interfaces');
355 } 358 }
356 buffer.write(',$n$n"+$reflectionName": $interfaces');
357 } 359 }
358 } 360 }
359 361
360 /** 362 /**
361 * Calls [addField] for each of the fields of [element]. 363 * Calls [addField] for each of the fields of [element].
362 * 364 *
363 * [element] must be a [ClassElement] or a [LibraryElement]. 365 * [element] must be a [ClassElement] or a [LibraryElement].
364 * 366 *
365 * If [element] is a [ClassElement], the static fields of the class are 367 * If [element] is a [ClassElement], the static fields of the class are
366 * visited if [visitStatics] is true and the instance fields are visited if 368 * visited if [visitStatics] is true and the instance fields are visited if
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 ? new Selector.getter(member.name, member.getLibrary()) 595 ? new Selector.getter(member.name, member.getLibrary())
594 : new Selector.setter(member.name, member.getLibrary()); 596 : new Selector.setter(member.name, member.getLibrary());
595 String reflectionName = task.getReflectionName(selector, name); 597 String reflectionName = task.getReflectionName(selector, name);
596 if (reflectionName != null) { 598 if (reflectionName != null) {
597 var reflectable = 599 var reflectable =
598 js(backend.isAccessibleByReflection(member) ? '1' : '0'); 600 js(backend.isAccessibleByReflection(member) ? '1' : '0');
599 builder.addProperty('+$reflectionName', reflectable); 601 builder.addProperty('+$reflectionName', reflectable);
600 } 602 }
601 } 603 }
602 } 604 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698