| 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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 sb.write('${setter}'); | 385 sb.write('${setter}'); |
| 386 } | 386 } |
| 387 sb.write(']'); | 387 sb.write(']'); |
| 388 return sb.toString(); | 388 return sb.toString(); |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 | 391 |
| 392 /// Enum representing the different kinds of destinations which a constructor | 392 /// Enum representing the different kinds of destinations which a constructor |
| 393 /// invocation might refer to. | 393 /// invocation might refer to. |
| 394 enum ConstructorAccessKind { | 394 enum ConstructorAccessKind { |
| 395 /// An invocation of a generative constructor. | 395 /// An invocation of a (redirecting) generative constructor. |
| 396 /// | 396 /// |
| 397 /// For instance | 397 /// For instance |
| 398 /// class C { | 398 /// class C { |
| 399 /// C(); | 399 /// C(); |
| 400 /// C.redirect() : this(); |
| 400 /// } | 401 /// } |
| 401 /// m() => new C(); | 402 /// m1() => new C(); |
| 403 /// m2() => new C.redirect(); |
| 402 /// | 404 /// |
| 403 GENERATIVE, | 405 GENERATIVE, |
| 404 | 406 |
| 405 /// An invocation of a redirecting generative constructor. | 407 /// An invocation of a (redirecting) factory constructor. |
| 406 /// | |
| 407 /// For instance | |
| 408 /// class C { | |
| 409 /// C() : this._(); | |
| 410 /// C._(); | |
| 411 /// } | |
| 412 /// m() => new C(); | |
| 413 /// | |
| 414 REDIRECTING_GENERATIVE, | |
| 415 | |
| 416 /// An invocation of a factory constructor. | |
| 417 /// | 408 /// |
| 418 /// For instance | 409 /// For instance |
| 419 /// class C { | 410 /// class C { |
| 420 /// factory C() => new C._(); | 411 /// factory C() => new C._(); |
| 412 /// factory C.redirect() => C._; |
| 421 /// C._(); | 413 /// C._(); |
| 422 /// } | 414 /// } |
| 423 /// m() => new C(); | 415 /// m1() => new C(); |
| 416 /// m2() => new C.redirect(); |
| 424 /// | 417 /// |
| 425 FACTORY, | 418 FACTORY, |
| 426 | 419 |
| 427 /// An invocation of a redirecting factory constructor. | |
| 428 /// | |
| 429 /// For instance | |
| 430 /// class C { | |
| 431 /// factory C() = C._; | |
| 432 /// C._(); | |
| 433 /// } | |
| 434 /// m() => new C(); | |
| 435 /// | |
| 436 REDIRECTING_FACTORY, | |
| 437 | |
| 438 /// An invocation of a (redirecting) generative constructor of an abstract | 420 /// An invocation of a (redirecting) generative constructor of an abstract |
| 439 /// class. | 421 /// class. |
| 440 /// | 422 /// |
| 441 /// For instance | 423 /// For instance |
| 442 /// abstract class C { | 424 /// abstract class C { |
| 443 /// C(); | 425 /// C(); |
| 444 /// } | 426 /// } |
| 445 /// m() => new C(); | 427 /// m() => new C(); |
| 446 /// | 428 /// |
| 447 ABSTRACT, | 429 ABSTRACT, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 466 /// An const invocation of an non-constant constructor. | 448 /// An const invocation of an non-constant constructor. |
| 467 /// | 449 /// |
| 468 /// For instance | 450 /// For instance |
| 469 /// class C { | 451 /// class C { |
| 470 /// C(); | 452 /// C(); |
| 471 /// } | 453 /// } |
| 472 /// m() => const C(); | 454 /// m() => const C(); |
| 473 /// | 455 /// |
| 474 NON_CONSTANT_CONSTRUCTOR, | 456 NON_CONSTANT_CONSTRUCTOR, |
| 475 | 457 |
| 476 /// An invocation of an ill-defined redirecting factory constructor. | |
| 477 /// | |
| 478 /// For instance | |
| 479 /// class C { | |
| 480 /// factory C() = Unresolved; | |
| 481 /// } | |
| 482 /// m() => new C(); | |
| 483 /// | |
| 484 ERRONEOUS_REDIRECTING_FACTORY, | |
| 485 | |
| 486 | |
| 487 /// An invocation of a constructor with incompatible arguments. | 458 /// An invocation of a constructor with incompatible arguments. |
| 488 /// | 459 /// |
| 489 /// For instance | 460 /// For instance |
| 490 /// class C { | 461 /// class C { |
| 491 /// C(); | 462 /// C(); |
| 492 /// } | 463 /// } |
| 493 /// m() => new C(true); | 464 /// m() => new C(true); |
| 494 /// | 465 /// |
| 495 INCOMPATIBLE, | 466 INCOMPATIBLE, |
| 496 } | 467 } |
| 497 | 468 |
| 498 /// Data structure used to classify the semantics of a constructor invocation. | 469 /// Data structure used to classify the semantics of a constructor invocation. |
| 499 class ConstructorAccessSemantics { | 470 class ConstructorAccessSemantics { |
| 500 /// The kind of constructor invocation. | 471 /// The kind of constructor invocation. |
| 501 final ConstructorAccessKind kind; | 472 final ConstructorAccessKind kind; |
| 502 | 473 |
| 503 /// The invoked constructor. | 474 /// The invoked constructor. |
| 504 final Element element; | 475 final Element element; |
| 505 | 476 |
| 506 /// The type on which the constructor is invoked. | 477 /// The type on which the constructor is invoked. |
| 507 final DartType type; | 478 final DartType type; |
| 508 | 479 |
| 509 ConstructorAccessSemantics(this.kind, this.element, this.type); | 480 ConstructorAccessSemantics(this.kind, this.element, this.type); |
| 510 | 481 |
| 511 /// The effect target of the access. Used to defined redirecting factory | |
| 512 /// constructor invocations. | |
| 513 ConstructorAccessSemantics get effectiveTargetSemantics => this; | |
| 514 | |
| 515 /// `true` if this invocation is erroneous. | |
| 516 bool get isErroneous { | |
| 517 return kind == ConstructorAccessKind.ABSTRACT || | |
| 518 kind == ConstructorAccessKind.UNRESOLVED_TYPE || | |
| 519 kind == ConstructorAccessKind.UNRESOLVED_CONSTRUCTOR || | |
| 520 kind == ConstructorAccessKind.NON_CONSTANT_CONSTRUCTOR || | |
| 521 kind == ConstructorAccessKind.ERRONEOUS_REDIRECTING_FACTORY || | |
| 522 kind == ConstructorAccessKind.INCOMPATIBLE; | |
| 523 } | |
| 524 | |
| 525 String toString() => 'ConstructorAccessSemantics($kind, $element, $type)'; | 482 String toString() => 'ConstructorAccessSemantics($kind, $element, $type)'; |
| 526 } | 483 } |
| 527 | |
| 528 /// Data structure used to classify the semantics of a redirecting factory | |
| 529 /// constructor invocation. | |
| 530 class RedirectingFactoryConstructorAccessSemantics | |
| 531 extends ConstructorAccessSemantics { | |
| 532 final ConstructorAccessSemantics effectiveTargetSemantics; | |
| 533 | |
| 534 RedirectingFactoryConstructorAccessSemantics( | |
| 535 ConstructorAccessKind kind, | |
| 536 Element element, | |
| 537 DartType type, | |
| 538 this.effectiveTargetSemantics) | |
| 539 : super(kind, element, type); | |
| 540 } | |
| 541 | |
| 542 | |
| OLD | NEW |