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('dart:uri'); | 7 #import('dart:uri'); |
8 | 8 |
9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. | 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. |
10 #import('../../compiler.dart', prefix: 'api_e'); | 10 #import('../../compiler.dart', prefix: 'api_e'); |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 class VariableElement extends Element { | 814 class VariableElement extends Element { |
815 final VariableListElement variables; | 815 final VariableListElement variables; |
816 Expression cachedNode; // The send or the identifier in the variables list. | 816 Expression cachedNode; // The send or the identifier in the variables list. |
817 | 817 |
818 Modifiers get modifiers => variables.modifiers; | 818 Modifiers get modifiers => variables.modifiers; |
819 | 819 |
820 VariableElement(SourceString name, | 820 VariableElement(SourceString name, |
821 VariableListElement this.variables, | 821 VariableListElement this.variables, |
822 ElementKind kind, | 822 ElementKind kind, |
823 Element enclosing, | 823 Element enclosing, |
824 [Node node]) | 824 {Node node}) |
825 : super(name, kind, enclosing), cachedNode = node; | 825 : super(name, kind, enclosing), cachedNode = node; |
826 | 826 |
827 Node parseNode(DiagnosticListener listener) { | 827 Node parseNode(DiagnosticListener listener) { |
828 if (cachedNode !== null) return cachedNode; | 828 if (cachedNode !== null) return cachedNode; |
829 VariableDefinitions definitions = variables.parseNode(listener); | 829 VariableDefinitions definitions = variables.parseNode(listener); |
830 for (Link<Node> link = definitions.definitions.nodes; | 830 for (Link<Node> link = definitions.definitions.nodes; |
831 !link.isEmpty(); link = link.tail) { | 831 !link.isEmpty(); link = link.tail) { |
832 Expression initializedIdentifier = link.head; | 832 Expression initializedIdentifier = link.head; |
833 Identifier identifier = initializedIdentifier.asIdentifier(); | 833 Identifier identifier = initializedIdentifier.asIdentifier(); |
834 if (identifier === null) { | 834 if (identifier === null) { |
(...skipping 25 matching lines...) Expand all Loading... |
860 * [:A(this.field):]. | 860 * [:A(this.field):]. |
861 */ | 861 */ |
862 class FieldParameterElement extends VariableElement { | 862 class FieldParameterElement extends VariableElement { |
863 VariableElement fieldElement; | 863 VariableElement fieldElement; |
864 | 864 |
865 FieldParameterElement(SourceString name, | 865 FieldParameterElement(SourceString name, |
866 this.fieldElement, | 866 this.fieldElement, |
867 VariableListElement variables, | 867 VariableListElement variables, |
868 Element enclosing, | 868 Element enclosing, |
869 Node node) | 869 Node node) |
870 : super(name, variables, ElementKind.FIELD_PARAMETER, enclosing, node); | 870 : super(name, variables, ElementKind.FIELD_PARAMETER, enclosing, |
| 871 node: node); |
871 } | 872 } |
872 | 873 |
873 // This element represents a list of variable or field declaration. | 874 // This element represents a list of variable or field declaration. |
874 // It contains the node, and the type. A [VariableElement] always | 875 // It contains the node, and the type. A [VariableElement] always |
875 // references its [VariableListElement]. It forwards its | 876 // references its [VariableListElement]. It forwards its |
876 // [computeType] and [parseNode] methods to this element. | 877 // [computeType] and [parseNode] methods to this element. |
877 class VariableListElement extends Element { | 878 class VariableListElement extends Element { |
878 VariableDefinitions cachedNode; | 879 VariableDefinitions cachedNode; |
879 DartType type; | 880 DartType type; |
880 final Modifiers modifiers; | 881 final Modifiers modifiers; |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 /** | 1545 /** |
1545 * Runs through all members of this class. | 1546 * Runs through all members of this class. |
1546 * | 1547 * |
1547 * The enclosing class is passed to the callback. This is useful when | 1548 * The enclosing class is passed to the callback. This is useful when |
1548 * [includeSuperMembers] is [:true:]. | 1549 * [includeSuperMembers] is [:true:]. |
1549 * | 1550 * |
1550 * When called on an implementation element both the members in the origin | 1551 * When called on an implementation element both the members in the origin |
1551 * and patch class are included. | 1552 * and patch class are included. |
1552 */ | 1553 */ |
1553 // TODO(johnniwinther): Clean up lookup to get rid of the include predicates. | 1554 // TODO(johnniwinther): Clean up lookup to get rid of the include predicates. |
1554 void forEachMember([void f(ClassElement enclosingClass, Element member), | 1555 void forEachMember(void f(ClassElement enclosingClass, Element member), |
1555 includeBackendMembers = false, | 1556 {includeBackendMembers: false, |
1556 includeSuperMembers = false]) { | 1557 includeSuperMembers: false}) { |
1557 bool includeInjectedMembers = isPatch; | 1558 bool includeInjectedMembers = isPatch; |
1558 Set<ClassElement> seen = new Set<ClassElement>(); | 1559 Set<ClassElement> seen = new Set<ClassElement>(); |
1559 ClassElement classElement = declaration; | 1560 ClassElement classElement = declaration; |
1560 do { | 1561 do { |
1561 if (seen.contains(classElement)) return; | 1562 if (seen.contains(classElement)) return; |
1562 seen.add(classElement); | 1563 seen.add(classElement); |
1563 | 1564 |
1564 // Iterate through the members in textual order, which requires | 1565 // Iterate through the members in textual order, which requires |
1565 // to reverse the data structure [localMembers] we created. | 1566 // to reverse the data structure [localMembers] we created. |
1566 // Textual order may be important for certain operations, for | 1567 // Textual order may be important for certain operations, for |
(...skipping 25 matching lines...) Expand all Loading... |
1592 * The enclosing class is passed to the callback. This is useful when | 1593 * The enclosing class is passed to the callback. This is useful when |
1593 * [includeSuperMembers] is [:true:]. | 1594 * [includeSuperMembers] is [:true:]. |
1594 * | 1595 * |
1595 * When [includeBackendMembers] and [includeSuperMembers] are both [:true:] | 1596 * When [includeBackendMembers] and [includeSuperMembers] are both [:true:] |
1596 * then the fields are visited in the same order as they need to be given | 1597 * then the fields are visited in the same order as they need to be given |
1597 * to the JavaScript constructor. | 1598 * to the JavaScript constructor. |
1598 * | 1599 * |
1599 * When called on the implementation element both the fields declared in the | 1600 * When called on the implementation element both the fields declared in the |
1600 * origin and in the patch are included. | 1601 * origin and in the patch are included. |
1601 */ | 1602 */ |
1602 void forEachInstanceField([void f(ClassElement enclosingClass, Element field), | 1603 void forEachInstanceField(void f(ClassElement enclosingClass, Element field), |
1603 includeBackendMembers = false, | 1604 {includeBackendMembers: false, |
1604 includeSuperMembers = false]) { | 1605 includeSuperMembers: false}) { |
1605 // Filters so that [f] is only invoked with instance fields. | 1606 // Filters so that [f] is only invoked with instance fields. |
1606 void fieldFilter(ClassElement enclosingClass, Element member) { | 1607 void fieldFilter(ClassElement enclosingClass, Element member) { |
1607 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { | 1608 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { |
1608 f(enclosingClass, member); | 1609 f(enclosingClass, member); |
1609 } | 1610 } |
1610 } | 1611 } |
1611 | 1612 |
1612 forEachMember(fieldFilter, includeBackendMembers, includeSuperMembers); | 1613 forEachMember(fieldFilter, |
| 1614 includeBackendMembers: includeBackendMembers, |
| 1615 includeSuperMembers: includeSuperMembers); |
1613 } | 1616 } |
1614 | 1617 |
1615 bool implementsInterface(ClassElement intrface) { | 1618 bool implementsInterface(ClassElement intrface) { |
1616 for (DartType implementedInterfaceType in allSupertypes) { | 1619 for (DartType implementedInterfaceType in allSupertypes) { |
1617 ClassElement implementedInterface = implementedInterfaceType.element; | 1620 ClassElement implementedInterface = implementedInterfaceType.element; |
1618 if (implementedInterface === intrface) { | 1621 if (implementedInterface === intrface) { |
1619 return true; | 1622 return true; |
1620 } | 1623 } |
1621 } | 1624 } |
1622 return false; | 1625 return false; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1963 | 1966 |
1964 MetadataAnnotation ensureResolved(Compiler compiler) { | 1967 MetadataAnnotation ensureResolved(Compiler compiler) { |
1965 if (resolutionState == STATE_NOT_STARTED) { | 1968 if (resolutionState == STATE_NOT_STARTED) { |
1966 compiler.resolver.resolveMetadataAnnotation(this); | 1969 compiler.resolver.resolveMetadataAnnotation(this); |
1967 } | 1970 } |
1968 return this; | 1971 return this; |
1969 } | 1972 } |
1970 | 1973 |
1971 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1974 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
1972 } | 1975 } |
OLD | NEW |