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

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 10349008: Set the right context to resolve types of fields, closures and parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | « no previous file | no next file » | 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 Type getType(TypeAnnotation annotation); 8 Type getType(TypeAnnotation annotation);
9 } 9 }
10 10
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 ClassElement currentClass; 570 ClassElement currentClass;
571 bool typeRequired = false; 571 bool typeRequired = false;
572 StatementScope statementScope; 572 StatementScope statementScope;
573 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION; 573 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION;
574 574
575 ResolverVisitor(Compiler compiler, Element element) 575 ResolverVisitor(Compiler compiler, Element element)
576 : this.mapping = new TreeElementMapping(), 576 : this.mapping = new TreeElementMapping(),
577 this.enclosingElement = element, 577 this.enclosingElement = element,
578 inInstanceContext = element.isInstanceMember() 578 inInstanceContext = element.isInstanceMember()
579 || element.isGenerativeConstructor(), 579 || element.isGenerativeConstructor(),
580 this.context = element.isMember()
581 ? new ClassScope(element.enclosingElement, element.getLibrary())
582 : new TopScope(element.getLibrary()),
583 this.currentClass = element.isMember() ? element.enclosingElement : null, 580 this.currentClass = element.isMember() ? element.enclosingElement : null,
584 this.statementScope = new StatementScope(), 581 this.statementScope = new StatementScope(),
585 super(compiler); 582 super(compiler) {
583 LibraryElement library = element.getLibrary();
kasperl 2012/05/03 13:25:29 How about a helper function for this while loop? I
584 while (element !== null) {
585 if (element.isMember()) {
586 this.context = new ClassScope(element.enclosingElement, library);
587 break;
588 } else {
589 element = element.enclosingElement;
590 }
591 }
592 if (this.context === null) {
593 this.context = new TopScope(library);
594 }
595 }
586 596
587 Element lookup(Node node, SourceString name) { 597 Element lookup(Node node, SourceString name) {
588 Element result = context.lookup(name); 598 Element result = context.lookup(name);
589 if (!inInstanceContext && result != null && result.isInstanceMember()) { 599 if (!inInstanceContext && result != null && result.isInstanceMember()) {
590 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); 600 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]);
591 } 601 }
592 return result; 602 return result;
593 } 603 }
594 604
595 // Create, or reuse an already created, statement element for a statement. 605 // Create, or reuse an already created, statement element for a statement.
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 typeRequired = old; 1071 typeRequired = old;
1062 return result; 1072 return result;
1063 } 1073 }
1064 1074
1065 Element resolveTypeName(TypeAnnotation node) { 1075 Element resolveTypeName(TypeAnnotation node) {
1066 Identifier typeName = node.typeName.asIdentifier(); 1076 Identifier typeName = node.typeName.asIdentifier();
1067 Send send = node.typeName.asSend(); 1077 Send send = node.typeName.asSend();
1068 if (send !== null) { 1078 if (send !== null) {
1069 typeName = send.selector; 1079 typeName = send.selector;
1070 } 1080 }
1071 if (typeName.source == Types.VOID) return compiler.types.voidType.element; 1081 if (typeName.source == Types.VOID) {
1072 if (send !== null) { 1082 return compiler.types.voidType.element;
1083 } else if (typeName.source.stringValue === Keyword.FACTORY.stringValue) {
kasperl 2012/05/03 13:25:29 === on string values seems a bit fishy. Maybe chan
1084 return compiler.dynamicClass;
1085 } else if (send !== null) {
1073 Element e = context.lookup(send.receiver.asIdentifier().source); 1086 Element e = context.lookup(send.receiver.asIdentifier().source);
1074 if (e !== null && e.kind === ElementKind.PREFIX) { 1087 if (e !== null && e.kind === ElementKind.PREFIX) {
1075 // The receiver is a prefix. Lookup in the imported members. 1088 // The receiver is a prefix. Lookup in the imported members.
1076 PrefixElement prefix = e; 1089 PrefixElement prefix = e;
1077 return prefix.lookupLocalMember(typeName.source); 1090 return prefix.lookupLocalMember(typeName.source);
1078 } else if (e !== null && e.kind === ElementKind.CLASS) { 1091 } else if (e !== null && e.kind === ElementKind.CLASS) {
1079 // The receiver is the class part of a named constructor. 1092 // The receiver is the class part of a named constructor.
1080 return e; 1093 return e;
1081 } else { 1094 } else {
1082 return null; 1095 return null;
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 1936
1924 TopScope(LibraryElement library) : super(null, library); 1937 TopScope(LibraryElement library) : super(null, library);
1925 Element lookup(SourceString name) { 1938 Element lookup(SourceString name) {
1926 return library.find(name); 1939 return library.find(name);
1927 } 1940 }
1928 1941
1929 Element add(Element newElement) { 1942 Element add(Element newElement) {
1930 throw "Cannot add an element in the top scope"; 1943 throw "Cannot add an element in the top scope";
1931 } 1944 }
1932 } 1945 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698