| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #import('dart:uri'); | 5 #import('dart:uri'); |
| 6 | 6 |
| 7 #import("../../../lib/compiler/implementation/leg.dart"); | 7 #import("../../../lib/compiler/implementation/leg.dart"); |
| 8 #import("../../../lib/compiler/implementation/elements/elements.dart"); | 8 #import("../../../lib/compiler/implementation/elements/elements.dart"); |
| 9 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 9 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 10 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart"); | 10 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart"); |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 resolveConstructor(String script, String statement, String className, | 556 resolveConstructor(String script, String statement, String className, |
| 557 String constructor, int expectedElementCount, | 557 String constructor, int expectedElementCount, |
| 558 [List expectedWarnings = const [], | 558 [List expectedWarnings = const [], |
| 559 List expectedErrors = const [], | 559 List expectedErrors = const [], |
| 560 String corelib = DEFAULT_CORELIB]) { | 560 String corelib = DEFAULT_CORELIB]) { |
| 561 MockCompiler compiler = new MockCompiler(corelib); | 561 MockCompiler compiler = new MockCompiler(corelib); |
| 562 compiler.parseScript(script); | 562 compiler.parseScript(script); |
| 563 compiler.resolveStatement(statement); | 563 compiler.resolveStatement(statement); |
| 564 ClassElement classElement = | 564 ClassElement classElement = |
| 565 compiler.mainApp.find(buildSourceString(className)); | 565 compiler.mainApp.find(buildSourceString(className)); |
| 566 Element element = | 566 Element element; |
| 567 classElement.lookupConstructor( | 567 if (constructor !== '') { |
| 568 new Selector.callConstructor(buildSourceString(constructor), | 568 element = classElement.lookupConstructor( |
| 569 classElement.getLibrary())); | 569 new Selector.callConstructor(buildSourceString(constructor), |
| 570 classElement.getLibrary())); |
| 571 } else { |
| 572 element = classElement.lookupConstructor( |
| 573 new Selector.callDefaultConstructor(classElement.getLibrary())); |
| 574 } |
| 575 |
| 570 FunctionExpression tree = element.parseNode(compiler); | 576 FunctionExpression tree = element.parseNode(compiler); |
| 571 ResolverVisitor visitor = new ResolverVisitor(compiler, element); | 577 ResolverVisitor visitor = new ResolverVisitor(compiler, element); |
| 572 new InitializerResolver(visitor).resolveInitializers(element, tree); | 578 new InitializerResolver(visitor).resolveInitializers(element, tree); |
| 573 visitor.visit(tree.body); | 579 visitor.visit(tree.body); |
| 574 Expect.equals(expectedElementCount, map(visitor).length); | 580 Expect.equals(expectedElementCount, map(visitor).length); |
| 575 | 581 |
| 576 compareWarningKinds(script, expectedWarnings, compiler.warnings); | 582 compareWarningKinds(script, expectedWarnings, compiler.warnings); |
| 577 compareWarningKinds(script, expectedErrors, compiler.errors); | 583 compareWarningKinds(script, expectedErrors, compiler.errors); |
| 578 } | 584 } |
| 579 | 585 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 Expect.equals(<String>['B', 'C', 'Object'].toString(), | 622 Expect.equals(<String>['B', 'C', 'Object'].toString(), |
| 617 asSortedStrings(supertypes).toString()); | 623 asSortedStrings(supertypes).toString()); |
| 618 } | 624 } |
| 619 | 625 |
| 620 testInitializers() { | 626 testInitializers() { |
| 621 String script; | 627 String script; |
| 622 script = """class A { | 628 script = """class A { |
| 623 int foo; int bar; | 629 int foo; int bar; |
| 624 A() : this.foo = 1, bar = 2; | 630 A() : this.foo = 1, bar = 2; |
| 625 }"""; | 631 }"""; |
| 626 resolveConstructor(script, "A a = new A();", "A", "A", 2); | 632 resolveConstructor(script, "A a = new A();", "A", "", 2); |
| 627 | 633 |
| 628 script = """class A { | 634 script = """class A { |
| 629 int foo; A a; | 635 int foo; A a; |
| 630 A() : a.foo = 1; | 636 A() : a.foo = 1; |
| 631 }"""; | 637 }"""; |
| 632 resolveConstructor(script, "A a = new A();", "A", "A", 0, | 638 resolveConstructor(script, "A a = new A();", "A", "", 0, |
| 633 [], [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]); | 639 [], [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]); |
| 634 | 640 |
| 635 script = """class A { | 641 script = """class A { |
| 636 int foo; | 642 int foo; |
| 637 A() : this.foo = 1, this.foo = 2; | 643 A() : this.foo = 1, this.foo = 2; |
| 638 }"""; | 644 }"""; |
| 639 resolveConstructor(script, "A a = new A();", "A", "A", 2, | 645 resolveConstructor(script, "A a = new A();", "A", "", 2, |
| 640 [MessageKind.ALREADY_INITIALIZED], | 646 [MessageKind.ALREADY_INITIALIZED], |
| 641 [MessageKind.DUPLICATE_INITIALIZER]); | 647 [MessageKind.DUPLICATE_INITIALIZER]); |
| 642 | 648 |
| 643 script = """class A { | 649 script = """class A { |
| 644 A() : this.foo = 1; | 650 A() : this.foo = 1; |
| 645 }"""; | 651 }"""; |
| 646 resolveConstructor(script, "A a = new A();", "A", "A", 0, | 652 resolveConstructor(script, "A a = new A();", "A", "", 0, |
| 647 [], [MessageKind.CANNOT_RESOLVE]); | 653 [], [MessageKind.CANNOT_RESOLVE]); |
| 648 | 654 |
| 649 script = """class A { | 655 script = """class A { |
| 650 int foo; | 656 int foo; |
| 651 int bar; | 657 int bar; |
| 652 A() : this.foo = bar; | 658 A() : this.foo = bar; |
| 653 }"""; | 659 }"""; |
| 654 resolveConstructor(script, "A a = new A();", "A", "A", 3, | 660 resolveConstructor(script, "A a = new A();", "A", "", 3, |
| 655 [], [MessageKind.NO_INSTANCE_AVAILABLE]); | 661 [], [MessageKind.NO_INSTANCE_AVAILABLE]); |
| 656 | 662 |
| 657 script = """class A { | 663 script = """class A { |
| 658 int foo() => 42; | 664 int foo() => 42; |
| 659 A() : foo(); | 665 A() : foo(); |
| 660 }"""; | 666 }"""; |
| 661 resolveConstructor(script, "A a = new A();", "A", "A", 0, | 667 resolveConstructor(script, "A a = new A();", "A", "", 0, |
| 662 [], [MessageKind.CONSTRUCTOR_CALL_EXPECTED]); | 668 [], [MessageKind.CONSTRUCTOR_CALL_EXPECTED]); |
| 663 | 669 |
| 664 script = """class A { | 670 script = """class A { |
| 665 int i; | 671 int i; |
| 666 A.a() : this.b(0); | 672 A.a() : this.b(0); |
| 667 A.b(int i); | 673 A.b(int i); |
| 668 }"""; | 674 }"""; |
| 669 resolveConstructor(script, "A a = new A.a();", "A", "a", 1, | 675 resolveConstructor(script, "A a = new A.a();", "A", "a", 1, |
| 670 [], []); | 676 [], []); |
| 671 | 677 |
| 672 script = """class A { | 678 script = """class A { |
| 673 int i; | 679 int i; |
| 674 A.a() : i = 42, this(0); | 680 A.a() : i = 42, this(0); |
| 675 A(int i); | 681 A(int i); |
| 676 }"""; | 682 }"""; |
| 677 resolveConstructor(script, "A a = new A.a();", "A", "a", 2, | 683 resolveConstructor(script, "A a = new A.a();", "A", "a", 2, |
| 678 [], [MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER]); | 684 [], [MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER]); |
| 679 | 685 |
| 680 script = """class A { | 686 script = """class A { |
| 681 int i; | 687 int i; |
| 682 A(i); | 688 A(i); |
| 683 } | 689 } |
| 684 class B extends A { | 690 class B extends A { |
| 685 B() : super(0); | 691 B() : super(0); |
| 686 }"""; | 692 }"""; |
| 687 resolveConstructor(script, "B a = new B();", "B", "B", 1, | 693 resolveConstructor(script, "B a = new B();", "B", "", 1, |
| 688 [], []); | 694 [], []); |
| 689 | 695 |
| 690 script = """class A { | 696 script = """class A { |
| 691 int i; | 697 int i; |
| 692 A(i); | 698 A(i); |
| 693 } | 699 } |
| 694 class B extends A { | 700 class B extends A { |
| 695 B() : super(0), super(1); | 701 B() : super(0), super(1); |
| 696 }"""; | 702 }"""; |
| 697 resolveConstructor(script, "B b = new B();", "B", "B", 2, | 703 resolveConstructor(script, "B b = new B();", "B", "", 2, |
| 698 [], [MessageKind.DUPLICATE_SUPER_INITIALIZER]); | 704 [], [MessageKind.DUPLICATE_SUPER_INITIALIZER]); |
| 699 | 705 |
| 700 script = ""; | 706 script = ""; |
| 701 final String CORELIB_WITH_INVALID_OBJECT = | 707 final String CORELIB_WITH_INVALID_OBJECT = |
| 702 '''print(var obj) {} | 708 '''print(var obj) {} |
| 703 class int {} | 709 class int {} |
| 704 class double {} | 710 class double {} |
| 705 class bool {} | 711 class bool {} |
| 706 class String {} | 712 class String {} |
| 707 class num {} | 713 class num {} |
| 708 class Function {} | 714 class Function {} |
| 709 class List {} | 715 class List {} |
| 710 class Closure {} | 716 class Closure {} |
| 711 class Null {} | 717 class Null {} |
| 712 class Dynamic_ {} | 718 class Dynamic_ {} |
| 713 class Object { Object() : super(); }'''; | 719 class Object { Object() : super(); }'''; |
| 714 resolveConstructor(script, "Object o = new Object();", "Object", "Object", 1, | 720 resolveConstructor(script, "Object o = new Object();", "Object", "", 1, |
| 715 [], [MessageKind.SUPER_INITIALIZER_IN_OBJECT], | 721 [], [MessageKind.SUPER_INITIALIZER_IN_OBJECT], |
| 716 corelib: CORELIB_WITH_INVALID_OBJECT); | 722 corelib: CORELIB_WITH_INVALID_OBJECT); |
| 717 } | 723 } |
| 718 | 724 |
| 719 map(ResolverVisitor visitor) { | 725 map(ResolverVisitor visitor) { |
| 720 TreeElementMapping elements = visitor.mapping; | 726 TreeElementMapping elements = visitor.mapping; |
| 721 return elements.map; | 727 return elements.map; |
| 722 } | 728 } |
| 723 | 729 |
| 724 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); | 730 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 var d = new D(); | 791 var d = new D(); |
| 786 --d; | 792 --d; |
| 787 }"""; | 793 }"""; |
| 788 final compiler = compileScript(script); | 794 final compiler = compileScript(script); |
| 789 | 795 |
| 790 checkMemberResolved(compiler, 'A', operatorName('+', false)); | 796 checkMemberResolved(compiler, 'A', operatorName('+', false)); |
| 791 checkMemberResolved(compiler, 'B', operatorName('+', false)); | 797 checkMemberResolved(compiler, 'B', operatorName('+', false)); |
| 792 checkMemberResolved(compiler, 'C', operatorName('-', false)); | 798 checkMemberResolved(compiler, 'C', operatorName('-', false)); |
| 793 checkMemberResolved(compiler, 'D', operatorName('-', false)); | 799 checkMemberResolved(compiler, 'D', operatorName('-', false)); |
| 794 } | 800 } |
| OLD | NEW |