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

Side by Side Diff: dart/frog/leg/resolver.dart

Issue 9808006: Resolve initializers in their proper scope. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 8 years, 9 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
« no previous file with comments | « dart/frog/leg/compile_time_constants.dart ('k') | dart/frog/leg/tree/nodes.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 } 8 }
9 9
10 class TreeElementMapping implements TreeElements { 10 class TreeElementMapping implements TreeElements {
(...skipping 30 matching lines...) Expand all
41 TreeElements resolve(Element element) { 41 TreeElements resolve(Element element) {
42 return measure(() { 42 return measure(() {
43 switch (element.kind) { 43 switch (element.kind) {
44 case ElementKind.GENERATIVE_CONSTRUCTOR: 44 case ElementKind.GENERATIVE_CONSTRUCTOR:
45 case ElementKind.FUNCTION: 45 case ElementKind.FUNCTION:
46 case ElementKind.GETTER: 46 case ElementKind.GETTER:
47 case ElementKind.SETTER: 47 case ElementKind.SETTER:
48 return resolveMethodElement(element); 48 return resolveMethodElement(element);
49 49
50 case ElementKind.FIELD: 50 case ElementKind.FIELD:
51 return resolveField(element);
52
51 case ElementKind.PARAMETER: 53 case ElementKind.PARAMETER:
52 case ElementKind.FIELD_PARAMETER: 54 case ElementKind.FIELD_PARAMETER:
53 return resolveVariableElement(element); 55 return resolveParameter(element);
54 56
55 default: 57 default:
56 compiler.unimplemented( 58 compiler.unimplemented(
57 "resolver", node: element.parseNode(compiler)); 59 "resolver", node: element.parseNode(compiler));
58 } 60 }
59 }); 61 });
60 } 62 }
61 63
62 SourceString getConstructorName(Send node) { 64 SourceString getConstructorName(Send node) {
63 if (node.receiver !== null) { 65 if (node.receiver !== null) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 181
180 if (constructor.defaultImplementation === null) { 182 if (constructor.defaultImplementation === null) {
181 // We failed find a constrcutor named either 183 // We failed find a constrcutor named either
182 // "MyInterface.name" or "MyClass.name". 184 // "MyInterface.name" or "MyClass.name".
183 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR2, 185 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR2,
184 [constructor.name, name]); 186 [constructor.name, name]);
185 } 187 }
186 } 188 }
187 } 189 }
188 190
189 TreeElements resolveVariableElement(Element element) { 191 TreeElements resolveField(Element element) {
190 Node tree = element.parseNode(compiler); 192 Node tree = element.parseNode(compiler);
191 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 193 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
192 if (tree is SendSet) { 194 initializerDo(tree, visitor.visit);
193 SendSet send = tree;
194 visitor.visit(send.arguments.head);
195 }
196 return visitor.mapping; 195 return visitor.mapping;
197 } 196 }
198 197
198 TreeElements resolveParameter(Element element) {
199 Node tree = element.parseNode(compiler);
200 ResolverVisitor visitor =
201 new ResolverVisitor(compiler, element.enclosingElement);
202 initializerDo(tree, visitor.visit);
203 return visitor.mapping;
204 }
205
199 Type resolveType(ClassElement element) { 206 Type resolveType(ClassElement element) {
200 if (element.isResolved) return element.type; 207 if (element.isResolved) return element.type;
201 return measure(() { 208 return measure(() {
202 ClassNode tree = element.parseNode(compiler); 209 ClassNode tree = element.parseNode(compiler);
203 ClassResolverVisitor visitor = 210 ClassResolverVisitor visitor =
204 new ClassResolverVisitor(compiler, element.getLibrary(), element); 211 new ClassResolverVisitor(compiler, element.getLibrary(), element);
205 visitor.visit(tree); 212 visitor.visit(tree);
206 element.isResolved = true; 213 element.isResolved = true;
207 return element.type; 214 return element.type;
208 }); 215 });
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 FunctionParameters functionParameters = 651 FunctionParameters functionParameters =
645 function.computeParameters(compiler); 652 function.computeParameters(compiler);
646 Link<Node> parameterNodes = node.parameters.nodes; 653 Link<Node> parameterNodes = node.parameters.nodes;
647 functionParameters.forEachParameter((Element element) { 654 functionParameters.forEachParameter((Element element) {
648 if (element == functionParameters.optionalParameters.head) { 655 if (element == functionParameters.optionalParameters.head) {
649 NodeList nodes = parameterNodes.head; 656 NodeList nodes = parameterNodes.head;
650 parameterNodes = nodes.nodes; 657 parameterNodes = nodes.nodes;
651 } 658 }
652 VariableDefinitions variableDefinitions = parameterNodes.head; 659 VariableDefinitions variableDefinitions = parameterNodes.head;
653 Node parameterNode = variableDefinitions.definitions.nodes.head; 660 Node parameterNode = variableDefinitions.definitions.nodes.head;
661 initializerDo(parameterNode, (n) => n.accept(this));
654 // Field parameters (this.x) are not visible inside the constructor. The 662 // Field parameters (this.x) are not visible inside the constructor. The
655 // fields they reference are visible, but must be resolved independently. 663 // fields they reference are visible, but must be resolved independently.
656 if (element.kind == ElementKind.FIELD_PARAMETER) { 664 if (element.kind == ElementKind.FIELD_PARAMETER) {
657 useElement(parameterNode, element); 665 useElement(parameterNode, element);
658 } else { 666 } else {
659 defineElement(variableDefinitions.definitions.nodes.head, element); 667 defineElement(variableDefinitions.definitions.nodes.head, element);
660 } 668 }
661 parameterNodes = parameterNodes.tail; 669 parameterNodes = parameterNodes.tail;
662 }); 670 });
663 } 671 }
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 1788
1781 TopScope(LibraryElement library) : super(null, library); 1789 TopScope(LibraryElement library) : super(null, library);
1782 Element lookup(SourceString name) { 1790 Element lookup(SourceString name) {
1783 return library.find(name); 1791 return library.find(name);
1784 } 1792 }
1785 1793
1786 Element add(Element element) { 1794 Element add(Element element) {
1787 throw "Cannot add an element in the top scope"; 1795 throw "Cannot add an element in the top scope";
1788 } 1796 }
1789 } 1797 }
OLDNEW
« no previous file with comments | « dart/frog/leg/compile_time_constants.dart ('k') | dart/frog/leg/tree/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698