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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 13866010: Correctly compile unresolved for-in loops. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added unit test Created 7 years, 8 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 part of resolution; 5 part of resolution;
6 6
7 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Set<Node> get superUses; 9 Set<Node> get superUses;
10 10
11 /// A set of additional dependencies. See [registerDependency] below. 11 /// A set of additional dependencies. See [registerDependency] below.
12 Set<Element> get otherDependencies; 12 Set<Element> get otherDependencies;
13 13
14 Element operator[](Node node); 14 Element operator[](Node node);
15 Selector getSelector(Send send); 15 Selector getSelector(Send send);
16 Selector getGetterSelectorInComplexSendSet(SendSet node); 16 Selector getGetterSelectorInComplexSendSet(SendSet node);
17 Selector getOperatorSelectorInComplexSendSet(SendSet node); 17 Selector getOperatorSelectorInComplexSendSet(SendSet node);
18 Selector getIteratorSelector(ForIn node);
19 Selector getMoveNextSelector(ForIn node);
20 Selector getCurrentSelector(ForIn node);
21 DartType getType(Node node); 18 DartType getType(Node node);
22 bool isParameterChecked(Element element); 19 bool isParameterChecked(Element element);
23 20
24 /// Register additional dependencies required by [currentElement]. 21 /// Register additional dependencies required by [currentElement].
25 /// For example, elements that are used by a backend. 22 /// For example, elements that are used by a backend.
26 void registerDependency(Element element); 23 void registerDependency(Element element);
27 } 24 }
28 25
29 class TreeElementMapping implements TreeElements { 26 class TreeElementMapping implements TreeElements {
30 final Element currentElement; 27 final Element currentElement;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 89 }
93 90
94 void setOperatorSelectorInComplexSendSet(SendSet node, Selector selector) { 91 void setOperatorSelectorInComplexSendSet(SendSet node, Selector selector) {
95 selectors[node.assignmentOperator] = selector; 92 selectors[node.assignmentOperator] = selector;
96 } 93 }
97 94
98 Selector getOperatorSelectorInComplexSendSet(SendSet node) { 95 Selector getOperatorSelectorInComplexSendSet(SendSet node) {
99 return selectors[node.assignmentOperator]; 96 return selectors[node.assignmentOperator];
100 } 97 }
101 98
102 // The following methods set selectors on the "for in" node. Since
103 // we're using three selectors, we need to use children of the node,
104 // and we arbitrarily choose which ones.
105
106 Selector setIteratorSelector(ForIn node, Selector selector) {
107 selectors[node] = selector;
108 }
109
110 Selector getIteratorSelector(ForIn node) {
111 return selectors[node];
112 }
113
114 Selector setMoveNextSelector(ForIn node, Selector selector) {
115 selectors[node.forToken] = selector;
116 }
117
118 Selector getMoveNextSelector(ForIn node) {
119 return selectors[node.forToken];
120 }
121
122 Selector setCurrentSelector(ForIn node, Selector selector) {
123 selectors[node.inToken] = selector;
124 }
125
126 Selector getCurrentSelector(ForIn node) {
127 return selectors[node.inToken];
128 }
129
130 bool isParameterChecked(Element element) { 99 bool isParameterChecked(Element element) {
131 return checkedParameters.contains(element); 100 return checkedParameters.contains(element);
132 } 101 }
133 102
134 void registerDependency(Element element) { 103 void registerDependency(Element element) {
135 otherDependencies.add(element.implementation); 104 otherDependencies.add(element.implementation);
136 } 105 }
137 106
138 String toString() => 'TreeElementMapping($currentElement)'; 107 String toString() => 'TreeElementMapping($currentElement)';
139 } 108 }
(...skipping 2564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 mapping[node] = target; 2673 mapping[node] = target;
2705 } 2674 }
2706 2675
2707 registerImplicitInvocation(SourceString name, int arity) { 2676 registerImplicitInvocation(SourceString name, int arity) {
2708 Selector selector = new Selector.call(name, null, arity); 2677 Selector selector = new Selector.call(name, null, arity);
2709 world.registerDynamicInvocation(name, selector); 2678 world.registerDynamicInvocation(name, selector);
2710 } 2679 }
2711 2680
2712 visitForIn(ForIn node) { 2681 visitForIn(ForIn node) {
2713 LibraryElement library = enclosingElement.getLibrary(); 2682 LibraryElement library = enclosingElement.getLibrary();
2714 Selector iteratorSelector = 2683 world.registerDynamicGetter(compiler.iteratorSelector.name,
2715 new Selector.getter(const SourceString('iterator'), library); 2684 compiler.iteratorSelector);
2716 world.registerDynamicGetter(iteratorSelector.name, iteratorSelector); 2685 world.registerDynamicGetter(compiler.currentSelector.name,
2717 mapping.setIteratorSelector(node, iteratorSelector); 2686 compiler.currentSelector);
2718 2687 world.registerDynamicInvocation(compiler.moveNextSelector.name,
2719 Selector currentSelector = 2688 compiler.moveNextSelector);
2720 new Selector.getter(const SourceString('current'), library);
2721 world.registerDynamicGetter(currentSelector.name, currentSelector);
2722 mapping.setCurrentSelector(node, currentSelector);
2723
2724 Selector moveNextSelector =
2725 new Selector.call(const SourceString('moveNext'), library, 0);
2726 world.registerDynamicInvocation(moveNextSelector.name, moveNextSelector);
2727 mapping.setMoveNextSelector(node, moveNextSelector);
2728 2689
2729 visit(node.expression); 2690 visit(node.expression);
2730 Scope blockScope = new BlockScope(scope); 2691 Scope blockScope = new BlockScope(scope);
2731 Node declaration = node.declaredIdentifier; 2692 Node declaration = node.declaredIdentifier;
2732 visitIn(declaration, blockScope); 2693 visitIn(declaration, blockScope);
2694
2695 Send send = declaration.asSend();
2696 VariableDefinitions variableDefinitions =
2697 declaration.asVariableDefinitions();
2698 Element loopVariable;
2699 Selector loopVariableSelector;
2700 if (send != null) {
2701 loopVariable = mapping[send];
2702 Identifier identifier = send.selector.asIdentifier();
2703 if (identifier == null) {
2704 compiler.reportErrorCode(send.selector, MessageKind.INVALID_FOR_IN);
2705 } else {
2706 loopVariableSelector = new Selector.setter(identifier.source, library);
2707 }
2708 if (send.receiver != null) {
2709 compiler.reportErrorCode(send.receiver, MessageKind.INVALID_FOR_IN);
2710 }
2711 } else if (variableDefinitions != null) {
2712 Link<Node> nodes = variableDefinitions.definitions.nodes;
2713 if (!nodes.tail.isEmpty) {
2714 compiler.reportErrorCode(nodes.tail.head, MessageKind.INVALID_FOR_IN);
2715 }
2716 Node first = nodes.head;
2717 Identifier identifier = first.asIdentifier();
2718 if (identifier == null) {
2719 compiler.reportErrorCode(first, MessageKind.INVALID_FOR_IN);
2720 } else {
2721 loopVariableSelector = new Selector.setter(identifier.source, library);
2722 loopVariable = mapping[identifier];
2723 }
2724 } else {
2725 compiler.reportErrorCode(declaration, MessageKind.INVALID_FOR_IN);
2726 }
2727 if (loopVariableSelector != null) {
2728 mapping.setSelector(declaration, loopVariableSelector);
2729 } else {
2730 // The selector may only be null if we reported an error.
2731 assert(invariant(declaration, compiler.compilationFailed));
2732 }
2733 if (loopVariable != null) {
2734 // loopVariable may be null if it could not be resolved.
2735 mapping[declaration] = loopVariable;
2736 }
2733 visitLoopBodyIn(node, node.body, blockScope); 2737 visitLoopBodyIn(node, node.body, blockScope);
2734
2735 // TODO(lrn): Also allow a single identifier.
2736 if ((declaration is !Send || declaration.asSend().selector is !Identifier
2737 || declaration.asSend().receiver != null)
2738 && (declaration is !VariableDefinitions ||
2739 !declaration.asVariableDefinitions().definitions.nodes.tail.isEmpty))
2740 {
2741 // The variable declaration is either not an identifier, not a
2742 // declaration, or it's declaring more than one variable.
2743 error(node.declaredIdentifier, MessageKind.INVALID_FOR_IN);
2744 }
2745 } 2738 }
2746 2739
2747 visitLabel(Label node) { 2740 visitLabel(Label node) {
2748 // Labels are handled by their containing statements/cases. 2741 // Labels are handled by their containing statements/cases.
2749 } 2742 }
2750 2743
2751 visitLabeledStatement(LabeledStatement node) { 2744 visitLabeledStatement(LabeledStatement node) {
2752 Statement body = node.statement; 2745 Statement body = node.statement;
2753 TargetElement targetElement = getOrCreateTargetElement(body); 2746 TargetElement targetElement = getOrCreateTargetElement(body);
2754 Map<String, LabelElement> labelElements = <String, LabelElement>{}; 2747 Map<String, LabelElement> labelElements = <String, LabelElement>{};
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3874 return e; 3867 return e;
3875 } 3868 }
3876 3869
3877 /// Assumed to be called by [resolveRedirectingFactory]. 3870 /// Assumed to be called by [resolveRedirectingFactory].
3878 Element visitReturn(Return node) { 3871 Element visitReturn(Return node) {
3879 Node expression = node.expression; 3872 Node expression = node.expression;
3880 return finishConstructorReference(visit(expression), 3873 return finishConstructorReference(visit(expression),
3881 expression, expression); 3874 expression, expression);
3882 } 3875 }
3883 } 3876 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698