| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.program_builder; | 5 part of dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * [member] is a field (instance, static, or top level). | 8 * [member] is a field (instance, static, or top level). |
| 9 * | 9 * |
| 10 * [name] is the field name that the [Namer] has picked for this field's | 10 * [name] is the field name that the [Namer] has picked for this field's |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 * [visitStatics] is false. | 46 * [visitStatics] is false. |
| 47 * | 47 * |
| 48 * If [element] is a [LibraryElement], [visitStatics] must be true. | 48 * If [element] is a [LibraryElement], [visitStatics] must be true. |
| 49 * | 49 * |
| 50 * When visiting the instance fields of a class, the fields of its superclass | 50 * When visiting the instance fields of a class, the fields of its superclass |
| 51 * are also visited if the class is instantiated. | 51 * are also visited if the class is instantiated. |
| 52 * | 52 * |
| 53 * Invariant: [element] must be a declaration element. | 53 * Invariant: [element] must be a declaration element. |
| 54 */ | 54 */ |
| 55 void visitFields(Element element, bool visitStatics, AcceptField f) { | 55 void visitFields(Element element, bool visitStatics, AcceptField f) { |
| 56 assert(invariant(element, element.isDeclaration)); | 56 assert(element.isDeclaration, failedAt(element)); |
| 57 | 57 |
| 58 ClassElement cls; | 58 ClassElement cls; |
| 59 bool isNativeClass = false; | 59 bool isNativeClass = false; |
| 60 bool isLibrary = false; | 60 bool isLibrary = false; |
| 61 bool isInstantiated = false; | 61 bool isInstantiated = false; |
| 62 if (element.isClass) { | 62 if (element.isClass) { |
| 63 cls = element; | 63 cls = element; |
| 64 isNativeClass = _nativeData.isNativeClass(cls); | 64 isNativeClass = _nativeData.isNativeClass(cls); |
| 65 | 65 |
| 66 // If the class is never instantiated we still need to set it up for | 66 // If the class is never instantiated we still need to set it up for |
| 67 // inheritance purposes, but we can simplify its JavaScript constructor. | 67 // inheritance purposes, but we can simplify its JavaScript constructor. |
| 68 isInstantiated = | 68 isInstantiated = |
| 69 _codegenWorldBuilder.directlyInstantiatedClasses.contains(cls); | 69 _codegenWorldBuilder.directlyInstantiatedClasses.contains(cls); |
| 70 } else if (element.isLibrary) { | 70 } else if (element.isLibrary) { |
| 71 isLibrary = true; | 71 isLibrary = true; |
| 72 assert(invariant(element, visitStatics)); | 72 assert(visitStatics, failedAt(element)); |
| 73 } else { | 73 } else { |
| 74 throw new SpannableAssertionFailure( | 74 throw new SpannableAssertionFailure( |
| 75 element, 'Expected a ClassElement or a LibraryElement.'); | 75 element, 'Expected a ClassElement or a LibraryElement.'); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void visitField(Element holder, FieldElement field) { | 78 void visitField(Element holder, FieldElement field) { |
| 79 assert(invariant(element, field.isDeclaration)); | 79 assert(field.isDeclaration, failedAt(element)); |
| 80 | 80 |
| 81 bool isMixinNativeField = isNativeClass && holder.isMixinApplication; | 81 bool isMixinNativeField = isNativeClass && holder.isMixinApplication; |
| 82 | 82 |
| 83 // See if we can dynamically create getters and setters. | 83 // See if we can dynamically create getters and setters. |
| 84 // We can only generate getters and setters for [element] since | 84 // We can only generate getters and setters for [element] since |
| 85 // the fields of super classes could be overwritten with getters or | 85 // the fields of super classes could be overwritten with getters or |
| 86 // setters. | 86 // setters. |
| 87 bool needsGetter = false; | 87 bool needsGetter = false; |
| 88 bool needsSetter = false; | 88 bool needsSetter = false; |
| 89 if (isLibrary || isMixinNativeField || holder == element) { | 89 if (isLibrary || isMixinNativeField || holder == element) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 field is ClosureFieldElement; | 157 field is ClosureFieldElement; |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool canAvoidGeneratedCheckedSetter(VariableElement member) { | 160 bool canAvoidGeneratedCheckedSetter(VariableElement member) { |
| 161 // We never generate accessors for top-level/static fields. | 161 // We never generate accessors for top-level/static fields. |
| 162 if (!member.isInstanceMember) return true; | 162 if (!member.isInstanceMember) return true; |
| 163 ResolutionDartType type = member.type; | 163 ResolutionDartType type = member.type; |
| 164 return type.treatAsDynamic || type.isObject; | 164 return type.treatAsDynamic || type.isObject; |
| 165 } | 165 } |
| 166 } | 166 } |
| OLD | NEW |