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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/program_builder/field_visitor.dart

Issue 3001823002: Revert "Various redemptions" (Closed)
Patch Set: Created 3 years, 4 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
OLDNEW
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 10 matching lines...) Expand all
21 * [needsCheckedSetter] indicates that a checked getter is needed, and in this 21 * [needsCheckedSetter] indicates that a checked getter is needed, and in this
22 * case, [needsSetter] is always false. [needsCheckedSetter] is only true when 22 * case, [needsSetter] is always false. [needsCheckedSetter] is only true when
23 * type assertions are enabled (checked mode). 23 * type assertions are enabled (checked mode).
24 */ 24 */
25 typedef void AcceptField(FieldEntity member, js.Name name, js.Name accessorName, 25 typedef void AcceptField(FieldEntity member, js.Name name, js.Name accessorName,
26 bool needsGetter, bool needsSetter, bool needsCheckedSetter); 26 bool needsGetter, bool needsSetter, bool needsCheckedSetter);
27 27
28 class FieldVisitor { 28 class FieldVisitor {
29 final CompilerOptions _options; 29 final CompilerOptions _options;
30 final ElementEnvironment _elementEnvironment; 30 final ElementEnvironment _elementEnvironment;
31 final CommonElements _commonElements;
32 final CodegenWorldBuilder _codegenWorldBuilder; 31 final CodegenWorldBuilder _codegenWorldBuilder;
33 final NativeData _nativeData; 32 final NativeData _nativeData;
34 final MirrorsData _mirrorsData; 33 final MirrorsData _mirrorsData;
35 final Namer _namer; 34 final Namer _namer;
36 final ClosedWorld _closedWorld; 35 final ClosedWorld _closedWorld;
37 36
38 FieldVisitor( 37 FieldVisitor(
39 this._options, 38 this._options,
40 this._elementEnvironment, 39 this._elementEnvironment,
41 this._commonElements,
42 this._codegenWorldBuilder, 40 this._codegenWorldBuilder,
43 this._nativeData, 41 this._nativeData,
44 this._mirrorsData, 42 this._mirrorsData,
45 this._namer, 43 this._namer,
46 this._closedWorld); 44 this._closedWorld);
47 45
48 /** 46 /**
49 * Invokes [f] for each of the fields of [element]. 47 * Invokes [f] for each of the fields of [element].
50 * 48 *
51 * [element] must be a [ClassEntity] or a [LibraryEntity]. 49 * [element] must be a [ClassElement] or a [LibraryElement].
52 * 50 *
53 * If [element] is a [ClassEntity], the static fields of the class are 51 * If [element] is a [ClassElement], the static fields of the class are
54 * visited if [visitStatics] is true and the instance fields are visited if 52 * visited if [visitStatics] is true and the instance fields are visited if
55 * [visitStatics] is false. 53 * [visitStatics] is false.
56 * 54 *
57 * If [element] is a [LibraryEntity], [visitStatics] must be true. 55 * If [element] is a [LibraryElement], [visitStatics] must be true.
58 * 56 *
59 * When visiting the instance fields of a class, the fields of its superclass 57 * When visiting the instance fields of a class, the fields of its superclass
60 * are also visited if the class is instantiated. 58 * are also visited if the class is instantiated.
61 * 59 *
62 * Invariant: [element] must be a declaration element. 60 * Invariant: [element] must be a declaration element.
63 */ 61 */
64 void visitFields(AcceptField f, 62 void visitFields(AcceptField f,
65 {bool visitStatics: false, LibraryEntity library, ClassEntity cls}) { 63 {bool visitStatics: false, LibraryEntity library, ClassEntity cls}) {
66 assert(!(library is LibraryElement && !library.isDeclaration), 64 assert(!(library is LibraryElement && !library.isDeclaration),
67 failedAt(library)); 65 failedAt(library));
68 assert(!(cls is ClassElement && !cls.isDeclaration), failedAt(cls)); 66 assert(!(cls is ClassElement && !cls.isDeclaration), failedAt(cls));
69 67
70 bool isNativeClass = false; 68 bool isNativeClass = false;
71 bool isLibrary = false; 69 bool isLibrary = false;
72 bool isInstantiated = false; 70 bool isInstantiated = false;
73 if (cls != null) { 71 if (cls != null) {
74 isNativeClass = _nativeData.isNativeClass(cls); 72 isNativeClass = _nativeData.isNativeClass(cls);
75 73
76 // If the class is never instantiated we still need to set it up for 74 // If the class is never instantiated we still need to set it up for
77 // inheritance purposes, but we can simplify its JavaScript constructor. 75 // inheritance purposes, but we can simplify its JavaScript constructor.
78 isInstantiated = 76 isInstantiated =
79 _codegenWorldBuilder.directlyInstantiatedClasses.contains(cls); 77 _codegenWorldBuilder.directlyInstantiatedClasses.contains(cls);
80 } else if (library != null) { 78 } else if (library != null) {
81 isLibrary = true; 79 isLibrary = true;
82 assert(visitStatics, failedAt(library)); 80 assert(visitStatics, failedAt(library));
83 } else { 81 } else {
84 failedAt( 82 failedAt(NO_LOCATION_SPANNABLE,
85 NO_LOCATION_SPANNABLE, 'Expected a ClassEntity or a LibraryEntity.'); 83 'Expected a ClassElement or a LibraryElement.');
86 } 84 }
87 85
88 void visitField(FieldEntity field, {ClassEntity holder}) { 86 void visitField(FieldEntity field, {ClassEntity holder}) {
89 assert(!(field is FieldElement && !field.isDeclaration), failedAt(field)); 87 assert(!(field is FieldElement && !field.isDeclaration), failedAt(field));
90 88
91 bool isMixinNativeField = 89 bool isMixinNativeField =
92 isNativeClass && _elementEnvironment.isMixinApplication(holder); 90 isNativeClass && _elementEnvironment.isMixinApplication(holder);
93 91
94 // See if we can dynamically create getters and setters. 92 // See if we can dynamically create getters and setters.
95 // We can only generate getters and setters for [element] since 93 // We can only generate getters and setters for [element] since
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 168
171 static bool fieldAccessNeverThrows(FieldEntity field) { 169 static bool fieldAccessNeverThrows(FieldEntity field) {
172 return 170 return
173 // We never access a field in a closure (a captured variable) without 171 // We never access a field in a closure (a captured variable) without
174 // knowing that it is there. Therefore we don't need to use a getter 172 // knowing that it is there. Therefore we don't need to use a getter
175 // (that will throw if the getter method is missing), but can always 173 // (that will throw if the getter method is missing), but can always
176 // access the field directly. 174 // access the field directly.
177 field is ClosureFieldElement; 175 field is ClosureFieldElement;
178 } 176 }
179 177
180 bool canAvoidGeneratedCheckedSetter(FieldEntity member) { 178 bool canAvoidGeneratedCheckedSetter(FieldElement member) {
181 // We never generate accessors for top-level/static fields. 179 // We never generate accessors for top-level/static fields.
182 if (!member.isInstanceMember) return true; 180 if (!member.isInstanceMember) return true;
183 DartType type = _elementEnvironment.getFieldType(member); 181 ResolutionDartType type = member.type;
184 return type.treatAsDynamic || type == _commonElements.objectType; 182 return type.treatAsDynamic || type.isObject;
185 } 183 }
186 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698