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