| 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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 /** | 1527 /** |
| 1527 * Runs through all members of this class. | 1528 * Runs through all members of this class. |
| 1528 * | 1529 * |
| 1529 * The enclosing class is passed to the callback. This is useful when | 1530 * The enclosing class is passed to the callback. This is useful when |
| 1530 * [includeSuperMembers] is [:true:]. | 1531 * [includeSuperMembers] is [:true:]. |
| 1531 * | 1532 * |
| 1532 * When called on an implementation element both the members in the origin | 1533 * When called on an implementation element both the members in the origin |
| 1533 * and patch class are included. | 1534 * and patch class are included. |
| 1534 */ | 1535 */ |
| 1535 // TODO(johnniwinther): Clean up lookup to get rid of the include predicates. | 1536 // TODO(johnniwinther): Clean up lookup to get rid of the include predicates. |
| 1536 void forEachMember([void f(ClassElement enclosingClass, Element member), | 1537 void forEachMember(void f(ClassElement enclosingClass, Element member), |
| 1537 includeBackendMembers = false, | 1538 {includeBackendMembers: false, |
| 1538 includeSuperMembers = false]) { | 1539 includeSuperMembers: false}) { |
| 1539 bool includeInjectedMembers = isPatch; | 1540 bool includeInjectedMembers = isPatch; |
| 1540 Set<ClassElement> seen = new Set<ClassElement>(); | 1541 Set<ClassElement> seen = new Set<ClassElement>(); |
| 1541 ClassElement classElement = declaration; | 1542 ClassElement classElement = declaration; |
| 1542 do { | 1543 do { |
| 1543 if (seen.contains(classElement)) return; | 1544 if (seen.contains(classElement)) return; |
| 1544 seen.add(classElement); | 1545 seen.add(classElement); |
| 1545 | 1546 |
| 1546 // Iterate through the members in textual order, which requires | 1547 // Iterate through the members in textual order, which requires |
| 1547 // to reverse the data structure [localMembers] we created. | 1548 // to reverse the data structure [localMembers] we created. |
| 1548 // Textual order may be important for certain operations, for | 1549 // Textual order may be important for certain operations, for |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1574 * The enclosing class is passed to the callback. This is useful when | 1575 * The enclosing class is passed to the callback. This is useful when |
| 1575 * [includeSuperMembers] is [:true:]. | 1576 * [includeSuperMembers] is [:true:]. |
| 1576 * | 1577 * |
| 1577 * When [includeBackendMembers] and [includeSuperMembers] are both [:true:] | 1578 * When [includeBackendMembers] and [includeSuperMembers] are both [:true:] |
| 1578 * then the fields are visited in the same order as they need to be given | 1579 * then the fields are visited in the same order as they need to be given |
| 1579 * to the JavaScript constructor. | 1580 * to the JavaScript constructor. |
| 1580 * | 1581 * |
| 1581 * When called on the implementation element both the fields declared in the | 1582 * When called on the implementation element both the fields declared in the |
| 1582 * origin and in the patch are included. | 1583 * origin and in the patch are included. |
| 1583 */ | 1584 */ |
| 1584 void forEachInstanceField([void f(ClassElement enclosingClass, Element field), | 1585 void forEachInstanceField(void f(ClassElement enclosingClass, Element field), |
| 1585 includeBackendMembers = false, | 1586 {includeBackendMembers: false, |
| 1586 includeSuperMembers = false]) { | 1587 includeSuperMembers: false}) { |
| 1587 // Filters so that [f] is only invoked with instance fields. | 1588 // Filters so that [f] is only invoked with instance fields. |
| 1588 void fieldFilter(ClassElement enclosingClass, Element member) { | 1589 void fieldFilter(ClassElement enclosingClass, Element member) { |
| 1589 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { | 1590 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { |
| 1590 f(enclosingClass, member); | 1591 f(enclosingClass, member); |
| 1591 } | 1592 } |
| 1592 } | 1593 } |
| 1593 | 1594 |
| 1594 forEachMember(fieldFilter, includeBackendMembers, includeSuperMembers); | 1595 forEachMember(fieldFilter, |
| 1596 includeBackendMembers: includeBackendMembers, |
| 1597 includeSuperMembers: includeSuperMembers); |
| 1595 } | 1598 } |
| 1596 | 1599 |
| 1597 bool implementsInterface(ClassElement intrface) { | 1600 bool implementsInterface(ClassElement intrface) { |
| 1598 for (DartType implementedInterfaceType in allSupertypes) { | 1601 for (DartType implementedInterfaceType in allSupertypes) { |
| 1599 ClassElement implementedInterface = implementedInterfaceType.element; | 1602 ClassElement implementedInterface = implementedInterfaceType.element; |
| 1600 if (implementedInterface === intrface) { | 1603 if (implementedInterface === intrface) { |
| 1601 return true; | 1604 return true; |
| 1602 } | 1605 } |
| 1603 } | 1606 } |
| 1604 return false; | 1607 return false; |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1945 | 1948 |
| 1946 MetadataAnnotation ensureResolved(Compiler compiler) { | 1949 MetadataAnnotation ensureResolved(Compiler compiler) { |
| 1947 if (resolutionState == STATE_NOT_STARTED) { | 1950 if (resolutionState == STATE_NOT_STARTED) { |
| 1948 compiler.resolver.resolveMetadataAnnotation(this); | 1951 compiler.resolver.resolveMetadataAnnotation(this); |
| 1949 } | 1952 } |
| 1950 return this; | 1953 return this; |
| 1951 } | 1954 } |
| 1952 | 1955 |
| 1953 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1956 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
| 1954 } | 1957 } |
| OLD | NEW |