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 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 class VariableElement extends Element { | 816 class VariableElement extends Element { |
817 final VariableListElement variables; | 817 final VariableListElement variables; |
818 Expression cachedNode; // The send or the identifier in the variables list. | 818 Expression cachedNode; // The send or the identifier in the variables list. |
819 | 819 |
820 Modifiers get modifiers => variables.modifiers; | 820 Modifiers get modifiers => variables.modifiers; |
821 | 821 |
822 VariableElement(SourceString name, | 822 VariableElement(SourceString name, |
823 VariableListElement this.variables, | 823 VariableListElement this.variables, |
824 ElementKind kind, | 824 ElementKind kind, |
825 Element enclosing, | 825 Element enclosing, |
826 [Node node]) | 826 {Node node}) |
827 : super(name, kind, enclosing), cachedNode = node; | 827 : super(name, kind, enclosing), cachedNode = node; |
828 | 828 |
829 Node parseNode(DiagnosticListener listener) { | 829 Node parseNode(DiagnosticListener listener) { |
830 if (cachedNode !== null) return cachedNode; | 830 if (cachedNode !== null) return cachedNode; |
831 VariableDefinitions definitions = variables.parseNode(listener); | 831 VariableDefinitions definitions = variables.parseNode(listener); |
832 for (Link<Node> link = definitions.definitions.nodes; | 832 for (Link<Node> link = definitions.definitions.nodes; |
833 !link.isEmpty(); link = link.tail) { | 833 !link.isEmpty(); link = link.tail) { |
834 Expression initializedIdentifier = link.head; | 834 Expression initializedIdentifier = link.head; |
835 Identifier identifier = initializedIdentifier.asIdentifier(); | 835 Identifier identifier = initializedIdentifier.asIdentifier(); |
836 if (identifier === null) { | 836 if (identifier === null) { |
(...skipping 25 matching lines...) Expand all Loading... | |
862 * [:A(this.field):]. | 862 * [:A(this.field):]. |
863 */ | 863 */ |
864 class FieldParameterElement extends VariableElement { | 864 class FieldParameterElement extends VariableElement { |
865 VariableElement fieldElement; | 865 VariableElement fieldElement; |
866 | 866 |
867 FieldParameterElement(SourceString name, | 867 FieldParameterElement(SourceString name, |
868 this.fieldElement, | 868 this.fieldElement, |
869 VariableListElement variables, | 869 VariableListElement variables, |
870 Element enclosing, | 870 Element enclosing, |
871 Node node) | 871 Node node) |
872 : super(name, variables, ElementKind.FIELD_PARAMETER, enclosing, node); | 872 : super(name, variables, ElementKind.FIELD_PARAMETER, enclosing, |
873 node: node); | |
873 } | 874 } |
874 | 875 |
875 // This element represents a list of variable or field declaration. | 876 // This element represents a list of variable or field declaration. |
876 // It contains the node, and the type. A [VariableElement] always | 877 // It contains the node, and the type. A [VariableElement] always |
877 // references its [VariableListElement]. It forwards its | 878 // references its [VariableListElement]. It forwards its |
878 // [computeType] and [parseNode] methods to this element. | 879 // [computeType] and [parseNode] methods to this element. |
879 class VariableListElement extends Element { | 880 class VariableListElement extends Element { |
880 VariableDefinitions cachedNode; | 881 VariableDefinitions cachedNode; |
881 DartType type; | 882 DartType type; |
882 final Modifiers modifiers; | 883 final Modifiers modifiers; |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1502 for (var element in localScope.getValues()) { | 1503 for (var element in localScope.getValues()) { |
1503 if (element.isConstructor()) return true; | 1504 if (element.isConstructor()) return true; |
1504 } | 1505 } |
1505 return false; | 1506 return false; |
1506 } | 1507 } |
1507 | 1508 |
1508 Link<Element> get constructors { | 1509 Link<Element> get constructors { |
1509 // TODO(ajohnsen): See if we can avoid this method at some point. | 1510 // TODO(ajohnsen): See if we can avoid this method at some point. |
1510 Link<Element> result = const EmptyLink<Element>(); | 1511 Link<Element> result = const EmptyLink<Element>(); |
1511 // TODO(johnniwinther): Should we include injected constructors? | 1512 // TODO(johnniwinther): Should we include injected constructors? |
1512 forEachMember((_, Element member) { | 1513 forEachMember(f: (_, Element member) { |
floitsch
2012/10/11 16:52:15
there seems to be a mismatch: here the function is
regis
2012/10/11 21:24:19
I guess I did not run this yet. Consistent now.
| |
1513 if (member.isConstructor()) result = result.prepend(member); | 1514 if (member.isConstructor()) result = result.prepend(member); |
1514 }); | 1515 }); |
1515 return result; | 1516 return result; |
1516 } | 1517 } |
1517 | 1518 |
1518 /** | 1519 /** |
1519 * Returns the super class, if any. | 1520 * Returns the super class, if any. |
1520 * | 1521 * |
1521 * The returned element may not be resolved yet. | 1522 * The returned element may not be resolved yet. |
1522 */ | 1523 */ |
1523 ClassElement get superclass { | 1524 ClassElement get superclass { |
1524 assert(supertypeLoadState == STATE_DONE); | 1525 assert(supertypeLoadState == STATE_DONE); |
1525 return supertype === null ? null : supertype.element; | 1526 return supertype === null ? null : supertype.element; |
1526 } | 1527 } |
1527 | 1528 |
1528 /** | 1529 /** |
1529 * Runs through all members of this class. | 1530 * Runs through all members of this class. |
1530 * | 1531 * |
1531 * The enclosing class is passed to the callback. This is useful when | 1532 * The enclosing class is passed to the callback. This is useful when |
1532 * [includeSuperMembers] is [:true:]. | 1533 * [includeSuperMembers] is [:true:]. |
1533 * | 1534 * |
1534 * When called on an implementation element both the members in the origin | 1535 * When called on an implementation element both the members in the origin |
1535 * and patch class are included. | 1536 * and patch class are included. |
1536 */ | 1537 */ |
1537 // TODO(johnniwinther): Clean up lookup to get rid of the include predicates. | 1538 // TODO(johnniwinther): Clean up lookup to get rid of the include predicates. |
1538 void forEachMember([void f(ClassElement enclosingClass, Element member), | 1539 void forEachMember(void f(ClassElement enclosingClass, Element member), |
floitsch
2012/10/11 16:52:15
I'm torn: the reason I made "f" optional was so th
regis
2012/10/11 21:24:19
Yes, I have changed it back and forth too, as show
| |
1539 includeBackendMembers = false, | 1540 {includeBackendMembers: false, |
1540 includeSuperMembers = false]) { | 1541 includeSuperMembers: false}) { |
1541 bool includeInjectedMembers = isPatch; | 1542 bool includeInjectedMembers = isPatch; |
1542 Set<ClassElement> seen = new Set<ClassElement>(); | 1543 Set<ClassElement> seen = new Set<ClassElement>(); |
1543 ClassElement classElement = declaration; | 1544 ClassElement classElement = declaration; |
1544 do { | 1545 do { |
1545 if (seen.contains(classElement)) return; | 1546 if (seen.contains(classElement)) return; |
1546 seen.add(classElement); | 1547 seen.add(classElement); |
1547 | 1548 |
1548 // Iterate through the members in textual order, which requires | 1549 // Iterate through the members in textual order, which requires |
1549 // to reverse the data structure [localMembers] we created. | 1550 // to reverse the data structure [localMembers] we created. |
1550 // Textual order may be important for certain operations, for | 1551 // Textual order may be important for certain operations, for |
(...skipping 25 matching lines...) Expand all Loading... | |
1576 * The enclosing class is passed to the callback. This is useful when | 1577 * The enclosing class is passed to the callback. This is useful when |
1577 * [includeSuperMembers] is [:true:]. | 1578 * [includeSuperMembers] is [:true:]. |
1578 * | 1579 * |
1579 * When [includeBackendMembers] and [includeSuperMembers] are both [:true:] | 1580 * When [includeBackendMembers] and [includeSuperMembers] are both [:true:] |
1580 * then the fields are visited in the same order as they need to be given | 1581 * then the fields are visited in the same order as they need to be given |
1581 * to the JavaScript constructor. | 1582 * to the JavaScript constructor. |
1582 * | 1583 * |
1583 * When called on the implementation element both the fields declared in the | 1584 * When called on the implementation element both the fields declared in the |
1584 * origin and in the patch are included. | 1585 * origin and in the patch are included. |
1585 */ | 1586 */ |
1586 void forEachInstanceField([void f(ClassElement enclosingClass, Element field), | 1587 void forEachInstanceField({void f(ClassElement enclosingClass, Element field), |
1587 includeBackendMembers = false, | 1588 includeBackendMembers: false, |
1588 includeSuperMembers = false]) { | 1589 includeSuperMembers: false}) { |
1589 // Filters so that [f] is only invoked with instance fields. | 1590 // Filters so that [f] is only invoked with instance fields. |
1590 void fieldFilter(ClassElement enclosingClass, Element member) { | 1591 void fieldFilter(ClassElement enclosingClass, Element member) { |
1591 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { | 1592 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { |
1592 f(enclosingClass, member); | 1593 f(enclosingClass, member); |
1593 } | 1594 } |
1594 } | 1595 } |
1595 | 1596 |
1596 forEachMember(fieldFilter, includeBackendMembers, includeSuperMembers); | 1597 forEachMember(fieldFilter, |
1598 includeBackendMembers: includeBackendMembers, | |
1599 includeSuperMembers: includeSuperMembers); | |
1597 } | 1600 } |
1598 | 1601 |
1599 bool implementsInterface(ClassElement intrface) { | 1602 bool implementsInterface(ClassElement intrface) { |
1600 for (DartType implementedInterfaceType in allSupertypes) { | 1603 for (DartType implementedInterfaceType in allSupertypes) { |
1601 ClassElement implementedInterface = implementedInterfaceType.element; | 1604 ClassElement implementedInterface = implementedInterfaceType.element; |
1602 if (implementedInterface === intrface) { | 1605 if (implementedInterface === intrface) { |
1603 return true; | 1606 return true; |
1604 } | 1607 } |
1605 } | 1608 } |
1606 return false; | 1609 return false; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1947 | 1950 |
1948 MetadataAnnotation ensureResolved(Compiler compiler) { | 1951 MetadataAnnotation ensureResolved(Compiler compiler) { |
1949 if (resolutionState == STATE_NOT_STARTED) { | 1952 if (resolutionState == STATE_NOT_STARTED) { |
1950 compiler.resolver.resolveMetadataAnnotation(this); | 1953 compiler.resolver.resolveMetadataAnnotation(this); |
1951 } | 1954 } |
1952 return this; | 1955 return this; |
1953 } | 1956 } |
1954 | 1957 |
1955 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1958 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
1956 } | 1959 } |
OLD | NEW |