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

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

Issue 869543004: dart2js: store fields in the model and make the emitters use it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 5 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.new_js_emitter.model; 5 library dart2js.new_js_emitter.model;
6 6
7 import '../js/js.dart' as js show Expression; 7 import '../js/js.dart' as js show Expression;
8 import '../constants/values.dart' show ConstantValue; 8 import '../constants/values.dart' show ConstantValue;
9 9
10 import '../deferred_load.dart' show OutputUnit; 10 import '../deferred_load.dart' show OutputUnit;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 124
125 class Constant { 125 class Constant {
126 final String name; 126 final String name;
127 final Holder holder; 127 final Holder holder;
128 final ConstantValue value; 128 final ConstantValue value;
129 129
130 Constant(this.name, this.holder, this.value); 130 Constant(this.name, this.holder, this.value);
131 } 131 }
132 132
133 class Library { 133 abstract class FieldContainer {
134 List<Field> get staticFieldsForReflection;
135 }
136
137 class Library implements FieldContainer {
134 /// The element should only be used during the transition to the new model. 138 /// The element should only be used during the transition to the new model.
135 /// Uses indicate missing information in the model. 139 /// Uses indicate missing information in the model.
136 final Element element; 140 final Element element;
137 141
138 final String uri; 142 final String uri;
139 final List<StaticMethod> statics; 143 final List<StaticMethod> statics;
140 final List<Class> classes; 144 final List<Class> classes;
141 145
142 Library(this.element, this.uri, this.statics, this.classes); 146 final List<Field> staticFieldsForReflection;
147
148 Library(this.element, this.uri, this.statics, this.classes,
149 this.staticFieldsForReflection);
143 } 150 }
144 151
145 class StaticField { 152 class StaticField {
146 /// The element should only be used during the transition to the new model. 153 /// The element should only be used during the transition to the new model.
147 /// Uses indicate missing information in the model. 154 /// Uses indicate missing information in the model.
148 final Element element; 155 final Element element;
149 156
150 final String name; 157 final String name;
151 // TODO(floitsch): the holder for static fields is the isolate object. We 158 // TODO(floitsch): the holder for static fields is the isolate object. We
152 // could remove this field and use the isolate object directly. 159 // could remove this field and use the isolate object directly.
153 final Holder holder; 160 final Holder holder;
154 final js.Expression code; 161 final js.Expression code;
155 final bool isFinal; 162 final bool isFinal;
156 final bool isLazy; 163 final bool isLazy;
157 164
158 StaticField(this.element, 165 StaticField(this.element,
159 this.name, this.holder, this.code, 166 this.name, this.holder, this.code,
160 this.isFinal, this.isLazy); 167 this.isFinal, this.isLazy);
161 } 168 }
162 169
163 class Class { 170 class Class implements FieldContainer {
164 /// The element should only be used during the transition to the new model. 171 /// The element should only be used during the transition to the new model.
165 /// Uses indicate missing information in the model. 172 /// Uses indicate missing information in the model.
166 final Element element; 173 final Element element;
167 174
168 final String name; 175 final String name;
169 final Holder holder; 176 final Holder holder;
170 Class _superclass; 177 Class _superclass;
171 final List<Method> methods; 178 final List<Method> methods;
172 final List<InstanceField> fields; 179 final List<Field> fields;
173 final List<StubMethod> isChecks; 180 final List<StubMethod> isChecks;
181 final List<Field> staticFieldsForReflection;
174 final bool onlyForRti; 182 final bool onlyForRti;
175 final bool isDirectlyInstantiated; 183 final bool isDirectlyInstantiated;
176 final bool isNative; 184 final bool isNative;
177 185
178 // If the class implements a function type, and the type is encoded in the 186 // If the class implements a function type, and the type is encoded in the
179 // metatada table, then this field contains the index into that field. 187 // metatada table, then this field contains the index into that field.
180 final int functionTypeIndex; 188 final int functionTypeIndex;
181 189
182 /// Whether the class must be evaluated eagerly. 190 /// Whether the class must be evaluated eagerly.
183 bool isEager = false; 191 bool isEager = false;
184 192
185 Class(this.element, this.name, this.holder, 193 Class(this.element, this.name, this.holder,
186 this.methods, 194 this.methods,
187 this.fields, 195 this.fields,
196 this.staticFieldsForReflection,
188 this.isChecks, 197 this.isChecks,
189 this.functionTypeIndex, 198 this.functionTypeIndex,
190 {this.onlyForRti, 199 {this.onlyForRti,
191 this.isDirectlyInstantiated, 200 this.isDirectlyInstantiated,
192 this.isNative}) { 201 this.isNative}) {
193 assert(onlyForRti != null); 202 assert(onlyForRti != null);
194 assert(isDirectlyInstantiated != null); 203 assert(isDirectlyInstantiated != null);
195 assert(isNative != null); 204 assert(isNative != null);
196 } 205 }
197 206
198 bool get isMixinApplication => false; 207 bool get isMixinApplication => false;
199 Class get superclass => _superclass; 208 Class get superclass => _superclass;
200 209
201 void setSuperclass(Class superclass) { 210 void setSuperclass(Class superclass) {
202 _superclass = superclass; 211 _superclass = superclass;
203 } 212 }
204 213
205 String get superclassName 214 String get superclassName
206 => (superclass == null) ? "" : superclass.name; 215 => (superclass == null) ? "" : superclass.name;
207 int get superclassHolderIndex 216 int get superclassHolderIndex
208 => (superclass == null) ? 0 : superclass.holder.index; 217 => (superclass == null) ? 0 : superclass.holder.index;
209 } 218 }
210 219
211 class MixinApplication extends Class { 220 class MixinApplication extends Class {
212 Class _mixinClass; 221 Class _mixinClass;
213 222
214 MixinApplication(Element element, String name, Holder holder, 223 MixinApplication(Element element, String name, Holder holder,
224 List<Field> instanceFields,
225 List<Field> staticFieldsForReflection,
215 List<StubMethod> isChecks, 226 List<StubMethod> isChecks,
216 int functionTypeIndex, 227 int functionTypeIndex,
217 {bool onlyForRti, 228 {bool onlyForRti,
218 bool isDirectlyInstantiated}) 229 bool isDirectlyInstantiated})
219 : super(element, 230 : super(element,
220 name, holder, 231 name, holder,
221 const <Method>[], const <InstanceField>[], 232 const <Method>[],
233 instanceFields,
234 staticFieldsForReflection,
222 isChecks, functionTypeIndex, 235 isChecks, functionTypeIndex,
223 onlyForRti: onlyForRti, 236 onlyForRti: onlyForRti,
224 isDirectlyInstantiated: isDirectlyInstantiated, 237 isDirectlyInstantiated: isDirectlyInstantiated,
225 isNative: false); 238 isNative: false);
226 239
227 bool get isMixinApplication => true; 240 bool get isMixinApplication => true;
228 Class get mixinClass => _mixinClass; 241 Class get mixinClass => _mixinClass;
229 242
230 void setMixinClass(Class mixinClass) { 243 void setMixinClass(Class mixinClass) {
231 _mixinClass = mixinClass; 244 _mixinClass = mixinClass;
232 } 245 }
233 } 246 }
234 247
235 class InstanceField { 248 /// A field.
249 ///
250 /// In general represents an instance field, but for reflection may also
251 /// represent static fields.
252 class Field {
236 /// The element should only be used during the transition to the new model. 253 /// The element should only be used during the transition to the new model.
237 /// Uses indicate missing information in the model. 254 /// Uses indicate missing information in the model.
238 final Element element; 255 final Element element;
239 256
240 final String name; 257 final String name;
258 final String accessorName;
241 259
242 /// 00: Does not need any getter. 260 /// 00: Does not need any getter.
243 /// 01: function() { return this.field; } 261 /// 01: function() { return this.field; }
244 /// 10: function(receiver) { return receiver.field; } 262 /// 10: function(receiver) { return receiver.field; }
245 /// 11: function(receiver) { return this.field; } 263 /// 11: function(receiver) { return this.field; }
246 final int getterFlags; 264 final int getterFlags;
247 265
248 /// 00: Does not need any setter. 266 /// 00: Does not need any setter.
249 /// 01: function(value) { this.field = value; } 267 /// 01: function(value) { this.field = value; }
250 /// 10: function(receiver, value) { receiver.field = value; } 268 /// 10: function(receiver, value) { receiver.field = value; }
251 /// 11: function(receiver, value) { this.field = value; } 269 /// 11: function(receiver, value) { this.field = value; }
252 final int setterFlags; 270 final int setterFlags;
253 271
272 final bool needsCheckedSetter;
273
254 // TODO(floitsch): support renamed fields. 274 // TODO(floitsch): support renamed fields.
255 InstanceField(this.element, this.name, this.getterFlags, this.setterFlags); 275 Field(this.element, this.name, this.accessorName,
276 this.getterFlags, this.setterFlags,
277 this.needsCheckedSetter);
256 278
257 bool get needsGetter => getterFlags != 0; 279 bool get needsGetter => getterFlags != 0;
258 bool get needsSetter => setterFlags != 0; 280 bool get needsUncheckedSetter => setterFlags != 0;
281
282 bool get needsInterceptedGetter => getterFlags > 1;
283 bool get needsInterceptedSetter => setterFlags > 1;
259 } 284 }
260 285
261 class Method { 286 class Method {
262 /// The element should only be used during the transition to the new model. 287 /// The element should only be used during the transition to the new model.
263 /// Uses indicate missing information in the model. 288 /// Uses indicate missing information in the model.
264 final Element element; 289 final Element element;
265 290
266 final String name; 291 final String name;
267 final js.Expression code; 292 final js.Expression code;
268 final bool needsTearOff; 293 final bool needsTearOff;
(...skipping 13 matching lines...) Expand all
282 StaticMethod(Element element, String name, this.holder, js.Expression code, 307 StaticMethod(Element element, String name, this.holder, js.Expression code,
283 {bool needsTearOff}) 308 {bool needsTearOff})
284 : super(element, name, code, needsTearOff: needsTearOff); 309 : super(element, name, code, needsTearOff: needsTearOff);
285 } 310 }
286 311
287 class StaticStubMethod extends StaticMethod { 312 class StaticStubMethod extends StaticMethod {
288 StaticStubMethod(String name, Holder holder, js.Expression code, 313 StaticStubMethod(String name, Holder holder, js.Expression code,
289 {bool needsTearOff}) 314 {bool needsTearOff})
290 : super(null, name, holder, code, needsTearOff: needsTearOff); 315 : super(null, name, holder, code, needsTearOff: needsTearOff);
291 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698