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

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, () {
ahe 2012/09/20 11:12:07 How about allowing function arguments in invariant
Johnni Winther 2012/09/21 09:18:25 Done.
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()) world.registerStaticUse(target.declaration);
ahe 2012/09/20 11:12:07 Why is this necessary?
Johnni Winther 2012/09/21 09:18:25 [target] might be the implementation element and o
ahe 2012/09/21 09:26:42 Why might it be the implementation element?
Johnni Winther 2012/09/21 10:08:13 If we are in a patch library, target might resolve
ahe 2012/09/21 12:11:31 Why?
Johnni Winther 2012/09/21 12:20:14 Because the patch scope (the scope created within
ahe 2012/09/21 12:21:22 Why?
ahe 2012/09/21 12:58:09 We discussed this offline. Seems that our invaria
1548 } 1565 }
1549 1566
1550 var interceptor = 1567 var interceptor =
1551 new Interceptors(compiler).getStaticInterceptorBySelector(selector); 1568 new Interceptors(compiler).getStaticInterceptorBySelector(selector);
1552 if (interceptor !== null) { 1569 if (interceptor !== null) {
1553 world.registerStaticUse(interceptor); 1570 world.registerStaticUse(interceptor);
1554 } 1571 }
1555 } 1572 }
1556 1573
1557 visitLiteralInt(LiteralInt node) { 1574 visitLiteralInt(LiteralInt node) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 resolveSelector(node.send); 1631 resolveSelector(node.send);
1615 resolveArguments(node.send.argumentsNode); 1632 resolveArguments(node.send.argumentsNode);
1616 useElement(node.send, constructor); 1633 useElement(node.send, constructor);
1617 if (Elements.isUnresolved(constructor)) return constructor; 1634 if (Elements.isUnresolved(constructor)) return constructor;
1618 // TODO(karlklose): handle optional arguments. 1635 // TODO(karlklose): handle optional arguments.
1619 if (node.send.argumentCount() != constructor.parameterCount(compiler)) { 1636 if (node.send.argumentCount() != constructor.parameterCount(compiler)) {
1620 // TODO(ngeoffray): resolution error with wrong number of 1637 // TODO(ngeoffray): resolution error with wrong number of
1621 // parameters. We cannot do this rigth now because of the 1638 // parameters. We cannot do this rigth now because of the
1622 // List constructor. 1639 // List constructor.
1623 } 1640 }
1624 world.registerStaticUse(constructor); 1641 world.registerStaticUse(constructor.declaration);
ahe 2012/09/20 11:12:07 Why?
Johnni Winther 2012/09/21 09:18:25 Same reason as before: [constructor] might be an i
1625 compiler.withCurrentElement(constructor, () { 1642 compiler.withCurrentElement(constructor, () {
1626 FunctionExpression tree = constructor.parseNode(compiler); 1643 FunctionExpression tree = constructor.parseNode(compiler);
1627 compiler.resolver.resolveConstructorImplementation(constructor, tree); 1644 compiler.resolver.resolveConstructorImplementation(constructor, tree);
1628 }); 1645 });
1629 world.registerStaticUse(constructor.defaultImplementation); 1646 world.registerStaticUse(constructor.defaultImplementation.declaration);
1630 ClassElement cls = constructor.defaultImplementation.getEnclosingClass(); 1647 ClassElement cls = constructor.defaultImplementation.getEnclosingClass();
1631 world.registerInstantiatedClass(cls); 1648 world.registerInstantiatedClass(cls.declaration);
1632 cls.forEachInstanceField( 1649 cls.forEachInstanceField(
1633 includeBackendMembers: false, 1650 includeBackendMembers: false,
1634 includeSuperMembers: true, 1651 includeSuperMembers: true,
1635 f: (ClassElement enclosingClass, Element member) { 1652 f: (ClassElement enclosingClass, Element member) {
1636 world.addToWorkList(member); 1653 world.addToWorkList(member);
1637 }); 1654 });
1638 return null; 1655 return null;
1639 } 1656 }
1640 1657
1641 /** 1658 /**
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 abstract Element localLookup(SourceString name); 2722 abstract Element localLookup(SourceString name);
2706 } 2723 }
2707 2724
2708 class VariableScope extends Scope { 2725 class VariableScope extends Scope {
2709 VariableScope(parent, element) : super(parent, element); 2726 VariableScope(parent, element) : super(parent, element);
2710 2727
2711 Element add(Element newElement) { 2728 Element add(Element newElement) {
2712 throw "Cannot add element to VariableScope"; 2729 throw "Cannot add element to VariableScope";
2713 } 2730 }
2714 2731
2715 Element lookup(SourceString name) => parent.lookup(name); 2732 Element localLookup(SourceString name) => null;
ahe 2012/09/20 11:12:07 I don't understand this change.
Johnni Winther 2012/09/21 09:18:25 [lookup] is defined in [Scope] to call [:parent.lo
2716 2733
2717 String toString() => '$element > $parent'; 2734 String toString() => '$element > $parent';
2718 } 2735 }
2719 2736
2720 /** 2737 /**
2721 * [TypeDeclarationScope] defines the outer scope of a type declaration in 2738 * [TypeDeclarationScope] defines the outer scope of a type declaration in
2722 * which the declared type variables and the entities in the enclosing scope are 2739 * 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 2740 * available but where declared and inherited members are not available. This
2724 * scope is only used for class/interface declarations during resolution of the 2741 * scope is only used for class/interface declarations during resolution of the
2725 * class hierarchy. In all other cases [ClassScope] is used. 2742 * class hierarchy. In all other cases [ClassScope] is used.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2825 2842
2826 Element localLookup(SourceString name) => library.find(name); 2843 Element localLookup(SourceString name) => library.find(name);
2827 Element lookup(SourceString name) => localLookup(name); 2844 Element lookup(SourceString name) => localLookup(name);
2828 Element lexicalLookup(SourceString name) => localLookup(name); 2845 Element lexicalLookup(SourceString name) => localLookup(name);
2829 2846
2830 Element add(Element newElement) { 2847 Element add(Element newElement) {
2831 throw "Cannot add an element in the top scope"; 2848 throw "Cannot add an element in the top scope";
2832 } 2849 }
2833 String toString() => '$element'; 2850 String toString() => '$element';
2834 } 2851 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698