| 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 #library('elements'); | 5 #library('elements'); |
| 6 | 6 |
| 7 #import('../tree/tree.dart'); | 7 #import('../tree/tree.dart'); |
| 8 #import('../scanner/scannerlib.dart'); | 8 #import('../scanner/scannerlib.dart'); |
| 9 #import('../leg.dart'); // TODO(karlklose): we only need type. | 9 #import('../leg.dart'); // TODO(karlklose): we only need type. |
| 10 #import('../util/util.dart'); | 10 #import('../util/util.dart'); |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 548 } |
| 549 | 549 |
| 550 Token position() => constructor.position(); | 550 Token position() => constructor.position(); |
| 551 } | 551 } |
| 552 | 552 |
| 553 class SynthesizedConstructorElement extends FunctionElement { | 553 class SynthesizedConstructorElement extends FunctionElement { |
| 554 SynthesizedConstructorElement(Element enclosing) | 554 SynthesizedConstructorElement(Element enclosing) |
| 555 : super(enclosing.name, ElementKind.GENERATIVE_CONSTRUCTOR, | 555 : super(enclosing.name, ElementKind.GENERATIVE_CONSTRUCTOR, |
| 556 null, enclosing); | 556 null, enclosing); |
| 557 | 557 |
| 558 FunctionType computeType(Compiler compiler) { | 558 Token position() => enclosing.position(); |
| 559 if (type != null) return type; | |
| 560 Type returnType = compiler.types.voidType; | |
| 561 type = new FunctionType(returnType, const EmptyLink<Type>(), this); | |
| 562 return type; | |
| 563 } | |
| 564 | |
| 565 Node parseNode(DiagnosticListener listener) { | |
| 566 if (cachedNode != null) return cachedNode; | |
| 567 cachedNode = new FunctionExpression( | |
| 568 new Identifier(enclosingElement.position()), | |
| 569 new NodeList.empty(), | |
| 570 new Block(new NodeList.empty()), | |
| 571 null, null, null, null); | |
| 572 return cachedNode; | |
| 573 } | |
| 574 | |
| 575 Token position() => null; | |
| 576 } | 559 } |
| 577 | 560 |
| 578 class ClassElement extends ContainerElement { | 561 class ClassElement extends ContainerElement { |
| 579 Type type; | 562 Type type; |
| 580 Type supertype; | 563 Type supertype; |
| 581 Type defaultClass; | 564 Type defaultClass; |
| 582 Link<Element> members = const EmptyLink<Element>(); | 565 Link<Element> members = const EmptyLink<Element>(); |
| 583 Map<SourceString, Element> localMembers; | 566 Map<SourceString, Element> localMembers; |
| 584 Map<SourceString, Element> constructors; | 567 Map<SourceString, Element> constructors; |
| 585 Link<Type> interfaces = const EmptyLink<Type>(); | 568 Link<Type> interfaces = const EmptyLink<Type>(); |
| 586 bool isResolved = false; | 569 bool isResolved = false; |
| 587 // backendMembers are members that have been added by the backend to simplify | 570 // backendMembers are members that have been added by the backend to simplify |
| 588 // compilation. They don't have any user-side counter-part. | 571 // compilation. They don't have any user-side counter-part. |
| 589 Link<Element> backendMembers = const EmptyLink<Element>(); | 572 Link<Element> backendMembers = const EmptyLink<Element>(); |
| 590 SynthesizedConstructorElement synthesizedConstructor; | |
| 591 | 573 |
| 592 Link<Type> allSupertypes; | 574 Link<Type> allSupertypes; |
| 593 | 575 |
| 594 ClassElement(SourceString name, CompilationUnitElement enclosing) | 576 ClassElement(SourceString name, CompilationUnitElement enclosing) |
| 595 : localMembers = new Map<SourceString, Element>(), | 577 : localMembers = new Map<SourceString, Element>(), |
| 596 constructors = new Map<SourceString, Element>(), | 578 constructors = new Map<SourceString, Element>(), |
| 597 super(name, ElementKind.CLASS, enclosing); | 579 super(name, ElementKind.CLASS, enclosing); |
| 598 | 580 |
| 599 void addMember(Element element, DiagnosticListener listener) { | 581 void addMember(Element element, DiagnosticListener listener) { |
| 600 members = members.prepend(element); | 582 members = members.prepend(element); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 } else { | 663 } else { |
| 682 normalizedName = className; | 664 normalizedName = className; |
| 683 } | 665 } |
| 684 Element result = constructors[normalizedName]; | 666 Element result = constructors[normalizedName]; |
| 685 if (result === null && noMatch !== null) { | 667 if (result === null && noMatch !== null) { |
| 686 result = noMatch(lookupLocalMember(constructorName)); | 668 result = noMatch(lookupLocalMember(constructorName)); |
| 687 } | 669 } |
| 688 return result; | 670 return result; |
| 689 } | 671 } |
| 690 | 672 |
| 691 bool canHaveDefaultConstructor() => constructors.length == 0; | |
| 692 | |
| 693 SynthesizedConstructorElement getSynthesizedConstructor() { | |
| 694 // TODO(ahe): Get rid of this method. Add the | |
| 695 // SynthesizedConstructorElement to [constructors] if empty when | |
| 696 // [resolve] is called. | |
| 697 if (synthesizedConstructor === null && canHaveDefaultConstructor()) { | |
| 698 synthesizedConstructor = new SynthesizedConstructorElement(this); | |
| 699 } | |
| 700 return synthesizedConstructor; | |
| 701 } | |
| 702 | |
| 703 /** | 673 /** |
| 704 * Returns the super class, if any. | 674 * Returns the super class, if any. |
| 705 * | 675 * |
| 706 * The returned element may not be resolved yet. | 676 * The returned element may not be resolved yet. |
| 707 */ | 677 */ |
| 708 ClassElement get superclass() { | 678 ClassElement get superclass() { |
| 709 assert(isResolved); | 679 assert(isResolved); |
| 710 return supertype === null ? null : supertype.element; | 680 return supertype === null ? null : supertype.element; |
| 711 } | 681 } |
| 712 | 682 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 | 826 |
| 857 LabelElement addLabel(Identifier label, String labelName) { | 827 LabelElement addLabel(Identifier label, String labelName) { |
| 858 LabelElement result = new LabelElement(label, labelName, this, | 828 LabelElement result = new LabelElement(label, labelName, this, |
| 859 enclosingElement); | 829 enclosingElement); |
| 860 labels = labels.prepend(result); | 830 labels = labels.prepend(result); |
| 861 return result; | 831 return result; |
| 862 } | 832 } |
| 863 | 833 |
| 864 Node parseNode(DiagnosticListener l) => statement; | 834 Node parseNode(DiagnosticListener l) => statement; |
| 865 } | 835 } |
| OLD | NEW |