Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 10917285: Stub implementation of patch invariants for the patch refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 abstract class TreeElements { 5 abstract class TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 DartType getType(TypeAnnotation annotation); 8 DartType getType(TypeAnnotation annotation);
9 bool isParameterChecked(Element element); 9 bool isParameterChecked(Element element);
10 } 10 }
11 11
12 class TreeElementMapping implements TreeElements { 12 class TreeElementMapping implements TreeElements {
13 final Element currentElement;
13 final Map<Node, Element> map; 14 final Map<Node, Element> map;
14 final Map<Node, Selector> selectors; 15 final Map<Node, Selector> selectors;
15 final Map<TypeAnnotation, DartType> types; 16 final Map<TypeAnnotation, DartType> types;
16 final Set<Element> checkedParameters; 17 final Set<Element> checkedParameters;
17 18
18 TreeElementMapping() 19 TreeElementMapping([Element this.currentElement])
19 : map = new LinkedHashMap<Node, Element>(), 20 : map = new LinkedHashMap<Node, Element>(),
20 selectors = new LinkedHashMap<Node, Selector>(), 21 selectors = new LinkedHashMap<Node, Selector>(),
21 types = new LinkedHashMap<TypeAnnotation, DartType>(), 22 types = new LinkedHashMap<TypeAnnotation, DartType>(),
22 checkedParameters = new Set<Element>(); 23 checkedParameters = new Set<Element>();
23 24
24 operator []=(Node node, Element element) => map[node] = element; 25 operator []=(Node node, Element element) {
26 assert(invariant(node, () {
27 if (node is FunctionExpression && node.modifiers != null) {
28 return !node.modifiers.isExternal();
29 }
30 return true;
31 }));
32 assert(invariant(node, () {
33 if (!element.isErroneous() && currentElement != null && element.isPatch) {
34 return currentElement.getImplementationLibrary().isPatch;
35 }
36 return true;
37 }));
38
39 map[node] = element;
40 }
25 operator [](Node node) => map[node]; 41 operator [](Node node) => map[node];
26 void remove(Node node) { map.remove(node); } 42 void remove(Node node) { map.remove(node); }
27 43
28 void setType(TypeAnnotation annotation, DartType type) { 44 void setType(TypeAnnotation annotation, DartType type) {
29 types[annotation] = type; 45 types[annotation] = type;
30 } 46 }
31 47
32 DartType getType(TypeAnnotation annotation) => types[annotation]; 48 DartType getType(TypeAnnotation annotation) => types[annotation];
33 49
34 void setSelector(Node node, Selector selector) { 50 void setSelector(Node node, Selector selector) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (seen.contains(redirection)) { 120 if (seen.contains(redirection)) {
105 resolver.visitor.error(node, MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE); 121 resolver.visitor.error(node, MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE);
106 return; 122 return;
107 } 123 }
108 seen.add(redirection); 124 seen.add(redirection);
109 redirection = resolveConstructorRedirection(redirection); 125 redirection = resolveConstructorRedirection(redirection);
110 } 126 }
111 } 127 }
112 128
113 TreeElements resolveMethodElement(FunctionElement element) { 129 TreeElements resolveMethodElement(FunctionElement element) {
130 assert(invariant(element, element.isDeclaration));
114 return compiler.withCurrentElement(element, () { 131 return compiler.withCurrentElement(element, () {
115 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; 132 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR;
116 TreeElements elements = 133 TreeElements elements =
117 compiler.enqueuer.resolution.getCachedElements(element); 134 compiler.enqueuer.resolution.getCachedElements(element);
118 if (elements !== null) { 135 if (elements !== null) {
119 assert(isConstructor); 136 assert(isConstructor);
120 return elements; 137 return elements;
121 } 138 }
122 FunctionExpression tree = element.parseNode(compiler); 139 FunctionExpression tree = element.parseNode(compiler);
123 if (isConstructor) { 140 if (isConstructor) {
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 bool inInstanceContext; 983 bool inInstanceContext;
967 bool inCheckContext; 984 bool inCheckContext;
968 Scope scope; 985 Scope scope;
969 ClassElement currentClass; 986 ClassElement currentClass;
970 ExpressionStatement currentExpressionStatement; 987 ExpressionStatement currentExpressionStatement;
971 bool typeRequired = false; 988 bool typeRequired = false;
972 StatementScope statementScope; 989 StatementScope statementScope;
973 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION; 990 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION;
974 991
975 ResolverVisitor(Compiler compiler, Element element) 992 ResolverVisitor(Compiler compiler, Element element)
976 : this.mapping = new TreeElementMapping(), 993 : this.mapping = new TreeElementMapping(element),
977 this.enclosingElement = element, 994 this.enclosingElement = element,
978 // When the element is a field, we are actually resolving its 995 // When the element is a field, we are actually resolving its
979 // initial value, which should not have access to instance 996 // initial value, which should not have access to instance
980 // fields. 997 // fields.
981 inInstanceContext = (element.isInstanceMember() && !element.isField()) 998 inInstanceContext = (element.isInstanceMember() && !element.isField())
982 || element.isGenerativeConstructor(), 999 || element.isGenerativeConstructor(),
983 this.currentClass = element.isMember() ? element.getEnclosingClass() 1000 this.currentClass = element.isMember() ? element.getEnclosingClass()
984 : null, 1001 : null,
985 this.statementScope = new StatementScope(), 1002 this.statementScope = new StatementScope(),
986 typeResolver = new TypeResolver(compiler), 1003 typeResolver = new TypeResolver(compiler),
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 if (selector.isGetter()) { 1554 if (selector.isGetter()) {
1538 world.registerDynamicGetter(selector.name, selector); 1555 world.registerDynamicGetter(selector.name, selector);
1539 } else if (selector.isSetter()) { 1556 } else if (selector.isSetter()) {
1540 world.registerDynamicSetter(selector.name, selector); 1557 world.registerDynamicSetter(selector.name, selector);
1541 } else { 1558 } else {
1542 world.registerDynamicInvocation(selector.name, selector); 1559 world.registerDynamicInvocation(selector.name, selector);
1543 } 1560 }
1544 } else if (Elements.isStaticOrTopLevel(target)) { 1561 } else if (Elements.isStaticOrTopLevel(target)) {
1545 // TODO(kasperl): It seems like we're not supposed to register 1562 // TODO(kasperl): It seems like we're not supposed to register
1546 // the use of classes. Wouldn't it be simpler if we just did? 1563 // the use of classes. Wouldn't it be simpler if we just did?
1547 if (!target.isClass()) world.registerStaticUse(target); 1564 if (!target.isClass()) {
1565 // [target] might be the implementation element and only declaration
1566 // elements may be registered.
1567 world.registerStaticUse(target.declaration);
1568 }
1548 } 1569 }
1549 1570
1550 var interceptor = 1571 var interceptor =
1551 new Interceptors(compiler).getStaticInterceptorBySelector(selector); 1572 new Interceptors(compiler).getStaticInterceptorBySelector(selector);
1552 if (interceptor !== null) { 1573 if (interceptor !== null) {
1553 world.registerStaticUse(interceptor); 1574 world.registerStaticUse(interceptor);
1554 } 1575 }
1555 } 1576 }
1556 1577
1557 visitLiteralInt(LiteralInt node) { 1578 visitLiteralInt(LiteralInt node) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 resolveSelector(node.send); 1635 resolveSelector(node.send);
1615 resolveArguments(node.send.argumentsNode); 1636 resolveArguments(node.send.argumentsNode);
1616 useElement(node.send, constructor); 1637 useElement(node.send, constructor);
1617 if (Elements.isUnresolved(constructor)) return constructor; 1638 if (Elements.isUnresolved(constructor)) return constructor;
1618 // TODO(karlklose): handle optional arguments. 1639 // TODO(karlklose): handle optional arguments.
1619 if (node.send.argumentCount() != constructor.parameterCount(compiler)) { 1640 if (node.send.argumentCount() != constructor.parameterCount(compiler)) {
1620 // TODO(ngeoffray): resolution error with wrong number of 1641 // TODO(ngeoffray): resolution error with wrong number of
1621 // parameters. We cannot do this rigth now because of the 1642 // parameters. We cannot do this rigth now because of the
1622 // List constructor. 1643 // List constructor.
1623 } 1644 }
1624 world.registerStaticUse(constructor); 1645 // [constructor] might be the implementation element and only declaration
1646 // elements may be registered.
1647 world.registerStaticUse(constructor.declaration);
1625 compiler.withCurrentElement(constructor, () { 1648 compiler.withCurrentElement(constructor, () {
1626 FunctionExpression tree = constructor.parseNode(compiler); 1649 FunctionExpression tree = constructor.parseNode(compiler);
1627 compiler.resolver.resolveConstructorImplementation(constructor, tree); 1650 compiler.resolver.resolveConstructorImplementation(constructor, tree);
1628 }); 1651 });
1629 world.registerStaticUse(constructor.defaultImplementation); 1652 // [constructor.defaultImplementation] might be the implementation element
1653 // and only declaration elements may be registered.
1654 world.registerStaticUse(constructor.defaultImplementation.declaration);
1630 ClassElement cls = constructor.defaultImplementation.getEnclosingClass(); 1655 ClassElement cls = constructor.defaultImplementation.getEnclosingClass();
1631 world.registerInstantiatedClass(cls); 1656 // [cls] might be the implementation element and only declaration elements
1657 // may be registered.
1658 world.registerInstantiatedClass(cls.declaration);
1632 cls.forEachInstanceField( 1659 cls.forEachInstanceField(
1633 includeBackendMembers: false, 1660 includeBackendMembers: false,
1634 includeSuperMembers: true, 1661 includeSuperMembers: true,
1635 f: (ClassElement enclosingClass, Element member) { 1662 f: (ClassElement enclosingClass, Element member) {
1636 world.addToWorkList(member); 1663 world.addToWorkList(member);
1637 }); 1664 });
1638 return null; 1665 return null;
1639 } 1666 }
1640 1667
1641 /** 1668 /**
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 abstract Element localLookup(SourceString name); 2732 abstract Element localLookup(SourceString name);
2706 } 2733 }
2707 2734
2708 class VariableScope extends Scope { 2735 class VariableScope extends Scope {
2709 VariableScope(parent, element) : super(parent, element); 2736 VariableScope(parent, element) : super(parent, element);
2710 2737
2711 Element add(Element newElement) { 2738 Element add(Element newElement) {
2712 throw "Cannot add element to VariableScope"; 2739 throw "Cannot add element to VariableScope";
2713 } 2740 }
2714 2741
2715 Element lookup(SourceString name) => parent.lookup(name); 2742 Element localLookup(SourceString name) => null;
2716 2743
2717 String toString() => '$element > $parent'; 2744 String toString() => '$element > $parent';
2718 } 2745 }
2719 2746
2720 /** 2747 /**
2721 * [TypeDeclarationScope] defines the outer scope of a type declaration in 2748 * [TypeDeclarationScope] defines the outer scope of a type declaration in
2722 * which the declared type variables and the entities in the enclosing scope are 2749 * which the declared type variables and the entities in the enclosing scope are
2723 * available but where declared and inherited members are not available. This 2750 * available but where declared and inherited members are not available. This
2724 * scope is only used for class/interface declarations during resolution of the 2751 * scope is only used for class/interface declarations during resolution of the
2725 * class hierarchy. In all other cases [ClassScope] is used. 2752 * class hierarchy. In all other cases [ClassScope] is used.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2825 2852
2826 Element localLookup(SourceString name) => library.find(name); 2853 Element localLookup(SourceString name) => library.find(name);
2827 Element lookup(SourceString name) => localLookup(name); 2854 Element lookup(SourceString name) => localLookup(name);
2828 Element lexicalLookup(SourceString name) => localLookup(name); 2855 Element lexicalLookup(SourceString name) => localLookup(name);
2829 2856
2830 Element add(Element newElement) { 2857 Element add(Element newElement) {
2831 throw "Cannot add an element in the top scope"; 2858 throw "Cannot add an element in the top scope";
2832 } 2859 }
2833 String toString() => '$element'; 2860 String toString() => '$element';
2834 } 2861 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/patch_parser.dart ('k') | lib/compiler/implementation/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698