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 /** | 5 /** |
6 * Code for classifying the semantics of identifiers appearing in a Dart file. | 6 * Code for classifying the semantics of identifiers appearing in a Dart file. |
7 */ | 7 */ |
8 library dart2js.access_semantics; | 8 library dart2js.access_semantics; |
9 | 9 |
10 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 UNRESOLVED_SUPER, | 142 UNRESOLVED_SUPER, |
143 | 143 |
144 /// The destination is invalid as an access. For instance a prefix used | 144 /// The destination is invalid as an access. For instance a prefix used |
145 /// as an expression. | 145 /// as an expression. |
146 INVALID, | 146 INVALID, |
147 } | 147 } |
148 | 148 |
149 enum CompoundAccessKind { | 149 enum CompoundAccessKind { |
150 /// Read from a static getter and write to a static setter. | 150 /// Read from a static getter and write to a static setter. |
151 STATIC_GETTER_SETTER, | 151 STATIC_GETTER_SETTER, |
| 152 |
152 /// Read from a static method (closurize) and write to a static setter. | 153 /// Read from a static method (closurize) and write to a static setter. |
153 STATIC_METHOD_SETTER, | 154 STATIC_METHOD_SETTER, |
154 | 155 |
155 /// Read from an unresolved static getter and write to a static setter. | 156 /// Read from an unresolved static getter and write to a static setter. |
156 UNRESOLVED_STATIC_GETTER, | 157 UNRESOLVED_STATIC_GETTER, |
| 158 |
157 /// Read from a static getter and write to an unresolved static setter. | 159 /// Read from a static getter and write to an unresolved static setter. |
158 UNRESOLVED_STATIC_SETTER, | 160 UNRESOLVED_STATIC_SETTER, |
159 | 161 |
160 /// Read from a top level getter and write to a top level setter. | 162 /// Read from a top level getter and write to a top level setter. |
161 TOPLEVEL_GETTER_SETTER, | 163 TOPLEVEL_GETTER_SETTER, |
| 164 |
162 /// Read from a top level method (closurize) and write to top level setter. | 165 /// Read from a top level method (closurize) and write to top level setter. |
163 TOPLEVEL_METHOD_SETTER, | 166 TOPLEVEL_METHOD_SETTER, |
164 | 167 |
165 /// Read from an unresolved top level getter and write to a top level setter. | 168 /// Read from an unresolved top level getter and write to a top level setter. |
166 UNRESOLVED_TOPLEVEL_GETTER, | 169 UNRESOLVED_TOPLEVEL_GETTER, |
| 170 |
167 /// Read from a top level getter and write to an unresolved top level setter. | 171 /// Read from a top level getter and write to an unresolved top level setter. |
168 UNRESOLVED_TOPLEVEL_SETTER, | 172 UNRESOLVED_TOPLEVEL_SETTER, |
169 | 173 |
170 /// Read from one superclass field and write to another. | 174 /// Read from one superclass field and write to another. |
171 SUPER_FIELD_FIELD, | 175 SUPER_FIELD_FIELD, |
| 176 |
172 /// Read from a superclass field and write to a superclass setter. | 177 /// Read from a superclass field and write to a superclass setter. |
173 SUPER_FIELD_SETTER, | 178 SUPER_FIELD_SETTER, |
| 179 |
174 /// Read from a superclass getter and write to a superclass setter. | 180 /// Read from a superclass getter and write to a superclass setter. |
175 SUPER_GETTER_SETTER, | 181 SUPER_GETTER_SETTER, |
| 182 |
176 /// Read from a superclass method (closurize) and write to a superclass | 183 /// Read from a superclass method (closurize) and write to a superclass |
177 /// setter. | 184 /// setter. |
178 SUPER_METHOD_SETTER, | 185 SUPER_METHOD_SETTER, |
| 186 |
179 /// Read from a superclass getter and write to a superclass field. | 187 /// Read from a superclass getter and write to a superclass field. |
180 SUPER_GETTER_FIELD, | 188 SUPER_GETTER_FIELD, |
181 | 189 |
182 /// Read from a superclass where the getter is unresolved. | 190 /// Read from a superclass where the getter is unresolved. |
183 // TODO(johnniwinther): Use [AccessKind.SUPER_GETTER] when the erroneous | 191 // TODO(johnniwinther): Use [AccessKind.SUPER_GETTER] when the erroneous |
184 // element is no longer needed. | 192 // element is no longer needed. |
185 UNRESOLVED_SUPER_GETTER, | 193 UNRESOLVED_SUPER_GETTER, |
| 194 |
186 /// Read from a superclass getter and write to an unresolved setter. | 195 /// Read from a superclass getter and write to an unresolved setter. |
187 // TODO(johnniwinther): Use [AccessKind.SUPER_SETTER] when the erroneous | 196 // TODO(johnniwinther): Use [AccessKind.SUPER_SETTER] when the erroneous |
188 // element is no longer needed. | 197 // element is no longer needed. |
189 UNRESOLVED_SUPER_SETTER, | 198 UNRESOLVED_SUPER_SETTER, |
190 } | 199 } |
191 | 200 |
192 /** | 201 /** |
193 * Data structure used to classify the semantics of a property access or method | 202 * Data structure used to classify the semantics of a property access or method |
194 * or function invocation. | 203 * or function invocation. |
195 */ | 204 */ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 245 } |
237 } else if (name != null) { | 246 } else if (name != null) { |
238 sb.write('name='); | 247 sb.write('name='); |
239 sb.write(name); | 248 sb.write(name); |
240 } | 249 } |
241 sb.write(']'); | 250 sb.write(']'); |
242 return sb.toString(); | 251 return sb.toString(); |
243 } | 252 } |
244 } | 253 } |
245 | 254 |
246 | |
247 class DynamicAccess extends AccessSemantics { | 255 class DynamicAccess extends AccessSemantics { |
248 final Name name; | 256 final Name name; |
249 | 257 |
250 const DynamicAccess.expression() | 258 const DynamicAccess.expression() |
251 : name = null, | 259 : name = null, |
252 super._(AccessKind.EXPRESSION); | 260 super._(AccessKind.EXPRESSION); |
253 | 261 |
254 const DynamicAccess.thisAccess() | 262 const DynamicAccess.thisAccess() |
255 : name = null, | 263 : name = null, |
256 super._(AccessKind.THIS); | 264 super._(AccessKind.THIS); |
257 | 265 |
258 const DynamicAccess.thisProperty(this.name) | 266 const DynamicAccess.thisProperty(this.name) |
259 : super._(AccessKind.THIS_PROPERTY); | 267 : super._(AccessKind.THIS_PROPERTY); |
260 | 268 |
261 const DynamicAccess.dynamicProperty(this.name) | 269 const DynamicAccess.dynamicProperty(this.name) |
262 : super._(AccessKind.DYNAMIC_PROPERTY); | 270 : super._(AccessKind.DYNAMIC_PROPERTY); |
263 | 271 |
264 const DynamicAccess.ifNotNullProperty(this.name) | 272 const DynamicAccess.ifNotNullProperty(this.name) |
265 : super._(AccessKind.CONDITIONAL_DYNAMIC_PROPERTY); | 273 : super._(AccessKind.CONDITIONAL_DYNAMIC_PROPERTY); |
266 } | 274 } |
267 | 275 |
268 class ConstantAccess extends AccessSemantics { | 276 class ConstantAccess extends AccessSemantics { |
269 final ConstantExpression constant; | 277 final ConstantExpression constant; |
270 | 278 |
271 ConstantAccess(AccessKind kind, this.constant) | 279 ConstantAccess(AccessKind kind, this.constant) : super._(kind); |
272 : super._(kind); | |
273 | 280 |
274 ConstantAccess.classTypeLiteral(this.constant) | 281 ConstantAccess.classTypeLiteral(this.constant) |
275 : super._(AccessKind.CLASS_TYPE_LITERAL); | 282 : super._(AccessKind.CLASS_TYPE_LITERAL); |
276 | 283 |
277 ConstantAccess.typedefTypeLiteral(this.constant) | 284 ConstantAccess.typedefTypeLiteral(this.constant) |
278 : super._(AccessKind.TYPEDEF_TYPE_LITERAL); | 285 : super._(AccessKind.TYPEDEF_TYPE_LITERAL); |
279 | 286 |
280 ConstantAccess.dynamicTypeLiteral(this.constant) | 287 ConstantAccess.dynamicTypeLiteral(this.constant) |
281 : super._(AccessKind.DYNAMIC_TYPE_LITERAL); | 288 : super._(AccessKind.DYNAMIC_TYPE_LITERAL); |
282 } | 289 } |
283 | 290 |
284 class StaticAccess extends AccessSemantics { | 291 class StaticAccess extends AccessSemantics { |
285 final Element element; | 292 final Element element; |
286 | 293 |
287 StaticAccess._(AccessKind kind, this.element) | 294 StaticAccess._(AccessKind kind, this.element) : super._(kind); |
288 : super._(kind); | |
289 | 295 |
290 StaticAccess.superSetter(MethodElement this.element) | 296 StaticAccess.superSetter(MethodElement this.element) |
291 : super._(AccessKind.SUPER_SETTER); | 297 : super._(AccessKind.SUPER_SETTER); |
292 | 298 |
293 StaticAccess.superField(FieldElement this.element) | 299 StaticAccess.superField(FieldElement this.element) |
294 : super._(AccessKind.SUPER_FIELD); | 300 : super._(AccessKind.SUPER_FIELD); |
295 | 301 |
296 StaticAccess.superFinalField(FieldElement this.element) | 302 StaticAccess.superFinalField(FieldElement this.element) |
297 : super._(AccessKind.SUPER_FINAL_FIELD); | 303 : super._(AccessKind.SUPER_FINAL_FIELD); |
298 | 304 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 349 |
344 StaticAccess.topLevelMethod(MethodElement this.element) | 350 StaticAccess.topLevelMethod(MethodElement this.element) |
345 : super._(AccessKind.TOPLEVEL_METHOD); | 351 : super._(AccessKind.TOPLEVEL_METHOD); |
346 | 352 |
347 StaticAccess.topLevelGetter(MethodElement this.element) | 353 StaticAccess.topLevelGetter(MethodElement this.element) |
348 : super._(AccessKind.TOPLEVEL_GETTER); | 354 : super._(AccessKind.TOPLEVEL_GETTER); |
349 | 355 |
350 StaticAccess.topLevelSetter(MethodElement this.element) | 356 StaticAccess.topLevelSetter(MethodElement this.element) |
351 : super._(AccessKind.TOPLEVEL_SETTER); | 357 : super._(AccessKind.TOPLEVEL_SETTER); |
352 | 358 |
353 StaticAccess.unresolved(this.element) | 359 StaticAccess.unresolved(this.element) : super._(AccessKind.UNRESOLVED); |
354 : super._(AccessKind.UNRESOLVED); | |
355 | 360 |
356 StaticAccess.unresolvedSuper(this.element) | 361 StaticAccess.unresolvedSuper(this.element) |
357 : super._(AccessKind.UNRESOLVED_SUPER); | 362 : super._(AccessKind.UNRESOLVED_SUPER); |
358 | 363 |
359 StaticAccess.invalid(this.element) | 364 StaticAccess.invalid(this.element) : super._(AccessKind.INVALID); |
360 : super._(AccessKind.INVALID); | |
361 } | 365 } |
362 | 366 |
363 class CompoundAccessSemantics extends AccessSemantics { | 367 class CompoundAccessSemantics extends AccessSemantics { |
364 final CompoundAccessKind compoundAccessKind; | 368 final CompoundAccessKind compoundAccessKind; |
365 final Element getter; | 369 final Element getter; |
366 final Element setter; | 370 final Element setter; |
367 | 371 |
368 CompoundAccessSemantics(this.compoundAccessKind, | 372 CompoundAccessSemantics(this.compoundAccessKind, this.getter, this.setter) |
369 this.getter, | |
370 this.setter) | |
371 : super._(AccessKind.COMPOUND); | 373 : super._(AccessKind.COMPOUND); |
372 | 374 |
373 Element get element => setter; | 375 Element get element => setter; |
374 | 376 |
375 String toString() { | 377 String toString() { |
376 StringBuffer sb = new StringBuffer(); | 378 StringBuffer sb = new StringBuffer(); |
377 sb.write('CompoundAccessSemantics['); | 379 sb.write('CompoundAccessSemantics['); |
378 sb.write('kind=$compoundAccessKind'); | 380 sb.write('kind=$compoundAccessKind'); |
379 if (getter != null) { | 381 if (getter != null) { |
380 sb.write(',getter='); | 382 sb.write(',getter='); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 /// The invoked constructor. | 476 /// The invoked constructor. |
475 final Element element; | 477 final Element element; |
476 | 478 |
477 /// The type on which the constructor is invoked. | 479 /// The type on which the constructor is invoked. |
478 final DartType type; | 480 final DartType type; |
479 | 481 |
480 ConstructorAccessSemantics(this.kind, this.element, this.type); | 482 ConstructorAccessSemantics(this.kind, this.element, this.type); |
481 | 483 |
482 String toString() => 'ConstructorAccessSemantics($kind, $element, $type)'; | 484 String toString() => 'ConstructorAccessSemantics($kind, $element, $type)'; |
483 } | 485 } |
OLD | NEW |