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

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: Additional problems found during testing. 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 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 {'type': node}, typeName.source, enclosingElement), 1517 {'type': node}, typeName.source, enclosingElement),
1549 new TypedefType.userProvidedBadType(typdef, arguments.toLink())); 1518 new TypedefType.userProvidedBadType(typdef, arguments.toLink()));
1550 } else { 1519 } else {
1551 if (arguments.isEmpty) { 1520 if (arguments.isEmpty) {
1552 type = typdef.rawType; 1521 type = typdef.rawType;
1553 } else { 1522 } else {
1554 type = new TypedefType(typdef, arguments.toLink()); 1523 type = new TypedefType(typdef, arguments.toLink());
1555 } 1524 }
1556 } 1525 }
1557 } else if (element.isTypeVariable()) { 1526 } else if (element.isTypeVariable()) {
1558 if (enclosingElement.isInStaticMember()) { 1527 Element outer = enclosingElement.getOutermostEnclosingMemberOrTopLevel() ;
1528 bool isInFactoryConstructor = outer != null && outer.isFactoryConstructo r();
1529 if (!outer.isClass()
1530 » && !outer.isTypedef()
1531 && !isInFactoryConstructor
1532 && Elements.isInStaticContext(enclosingElement)) {
1559 compiler.backend.registerThrowRuntimeError( 1533 compiler.backend.registerThrowRuntimeError(
1560 // TODO(ahe): Get the TreeElements for the current element. 1534 // TODO(ahe): Get the TreeElements for the current element.
1561 compiler.globalDependencies); 1535 compiler.globalDependencies);
1562 compiler.reportWarning(node, 1536 compiler.reportWarning(node,
1563 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER.message( 1537 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER.message(
1564 {'typeVariableName': node})); 1538 {'typeVariableName': node}));
1565 type = new MalformedType( 1539 type = new MalformedType(
1566 new ErroneousElementX( 1540 new ErroneousElementX(
1567 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, 1541 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1568 {'typeVariableName': node}, 1542 {'typeVariableName': node},
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 mapping[node] = target; 2678 mapping[node] = target;
2705 } 2679 }
2706 2680
2707 registerImplicitInvocation(SourceString name, int arity) { 2681 registerImplicitInvocation(SourceString name, int arity) {
2708 Selector selector = new Selector.call(name, null, arity); 2682 Selector selector = new Selector.call(name, null, arity);
2709 world.registerDynamicInvocation(name, selector); 2683 world.registerDynamicInvocation(name, selector);
2710 } 2684 }
2711 2685
2712 visitForIn(ForIn node) { 2686 visitForIn(ForIn node) {
2713 LibraryElement library = enclosingElement.getLibrary(); 2687 LibraryElement library = enclosingElement.getLibrary();
2714 Selector iteratorSelector = 2688 world.registerDynamicGetter(compiler.iteratorSelector.name,
2715 new Selector.getter(const SourceString('iterator'), library); 2689 compiler.iteratorSelector);
2716 world.registerDynamicGetter(iteratorSelector.name, iteratorSelector); 2690 world.registerDynamicGetter(compiler.currentSelector.name,
2717 mapping.setIteratorSelector(node, iteratorSelector); 2691 compiler.currentSelector);
2718 2692 world.registerDynamicInvocation(compiler.moveNextSelector.name,
2719 Selector currentSelector = 2693 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 2694
2729 visit(node.expression); 2695 visit(node.expression);
2730 Scope blockScope = new BlockScope(scope); 2696 Scope blockScope = new BlockScope(scope);
2731 Node declaration = node.declaredIdentifier; 2697 Node declaration = node.declaredIdentifier;
2732 visitIn(declaration, blockScope); 2698 visitIn(declaration, blockScope);
2699
2700 Send send = declaration.asSend();
2701 VariableDefinitions variableDefinitions =
2702 declaration.asVariableDefinitions();
2703 Element loopVariable;
2704 Selector loopVariableSelector;
2705 if (send != null) {
2706 loopVariable = mapping[send];
2707 Identifier identifier = send.selector.asIdentifier();
2708 if (identifier == null) {
2709 compiler.reportErrorCode(send.selector, MessageKind.INVALID_FOR_IN);
2710 } else {
2711 loopVariableSelector = new Selector.setter(identifier.source, library);
2712 }
2713 if (send.receiver != null) {
2714 compiler.reportErrorCode(send.receiver, MessageKind.INVALID_FOR_IN);
2715 }
2716 } else if (variableDefinitions != null) {
2717 Link<Node> nodes = variableDefinitions.definitions.nodes;
2718 if (!nodes.tail.isEmpty) {
2719 compiler.reportErrorCode(nodes.tail.head, MessageKind.INVALID_FOR_IN);
2720 }
2721 Node first = nodes.head;
2722 Identifier identifier = first.asIdentifier();
2723 if (identifier == null) {
2724 compiler.reportErrorCode(first, MessageKind.INVALID_FOR_IN);
2725 } else {
2726 loopVariableSelector = new Selector.setter(identifier.source, library);
2727 loopVariable = mapping[identifier];
2728 }
2729 } else {
2730 compiler.reportErrorCode(declaration, MessageKind.INVALID_FOR_IN);
2731 }
2732 if (loopVariableSelector != null) {
2733 mapping.setSelector(declaration, loopVariableSelector);
2734 } else {
2735 // The selector may only be null if we reported an error.
2736 assert(invariant(declaration, compiler.compilationFailed));
2737 }
2738 if (loopVariable != null) {
2739 // loopVariable may be null if it could not be resolved.
2740 mapping[declaration] = loopVariable;
2741 }
2733 visitLoopBodyIn(node, node.body, blockScope); 2742 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 } 2743 }
2746 2744
2747 visitLabel(Label node) { 2745 visitLabel(Label node) {
2748 // Labels are handled by their containing statements/cases. 2746 // Labels are handled by their containing statements/cases.
2749 } 2747 }
2750 2748
2751 visitLabeledStatement(LabeledStatement node) { 2749 visitLabeledStatement(LabeledStatement node) {
2752 Statement body = node.statement; 2750 Statement body = node.statement;
2753 TargetElement targetElement = getOrCreateTargetElement(body); 2751 TargetElement targetElement = getOrCreateTargetElement(body);
2754 Map<String, LabelElement> labelElements = <String, LabelElement>{}; 2752 Map<String, LabelElement> labelElements = <String, LabelElement>{};
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3874 return e; 3872 return e;
3875 } 3873 }
3876 3874
3877 /// Assumed to be called by [resolveRedirectingFactory]. 3875 /// Assumed to be called by [resolveRedirectingFactory].
3878 Element visitReturn(Return node) { 3876 Element visitReturn(Return node) {
3879 Node expression = node.expression; 3877 Node expression = node.expression;
3880 return finishConstructorReference(visit(expression), 3878 return finishConstructorReference(visit(expression),
3881 expression, expression); 3879 expression, expression);
3882 } 3880 }
3883 } 3881 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698