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 library dart2js.js_emitter.full_emitter.class_emitter; | 5 library dart2js.js_emitter.full_emitter.class_emitter; |
6 | 6 |
7 import '../../common.dart'; | 7 import '../../common.dart'; |
8 import '../../common/names.dart' show Names; | 8 import '../../common/names.dart' show Names; |
9 import '../../common_elements.dart'; | 9 import '../../common_elements.dart'; |
10 import '../../elements/resolution_types.dart' show ResolutionDartType; | 10 import '../../elements/resolution_types.dart' show ResolutionDartType; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // Fields can only be reflected if their declaring class is reflectable | 190 // Fields can only be reflected if their declaring class is reflectable |
191 // (as they are only accessible via [ClassMirror.declarations]). | 191 // (as they are only accessible via [ClassMirror.declarations]). |
192 // However, set/get operations can be performed on them, so they are | 192 // However, set/get operations can be performed on them, so they are |
193 // reflectable in some sense, which leads to [isAccessibleByReflection] | 193 // reflectable in some sense, which leads to [isAccessibleByReflection] |
194 // reporting `true`. | 194 // reporting `true`. |
195 if (backend.mirrorsData.isMemberAccessibleByReflection(fieldElement)) { | 195 if (backend.mirrorsData.isMemberAccessibleByReflection(fieldElement)) { |
196 fieldNameParts.add(new jsAst.LiteralString('-')); | 196 fieldNameParts.add(new jsAst.LiteralString('-')); |
197 if (fieldElement.isTopLevel || | 197 if (fieldElement.isTopLevel || |
198 backend.mirrorsData | 198 backend.mirrorsData |
199 .isClassAccessibleByReflection(fieldElement.enclosingClass)) { | 199 .isClassAccessibleByReflection(fieldElement.enclosingClass)) { |
200 // TODO(johnniwinther): Support field entities. | 200 // TODO(redemption): Support field entities. |
201 FieldElement element = fieldElement; | 201 FieldElement element = fieldElement; |
202 ResolutionDartType type = element.type; | 202 ResolutionDartType type = element.type; |
203 fieldNameParts.add(task.metadataCollector.reifyType(type)); | 203 fieldNameParts.add(task.metadataCollector.reifyType(type)); |
204 } | 204 } |
205 } | 205 } |
206 jsAst.Literal fieldNameAst = js.concatenateStrings(fieldNameParts); | 206 jsAst.Literal fieldNameAst = js.concatenateStrings(fieldNameParts); |
207 builder.addField(fieldNameAst); | 207 builder.addField(fieldNameAst); |
208 // Add 1 because adding a field to the class also requires a comma | 208 // Add 1 because adding a field to the class also requires a comma |
209 compiler.dumpInfoTask.registerElementAst(fieldElement, fieldNameAst); | 209 compiler.dumpInfoTask.registerElementAst(fieldElement, fieldNameAst); |
210 fieldsAdded = true; | 210 fieldsAdded = true; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 ClassEntity classEntity = cls.element; | 313 ClassEntity classEntity = cls.element; |
314 jsAst.Name className = cls.name; | 314 jsAst.Name className = cls.name; |
315 | 315 |
316 var metadata = | 316 var metadata = |
317 task.metadataCollector.buildClassMetadataFunction(classEntity); | 317 task.metadataCollector.buildClassMetadataFunction(classEntity); |
318 if (metadata != null) { | 318 if (metadata != null) { |
319 classBuilder.addPropertyByName("@", metadata); | 319 classBuilder.addPropertyByName("@", metadata); |
320 } | 320 } |
321 | 321 |
322 if (backend.mirrorsData.isClassAccessibleByReflection(classEntity)) { | 322 if (backend.mirrorsData.isClassAccessibleByReflection(classEntity)) { |
323 // TODO(johnniwinther): Handle class entities. | 323 // TODO(redemption): Handle class entities. |
324 ClassElement classElement = classEntity; | 324 ClassElement classElement = classEntity; |
325 List<ResolutionDartType> typeVars = classElement.typeVariables; | 325 List<ResolutionDartType> typeVars = classElement.typeVariables; |
326 Iterable typeVariableProperties = | 326 Iterable typeVariableProperties = |
327 emitter.typeVariableCodegenAnalysis.typeVariablesOf(classElement); | 327 emitter.typeVariableCodegenAnalysis.typeVariablesOf(classElement); |
328 | 328 |
329 ClassElement superclass = classElement.superclass; | 329 ClassElement superclass = classElement.superclass; |
330 bool hasSuper = superclass != null; | 330 bool hasSuper = superclass != null; |
331 if ((!typeVariableProperties.isEmpty && !hasSuper) || | 331 if ((!typeVariableProperties.isEmpty && !hasSuper) || |
332 (hasSuper && !equalElements(superclass.typeVariables, typeVars))) { | 332 (hasSuper && !equalElements(superclass.typeVariables, typeVars))) { |
333 classBuilder.addPropertyByName( | 333 classBuilder.addPropertyByName( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 enclosingBuilder.addProperty(className, propertyValue); | 367 enclosingBuilder.addProperty(className, propertyValue); |
368 | 368 |
369 String reflectionName = | 369 String reflectionName = |
370 emitter.getReflectionClassName(classEntity, className); | 370 emitter.getReflectionClassName(classEntity, className); |
371 if (reflectionName != null) { | 371 if (reflectionName != null) { |
372 if (!backend.mirrorsData.isClassAccessibleByReflection(classEntity) || | 372 if (!backend.mirrorsData.isClassAccessibleByReflection(classEntity) || |
373 cls.onlyForRti) { | 373 cls.onlyForRti) { |
374 // TODO(herhut): Fix use of reflection name here. | 374 // TODO(herhut): Fix use of reflection name here. |
375 enclosingBuilder.addPropertyByName("+$reflectionName", js.number(0)); | 375 enclosingBuilder.addPropertyByName("+$reflectionName", js.number(0)); |
376 } else { | 376 } else { |
377 // TODO(johnniwinther): Handle class entities. | 377 // TODO(redemption): Handle class entities. |
378 ClassElement classElement = classEntity; | 378 ClassElement classElement = classEntity; |
379 List<jsAst.Expression> types = <jsAst.Expression>[]; | 379 List<jsAst.Expression> types = <jsAst.Expression>[]; |
380 if (classElement.supertype != null) { | 380 if (classElement.supertype != null) { |
381 types.add(task.metadataCollector.reifyType(classElement.supertype)); | 381 types.add(task.metadataCollector.reifyType(classElement.supertype)); |
382 } | 382 } |
383 for (ResolutionDartType interface in classElement.interfaces) { | 383 for (ResolutionDartType interface in classElement.interfaces) { |
384 types.add(task.metadataCollector.reifyType(interface)); | 384 types.add(task.metadataCollector.reifyType(interface)); |
385 } | 385 } |
386 // TODO(herhut): Fix use of reflection name here. | 386 // TODO(herhut): Fix use of reflection name here. |
387 enclosingBuilder.addPropertyByName( | 387 enclosingBuilder.addPropertyByName( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 String reflectionName = emitter.getReflectionSelectorName(selector, name); | 454 String reflectionName = emitter.getReflectionSelectorName(selector, name); |
455 if (reflectionName != null) { | 455 if (reflectionName != null) { |
456 var reflectable = js( | 456 var reflectable = js( |
457 backend.mirrorsData.isMemberAccessibleByReflection(member) | 457 backend.mirrorsData.isMemberAccessibleByReflection(member) |
458 ? '1' | 458 ? '1' |
459 : '0'); | 459 : '0'); |
460 builder.addPropertyByName('+$reflectionName', reflectable); | 460 builder.addPropertyByName('+$reflectionName', reflectable); |
461 } | 461 } |
462 } | 462 } |
463 } | 463 } |
OLD | NEW |