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

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: Leftovers from rebase. 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 element])
ngeoffray 2012/09/17 12:46:24 Could you not make it optional? Also you can write
Johnni Winther 2012/09/20 08:12:23 Several call-sites uses optionality.
19 : map = new LinkedHashMap<Node, Element>(), 20 : currentElement = element,
21 map = new LinkedHashMap<Node, Element>(),
20 selectors = new LinkedHashMap<Node, Selector>(), 22 selectors = new LinkedHashMap<Node, Selector>(),
21 types = new LinkedHashMap<TypeAnnotation, DartType>(), 23 types = new LinkedHashMap<TypeAnnotation, DartType>(),
22 checkedParameters = new Set<Element>(); 24 checkedParameters = new Set<Element>();
23 25
24 operator []=(Node node, Element element) => map[node] = element; 26 operator []=(Node node, Element element) {
27 if (node is FunctionExpression && node.modifiers != null) {
ngeoffray 2012/09/17 12:46:24 Put this 'if' in the assert.
Johnni Winther 2012/09/20 08:12:23 Done.
28 assert (!node.modifiers.isExternal());
29 }
30 if (!element.isErroneous() && currentElement != null && element.isPatch) {
ngeoffray 2012/09/17 12:46:24 ditto.
Johnni Winther 2012/09/20 08:12:23 Done.
31 assert(currentElement.getImplementationLibrary().isPatch);
32 }
33
34 map[node] = element;
35 }
25 operator [](Node node) => map[node]; 36 operator [](Node node) => map[node];
26 void remove(Node node) { map.remove(node); } 37 void remove(Node node) { map.remove(node); }
27 38
28 void setType(TypeAnnotation annotation, DartType type) { 39 void setType(TypeAnnotation annotation, DartType type) {
29 types[annotation] = type; 40 types[annotation] = type;
30 } 41 }
31 42
32 DartType getType(TypeAnnotation annotation) => types[annotation]; 43 DartType getType(TypeAnnotation annotation) => types[annotation];
33 44
34 void setSelector(Node node, Selector selector) { 45 void setSelector(Node node, Selector selector) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (seen.contains(redirection)) { 115 if (seen.contains(redirection)) {
105 resolver.visitor.error(node, MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE); 116 resolver.visitor.error(node, MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE);
106 return; 117 return;
107 } 118 }
108 seen.add(redirection); 119 seen.add(redirection);
109 redirection = resolveConstructorRedirection(redirection); 120 redirection = resolveConstructorRedirection(redirection);
110 } 121 }
111 } 122 }
112 123
113 TreeElements resolveMethodElement(FunctionElement element) { 124 TreeElements resolveMethodElement(FunctionElement element) {
125 assert(element.isDeclaration);
114 return compiler.withCurrentElement(element, () { 126 return compiler.withCurrentElement(element, () {
115 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; 127 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR;
116 TreeElements elements = 128 TreeElements elements =
117 compiler.enqueuer.resolution.getCachedElements(element); 129 compiler.enqueuer.resolution.getCachedElements(element);
118 if (elements !== null) { 130 if (elements !== null) {
119 assert(isConstructor); 131 assert(isConstructor);
120 return elements; 132 return elements;
121 } 133 }
122 FunctionExpression tree = element.parseNode(compiler); 134 FunctionExpression tree = element.parseNode(compiler);
123 if (isConstructor) { 135 if (isConstructor) {
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 bool inInstanceContext; 970 bool inInstanceContext;
959 bool inCheckContext; 971 bool inCheckContext;
960 Scope scope; 972 Scope scope;
961 ClassElement currentClass; 973 ClassElement currentClass;
962 ExpressionStatement currentExpressionStatement; 974 ExpressionStatement currentExpressionStatement;
963 bool typeRequired = false; 975 bool typeRequired = false;
964 StatementScope statementScope; 976 StatementScope statementScope;
965 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION; 977 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION;
966 978
967 ResolverVisitor(Compiler compiler, Element element) 979 ResolverVisitor(Compiler compiler, Element element)
968 : this.mapping = new TreeElementMapping(), 980 : this.mapping = new TreeElementMapping(element),
969 this.enclosingElement = element, 981 this.enclosingElement = element,
970 // When the element is a field, we are actually resolving its 982 // When the element is a field, we are actually resolving its
971 // initial value, which should not have access to instance 983 // initial value, which should not have access to instance
972 // fields. 984 // fields.
973 inInstanceContext = (element.isInstanceMember() && !element.isField()) 985 inInstanceContext = (element.isInstanceMember() && !element.isField())
974 || element.isGenerativeConstructor(), 986 || element.isGenerativeConstructor(),
975 this.currentClass = element.isMember() ? element.getEnclosingClass() 987 this.currentClass = element.isMember() ? element.getEnclosingClass()
976 : null, 988 : null,
977 this.statementScope = new StatementScope(), 989 this.statementScope = new StatementScope(),
978 typeResolver = new TypeResolver(compiler), 990 typeResolver = new TypeResolver(compiler),
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 if (selector.isGetter()) { 1525 if (selector.isGetter()) {
1514 world.registerDynamicGetter(selector.name, selector); 1526 world.registerDynamicGetter(selector.name, selector);
1515 } else if (selector.isSetter()) { 1527 } else if (selector.isSetter()) {
1516 world.registerDynamicSetter(selector.name, selector); 1528 world.registerDynamicSetter(selector.name, selector);
1517 } else { 1529 } else {
1518 world.registerDynamicInvocation(selector.name, selector); 1530 world.registerDynamicInvocation(selector.name, selector);
1519 } 1531 }
1520 } else if (Elements.isStaticOrTopLevel(target)) { 1532 } else if (Elements.isStaticOrTopLevel(target)) {
1521 // TODO(kasperl): It seems like we're not supposed to register 1533 // TODO(kasperl): It seems like we're not supposed to register
1522 // the use of classes. Wouldn't it be simpler if we just did? 1534 // the use of classes. Wouldn't it be simpler if we just did?
1523 if (!target.isClass()) world.registerStaticUse(target); 1535 if (!target.isClass()) world.registerStaticUse(target.declaration);
1524 } 1536 }
1525 1537
1526 // TODO(kasperl): Pass the selector directly. 1538 // TODO(kasperl): Pass the selector directly.
1527 var interceptor = new Interceptors(compiler).getStaticInterceptor( 1539 var interceptor = new Interceptors(compiler).getStaticInterceptor(
1528 selector.name, 1540 selector.name,
1529 selector.argumentCount); 1541 selector.argumentCount);
1530 if (interceptor !== null) { 1542 if (interceptor !== null) {
1531 world.registerStaticUse(interceptor); 1543 world.registerStaticUse(interceptor);
1532 } 1544 }
1533 } 1545 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 resolveSelector(node.send); 1604 resolveSelector(node.send);
1593 resolveArguments(node.send.argumentsNode); 1605 resolveArguments(node.send.argumentsNode);
1594 useElement(node.send, constructor); 1606 useElement(node.send, constructor);
1595 if (Elements.isUnresolved(constructor)) return constructor; 1607 if (Elements.isUnresolved(constructor)) return constructor;
1596 // TODO(karlklose): handle optional arguments. 1608 // TODO(karlklose): handle optional arguments.
1597 if (node.send.argumentCount() != constructor.parameterCount(compiler)) { 1609 if (node.send.argumentCount() != constructor.parameterCount(compiler)) {
1598 // TODO(ngeoffray): resolution error with wrong number of 1610 // TODO(ngeoffray): resolution error with wrong number of
1599 // parameters. We cannot do this rigth now because of the 1611 // parameters. We cannot do this rigth now because of the
1600 // List constructor. 1612 // List constructor.
1601 } 1613 }
1602 world.registerStaticUse(constructor); 1614 world.registerStaticUse(constructor.declaration);
1603 compiler.withCurrentElement(constructor, () { 1615 compiler.withCurrentElement(constructor, () {
1604 FunctionExpression tree = constructor.parseNode(compiler); 1616 FunctionExpression tree = constructor.parseNode(compiler);
1605 compiler.resolver.resolveConstructorImplementation(constructor, tree); 1617 compiler.resolver.resolveConstructorImplementation(constructor, tree);
1606 }); 1618 });
1607 world.registerStaticUse(constructor.defaultImplementation); 1619 world.registerStaticUse(constructor.defaultImplementation.declaration);
1608 ClassElement cls = constructor.defaultImplementation.getEnclosingClass(); 1620 ClassElement cls = constructor.defaultImplementation.getEnclosingClass();
1609 world.registerInstantiatedClass(cls); 1621 world.registerInstantiatedClass(cls.declaration);
1610 cls.forEachInstanceField( 1622 cls.forEachInstanceField(
1611 includeBackendMembers: false, 1623 includeBackendMembers: false,
1612 includeSuperMembers: true, 1624 includeSuperMembers: true,
1613 f: (ClassElement enclosingClass, Element member) { 1625 f: (ClassElement enclosingClass, Element member) {
1614 world.addToWorkList(member); 1626 world.addToWorkList(member);
1615 }); 1627 });
1616 return null; 1628 return null;
1617 } 1629 }
1618 1630
1619 /** 1631 /**
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
2643 abstract Element localLookup(SourceString name); 2655 abstract Element localLookup(SourceString name);
2644 } 2656 }
2645 2657
2646 class VariableScope extends Scope { 2658 class VariableScope extends Scope {
2647 VariableScope(parent, element) : super(parent, element); 2659 VariableScope(parent, element) : super(parent, element);
2648 2660
2649 Element add(Element newElement) { 2661 Element add(Element newElement) {
2650 throw "Cannot add element to VariableScope"; 2662 throw "Cannot add element to VariableScope";
2651 } 2663 }
2652 2664
2653 Element lookup(SourceString name) => parent.lookup(name); 2665 Element localLookup(SourceString name) => null;
2654 2666
2655 String toString() => '$element > $parent'; 2667 String toString() => '$element > $parent';
2656 } 2668 }
2657 2669
2658 /** 2670 /**
2659 * [TypeDeclarationScope] defines the outer scope of a type declaration in 2671 * [TypeDeclarationScope] defines the outer scope of a type declaration in
2660 * which the declared type variables and the entities in the enclosing scope are 2672 * which the declared type variables and the entities in the enclosing scope are
2661 * available but where declared and inherited members are not available. This 2673 * available but where declared and inherited members are not available. This
2662 * scope is only used for class/interface declarations during resolution of the 2674 * scope is only used for class/interface declarations during resolution of the
2663 * class hierarchy. In all other cases [ClassScope] is used. 2675 * class hierarchy. In all other cases [ClassScope] is used.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 2775
2764 Element localLookup(SourceString name) => library.find(name); 2776 Element localLookup(SourceString name) => library.find(name);
2765 Element lookup(SourceString name) => localLookup(name); 2777 Element lookup(SourceString name) => localLookup(name);
2766 Element lexicalLookup(SourceString name) => localLookup(name); 2778 Element lexicalLookup(SourceString name) => localLookup(name);
2767 2779
2768 Element add(Element newElement) { 2780 Element add(Element newElement) {
2769 throw "Cannot add an element in the top scope"; 2781 throw "Cannot add an element in the top scope";
2770 } 2782 }
2771 String toString() => '$element'; 2783 String toString() => '$element';
2772 } 2784 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698