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

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: Address Kasper's comments. 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 | « lib/compiler/implementation/elements/elements.dart ('k') | 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();
584 element = element.getEnclosingMember();
585 if (element !== null) {
586 context = new ClassScope(element.enclosingElement, library);
587 } else {
588 this.context = new TopScope(library);
589 }
590 }
586 591
587 Element lookup(Node node, SourceString name) { 592 Element lookup(Node node, SourceString name) {
588 Element result = context.lookup(name); 593 Element result = context.lookup(name);
589 if (!inInstanceContext && result != null && result.isInstanceMember()) { 594 if (!inInstanceContext && result != null && result.isInstanceMember()) {
590 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); 595 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]);
591 } 596 }
592 return result; 597 return result;
593 } 598 }
594 599
595 // Create, or reuse an already created, statement element for a statement. 600 // 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; 1066 typeRequired = old;
1062 return result; 1067 return result;
1063 } 1068 }
1064 1069
1065 Element resolveTypeName(TypeAnnotation node) { 1070 Element resolveTypeName(TypeAnnotation node) {
1066 Identifier typeName = node.typeName.asIdentifier(); 1071 Identifier typeName = node.typeName.asIdentifier();
1067 Send send = node.typeName.asSend(); 1072 Send send = node.typeName.asSend();
1068 if (send !== null) { 1073 if (send !== null) {
1069 typeName = send.selector; 1074 typeName = send.selector;
1070 } 1075 }
1071 if (typeName.source == Types.VOID) return compiler.types.voidType.element; 1076 if (typeName.source == Types.VOID) {
1072 if (send !== null) { 1077 return compiler.types.voidType.element;
1078 } else if (typeName.source.stringValue == Keyword.FACTORY.stringValue) {
1079 return compiler.dynamicClass;
ngeoffray 2012/05/07 09:32:30 You can remove this check, we have a fix: https://
1080 } else if (send !== null) {
1073 Element e = context.lookup(send.receiver.asIdentifier().source); 1081 Element e = context.lookup(send.receiver.asIdentifier().source);
1074 if (e !== null && e.kind === ElementKind.PREFIX) { 1082 if (e !== null && e.kind === ElementKind.PREFIX) {
1075 // The receiver is a prefix. Lookup in the imported members. 1083 // The receiver is a prefix. Lookup in the imported members.
1076 PrefixElement prefix = e; 1084 PrefixElement prefix = e;
1077 return prefix.lookupLocalMember(typeName.source); 1085 return prefix.lookupLocalMember(typeName.source);
1078 } else if (e !== null && e.kind === ElementKind.CLASS) { 1086 } else if (e !== null && e.kind === ElementKind.CLASS) {
1079 // The receiver is the class part of a named constructor. 1087 // The receiver is the class part of a named constructor.
1080 return e; 1088 return e;
1081 } else { 1089 } else {
1082 return null; 1090 return null;
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 1931
1924 TopScope(LibraryElement library) : super(null, library); 1932 TopScope(LibraryElement library) : super(null, library);
1925 Element lookup(SourceString name) { 1933 Element lookup(SourceString name) {
1926 return library.find(name); 1934 return library.find(name);
1927 } 1935 }
1928 1936
1929 Element add(Element newElement) { 1937 Element add(Element newElement) {
1930 throw "Cannot add an element in the top scope"; 1938 throw "Cannot add an element in the top scope";
1931 } 1939 }
1932 } 1940 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698