| OLD | NEW |
| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 ClassBuilder builder, | 284 ClassBuilder builder, |
| 285 CodeBuffer buffer) { | 285 CodeBuffer buffer) { |
| 286 var metadata = task.buildMetadataFunction(classElement); | 286 var metadata = task.buildMetadataFunction(classElement); |
| 287 if (metadata != null) { | 287 if (metadata != null) { |
| 288 builder.addProperty("@", metadata); | 288 builder.addProperty("@", metadata); |
| 289 } | 289 } |
| 290 | 290 |
| 291 if (backend.isNeededForReflection(classElement)) { | 291 if (backend.isNeededForReflection(classElement)) { |
| 292 Link typeVars = classElement.typeVariables; | 292 Link typeVars = classElement.typeVariables; |
| 293 List properties = []; | 293 List properties = []; |
| 294 for (TypeVariableType typeVar in typeVars) { | 294 if (task.typeVariableHandler.typeVariablesOf(classElement) != null) { |
| 295 properties.add(js.string(typeVar.name.slowToString())); | 295 properties = task.typeVariableHandler.typeVariablesOf(classElement) |
| 296 properties.add(js.toExpression(task.reifyType(typeVar.element.bound))); | 296 .map(js.toExpression); |
| 297 } | 297 } |
| 298 | 298 |
| 299 ClassElement superclass = classElement.superclass; | 299 ClassElement superclass = classElement.superclass; |
| 300 bool hasSuper = superclass != null; | 300 bool hasSuper = superclass != null; |
| 301 if ((!properties.isEmpty && !hasSuper) || | 301 if ((!properties.isEmpty && !hasSuper) || |
| 302 (hasSuper && superclass.typeVariables != typeVars)) { | 302 (hasSuper && superclass.typeVariables != typeVars)) { |
| 303 builder.addProperty('<>', new jsAst.ArrayInitializer.from(properties)); | 303 builder.addProperty('<>', new jsAst.ArrayInitializer.from(properties)); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 List<CodeBuffer> classBuffers = task.elementBuffers[classElement]; | 306 List<CodeBuffer> classBuffers = task.elementBuffers[classElement]; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 333 } | 333 } |
| 334 | 334 |
| 335 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. | 335 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. |
| 336 if (!buffer.isEmpty) { | 336 if (!buffer.isEmpty) { |
| 337 buffer.write(',$n$n'); | 337 buffer.write(',$n$n'); |
| 338 } | 338 } |
| 339 buffer.write('$className:$_'); | 339 buffer.write('$className:$_'); |
| 340 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); | 340 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); |
| 341 String reflectionName = task.getReflectionName(classElement, className); | 341 String reflectionName = task.getReflectionName(classElement, className); |
| 342 if (reflectionName != null) { | 342 if (reflectionName != null) { |
| 343 List<int> interfaces = <int>[]; | 343 if (!backend.isNeededForReflection(classElement)) { |
| 344 for (DartType interface in classElement.interfaces) { | 344 buffer.write(',$n$n"+$reflectionName": 0'); |
| 345 interfaces.add(task.reifyType(interface)); | 345 } else { |
| 346 List<int> interfaces = <int>[]; |
| 347 for (DartType interface in classElement.interfaces) { |
| 348 interfaces.add(task.reifyType(interface)); |
| 349 } |
| 350 buffer.write(',$n$n"+$reflectionName": $interfaces'); |
| 346 } | 351 } |
| 347 buffer.write(',$n$n"+$reflectionName": $interfaces'); | |
| 348 } | 352 } |
| 349 } | 353 } |
| 350 | 354 |
| 351 /** | 355 /** |
| 352 * Calls [addField] for each of the fields of [element]. | 356 * Calls [addField] for each of the fields of [element]. |
| 353 * | 357 * |
| 354 * [element] must be a [ClassElement] or a [LibraryElement]. | 358 * [element] must be a [ClassElement] or a [LibraryElement]. |
| 355 * | 359 * |
| 356 * If [element] is a [ClassElement], the static fields of the class are | 360 * 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 | 361 * visited if [visitStatics] is true and the instance fields are visited if |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 ? new Selector.getter(member.name, member.getLibrary()) | 588 ? new Selector.getter(member.name, member.getLibrary()) |
| 585 : new Selector.setter(member.name, member.getLibrary()); | 589 : new Selector.setter(member.name, member.getLibrary()); |
| 586 String reflectionName = task.getReflectionName(selector, name); | 590 String reflectionName = task.getReflectionName(selector, name); |
| 587 if (reflectionName != null) { | 591 if (reflectionName != null) { |
| 588 var reflectable = | 592 var reflectable = |
| 589 js(backend.isAccessibleByReflection(member) ? '1' : '0'); | 593 js(backend.isAccessibleByReflection(member) ? '1' : '0'); |
| 590 builder.addProperty('+$reflectionName', reflectable); | 594 builder.addProperty('+$reflectionName', reflectable); |
| 591 } | 595 } |
| 592 } | 596 } |
| 593 } | 597 } |
| OLD | NEW |