| 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 // TODO(johnniwinther): Temporarily copied from analyzer2dart. Merge when | 5 // TODO(johnniwinther): Temporarily copied from analyzer2dart. Merge when |
| 6 // we shared code with the analyzer and this semantic visitor is complete. | 6 // we shared code with the analyzer and this semantic visitor is complete. |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Code for classifying the semantics of identifiers appearing in a Dart file. | 9 * Code for classifying the semantics of identifiers appearing in a Dart file. |
| 10 */ | 10 */ |
| 11 library dart2js.access_semantics; | 11 library dart2js.access_semantics; |
| 12 | 12 |
| 13 import '../constants/expressions.dart'; | 13 import '../constants/expressions.dart'; |
| 14 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
| 15 import '../dart_types.dart'; |
| 15 | 16 |
| 16 /// Enum representing the different kinds of destinations which a property | 17 /// Enum representing the different kinds of destinations which a property |
| 17 /// access or method or function invocation might refer to. | 18 /// access or method or function invocation might refer to. |
| 18 enum AccessKind { | 19 enum AccessKind { |
| 19 /// The destination of the access is an instance method, property, or field | 20 /// The destination of the access is an instance method, property, or field |
| 20 /// of a class, and thus must be determined dynamically. | 21 /// of a class, and thus must be determined dynamically. |
| 21 DYNAMIC_PROPERTY, | 22 DYNAMIC_PROPERTY, |
| 22 | 23 |
| 23 // TODO(johnniwinther): Split these cases into captured and non-captured | 24 // TODO(johnniwinther): Split these cases into captured and non-captured |
| 24 // local access. | 25 // local access. |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 final Element getter; | 301 final Element getter; |
| 301 final Element setter; | 302 final Element setter; |
| 302 | 303 |
| 303 CompoundAccessSemantics(this.compoundAccessKind, | 304 CompoundAccessSemantics(this.compoundAccessKind, |
| 304 this.getter, | 305 this.getter, |
| 305 this.setter) | 306 this.setter) |
| 306 : super._(AccessKind.COMPOUND); | 307 : super._(AccessKind.COMPOUND); |
| 307 | 308 |
| 308 Element get element => setter; | 309 Element get element => setter; |
| 309 } | 310 } |
| 311 |
| 312 /// Enum representing the different kinds of destinations which a constructor |
| 313 /// invocation might refer to. |
| 314 enum ConstructorAccessKind { |
| 315 /// An invocation of a generative constructor. |
| 316 /// |
| 317 /// For instance |
| 318 /// class C { |
| 319 /// C(); |
| 320 /// } |
| 321 /// m() => new C(); |
| 322 /// |
| 323 GENERATIVE, |
| 324 |
| 325 /// An invocation of a redirecting generative constructor. |
| 326 /// |
| 327 /// For instance |
| 328 /// class C { |
| 329 /// C() : this._(); |
| 330 /// C._(); |
| 331 /// } |
| 332 /// m() => new C(); |
| 333 /// |
| 334 REDIRECTING_GENERATIVE, |
| 335 |
| 336 /// An invocation of a factory constructor. |
| 337 /// |
| 338 /// For instance |
| 339 /// class C { |
| 340 /// factory C() => new C._(); |
| 341 /// C._(); |
| 342 /// } |
| 343 /// m() => new C(); |
| 344 /// |
| 345 FACTORY, |
| 346 |
| 347 /// An invocation of a redirecting factory constructor. |
| 348 /// |
| 349 /// For instance |
| 350 /// class C { |
| 351 /// factory C() = C._; |
| 352 /// C._(); |
| 353 /// } |
| 354 /// m() => new C(); |
| 355 /// |
| 356 REDIRECTING_FACTORY, |
| 357 |
| 358 /// An invocation of a (redirecting) generative constructor of an abstract |
| 359 /// class. |
| 360 /// |
| 361 /// For instance |
| 362 /// abstract class C { |
| 363 /// C(); |
| 364 /// } |
| 365 /// m() => new C(); |
| 366 /// |
| 367 ABSTRACT, |
| 368 |
| 369 /// An invocation of an unresolved constructor or an unresolved type. |
| 370 /// |
| 371 /// For instance |
| 372 /// class C { |
| 373 /// C(); |
| 374 /// } |
| 375 /// m1() => new C.unresolved(); |
| 376 /// m2() => new Unresolved(); |
| 377 /// |
| 378 // TODO(johnniwinther): Differentiate between error types. |
| 379 ERRONEOUS, |
| 380 |
| 381 /// An invocation of an ill-defined redirecting factory constructor. |
| 382 /// |
| 383 /// For instance |
| 384 /// class C { |
| 385 /// factory C() = Unresolved; |
| 386 /// } |
| 387 /// m() => new C(); |
| 388 /// |
| 389 ERRONEOUS_REDIRECTING_FACTORY, |
| 390 } |
| 391 |
| 392 /// Data structure used to classify the semantics of a constructor invocation. |
| 393 class ConstructorAccessSemantics { |
| 394 /// The kind of constructor invocation. |
| 395 final ConstructorAccessKind kind; |
| 396 |
| 397 /// The invoked constructor. |
| 398 final Element element; |
| 399 |
| 400 /// The type on which the constructor is invoked. |
| 401 final DartType type; |
| 402 |
| 403 ConstructorAccessSemantics(this.kind, this.element, this.type); |
| 404 |
| 405 /// The effect target of the access. Used to defined redirecting factory |
| 406 /// constructor invocations. |
| 407 ConstructorAccessSemantics get effectiveTargetSemantics => this; |
| 408 |
| 409 /// `true` if this invocation is erroneous. |
| 410 bool get isErroneous { |
| 411 return kind == ConstructorAccessKind.ABSTRACT || |
| 412 kind == ConstructorAccessKind.ERRONEOUS || |
| 413 kind == ConstructorAccessKind.ERRONEOUS_REDIRECTING_FACTORY; |
| 414 } |
| 415 } |
| 416 |
| 417 /// Data structure used to classify the semantics of a redirecting factory |
| 418 /// constructor invocation. |
| 419 class RedirectingFactoryConstructorAccessSemantics |
| 420 extends ConstructorAccessSemantics { |
| 421 final ConstructorAccessSemantics effectiveTargetSemantics; |
| 422 |
| 423 RedirectingFactoryConstructorAccessSemantics( |
| 424 ConstructorAccessKind kind, |
| 425 Element element, |
| 426 DartType type, |
| 427 this.effectiveTargetSemantics) |
| 428 : super(kind, element, type); |
| 429 } |
| 430 |
| 431 |
| OLD | NEW |