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

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

Issue 10913081: Fix resolution of type parameters in static context, and the use of type parameters in closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 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 DartType getType(TypeAnnotation annotation); 8 DartType getType(TypeAnnotation annotation);
9 bool isParameterChecked(Element element); 9 bool isParameterChecked(Element element);
10 } 10 }
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 // When the element is a field, we are actually resolving its 964 // When the element is a field, we are actually resolving its
965 // initial value, which should not have access to instance 965 // initial value, which should not have access to instance
966 // fields. 966 // fields.
967 inInstanceContext = (element.isInstanceMember() && !element.isField()) 967 inInstanceContext = (element.isInstanceMember() && !element.isField())
968 || element.isGenerativeConstructor(), 968 || element.isGenerativeConstructor(),
969 this.currentClass = element.isMember() ? 969 this.currentClass = element.isMember() ?
970 element.getEnclosingClass() : 970 element.getEnclosingClass() :
971 null, 971 null,
972 this.statementScope = new StatementScope(), 972 this.statementScope = new StatementScope(),
973 typeResolver = new TypeResolver(compiler), 973 typeResolver = new TypeResolver(compiler),
974 scope = element.buildEnclosingScope(), 974 scope = element.buildScope(),
975 super(compiler) { 975 super(compiler) {
976 } 976 }
977 977
978 Enqueuer get world => compiler.enqueuer.resolution; 978 Enqueuer get world => compiler.enqueuer.resolution;
979 979
980 Element lookup(Node node, SourceString name) { 980 Element lookup(Node node, SourceString name) {
981 Element result = scope.lookup(name); 981 Element result = scope.lookup(name);
982 if (!inInstanceContext && result != null && result.isInstanceMember()) { 982 if (!inInstanceContext && result != null && result.isInstanceMember()) {
983 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); 983 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]);
984 } 984 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 1061
1062 DartType useType(TypeAnnotation annotation, DartType type) { 1062 DartType useType(TypeAnnotation annotation, DartType type) {
1063 if (type !== null) { 1063 if (type !== null) {
1064 mapping.setType(annotation, type); 1064 mapping.setType(annotation, type);
1065 useElement(annotation, type.element); 1065 useElement(annotation, type.element);
1066 } 1066 }
1067 return type; 1067 return type;
1068 } 1068 }
1069 1069
1070 void setupFunction(FunctionExpression node, FunctionElement function) { 1070 void setupFunction(FunctionExpression node, FunctionElement function) {
1071 scope = new MethodScope(scope, function); 1071 // If [function] is the [enclosingElement], the [scope] has
1072 // already been set in the constructor of [ResolverVisitor].
1073 if (function != enclosingElement) scope = new MethodScope(scope, function);
1074
1072 // Put the parameters in scope. 1075 // Put the parameters in scope.
1073 FunctionSignature functionParameters = 1076 FunctionSignature functionParameters =
1074 function.computeSignature(compiler); 1077 function.computeSignature(compiler);
1075 Link<Node> parameterNodes = (node.parameters === null) 1078 Link<Node> parameterNodes = (node.parameters === null)
1076 ? const EmptyLink<Node>() : node.parameters.nodes; 1079 ? const EmptyLink<Node>() : node.parameters.nodes;
1077 functionParameters.forEachParameter((Element element) { 1080 functionParameters.forEachParameter((Element element) {
1078 if (element == functionParameters.optionalParameters.head) { 1081 if (element == functionParameters.optionalParameters.head) {
1079 NodeList nodes = parameterNodes.head; 1082 NodeList nodes = parameterNodes.head;
1080 parameterNodes = nodes.nodes; 1083 parameterNodes = nodes.nodes;
1081 } 1084 }
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 2556
2554 class Scope { 2557 class Scope {
2555 final Element element; 2558 final Element element;
2556 final Scope parent; 2559 final Scope parent;
2557 2560
2558 Scope(this.parent, this.element); 2561 Scope(this.parent, this.element);
2559 abstract Element add(Element element); 2562 abstract Element add(Element element);
2560 abstract Element lookup(SourceString name); 2563 abstract Element lookup(SourceString name);
2561 } 2564 }
2562 2565
2566 class VariableScope extends Scope {
2567 VariableScope(parent, element) : super(parent, element);
2568
2569 Element add(Element newElement) {
2570 throw "Cannot add element to VariableScope";
2571 }
2572
2573 Element lookup(SourceString name) => parent.lookup(name);
2574
2575 String toString() => '$element > $parent';
2576 }
2577
2563 /** 2578 /**
2564 * [TypeDeclarationScope] defines the outer scope of a type declaration in 2579 * [TypeDeclarationScope] defines the outer scope of a type declaration in
2565 * which the declared type variables and the entities in the enclosing scope are 2580 * which the declared type variables and the entities in the enclosing scope are
2566 * available but where declared and inherited members are not available. This 2581 * available but where declared and inherited members are not available. This
2567 * scope is only used for class/interface declarations during resolution of the 2582 * scope is only used for class/interface declarations during resolution of the
2568 * class hierarchy. In all other cases [ClassScope] is used. 2583 * class hierarchy. In all other cases [ClassScope] is used.
2569 */ 2584 */
2570 class TypeDeclarationScope extends Scope { 2585 class TypeDeclarationScope extends Scope {
2571 TypeDeclarationElement get element => super.element; 2586 TypeDeclarationElement get element => super.element;
2572 2587
2573 TypeDeclarationScope(parent, TypeDeclarationElement element) 2588 TypeDeclarationScope(parent, TypeDeclarationElement element)
2574 : super(parent, element) { 2589 : super(parent, element) {
2575 assert(parent !== null); 2590 assert(parent !== null);
2576 } 2591 }
2577 2592
2578 Element add(Element newElement) { 2593 Element add(Element newElement) {
2579 throw "Cannot add element to TypeDeclarationScope"; 2594 throw "Cannot add element to TypeDeclarationScope";
2580 } 2595 }
2581 2596
2582 /**
2583 * Looks up [name] within the type variables declared in [element].
2584 */
2585 Element lookupTypeVariable(SourceString name) {
2586 return null;
2587 }
2588
2589 Element lookup(SourceString name) { 2597 Element lookup(SourceString name) {
2590 Link<DartType> typeVariableLink = element.typeVariables; 2598 Link<DartType> typeVariableLink = element.typeVariables;
2591 while (!typeVariableLink.isEmpty()) { 2599 while (!typeVariableLink.isEmpty()) {
2592 TypeVariableType typeVariable = typeVariableLink.head; 2600 TypeVariableType typeVariable = typeVariableLink.head;
2593 if (typeVariable.name == name) { 2601 if (typeVariable.name == name) {
2594 return typeVariable.element; 2602 return typeVariable.element;
2595 } 2603 }
2596 typeVariableLink = typeVariableLink.tail; 2604 typeVariableLink = typeVariableLink.tail;
2597 } 2605 }
2598 2606
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 2642
2635 String toString() => 'block${elements.getKeys()} > $parent'; 2643 String toString() => 'block${elements.getKeys()} > $parent';
2636 } 2644 }
2637 2645
2638 /** 2646 /**
2639 * [ClassScope] defines the inner scope of a class/interface declaration in 2647 * [ClassScope] defines the inner scope of a class/interface declaration in
2640 * which declared members, declared type variables, entities in the enclosing 2648 * which declared members, declared type variables, entities in the enclosing
2641 * scope and inherited members are available, in the given order. 2649 * scope and inherited members are available, in the given order.
2642 */ 2650 */
2643 class ClassScope extends TypeDeclarationScope { 2651 class ClassScope extends TypeDeclarationScope {
2652 bool inStaticContext = false;
2653
2644 ClassScope(Scope parentScope, ClassElement element) 2654 ClassScope(Scope parentScope, ClassElement element)
2645 : super(parentScope, element); 2655 : super(parentScope, element);
2646 2656
2647 Element lookup(SourceString name) { 2657 Element lookup(SourceString name) {
2648 ClassElement cls = element; 2658 ClassElement cls = element;
2649 Element result = cls.lookupLocalMember(name); 2659 Element result = cls.lookupLocalMember(name);
2650 if (result !== null) return result; 2660 if (result !== null) return result;
2651 result = super.lookup(name); 2661 if (!inStaticContext) {
2662 result = super.lookup(name);
karlklose 2012/09/05 13:58:36 Perhaps add a comment here that this means going t
ngeoffray 2012/09/05 15:36:11 Done.
2663 } else {
2664 result = parent.lookup(name);
2665 }
2652 if (result != null) return result; 2666 if (result != null) return result;
2653 return cls.lookupSuperMember(name); 2667 return cls.lookupSuperMember(name);
2654 } 2668 }
2655 2669
2656 Element add(Element newElement) { 2670 Element add(Element newElement) {
2657 throw "Cannot add an element in a class scope"; 2671 throw "Cannot add an element in a class scope";
2658 } 2672 }
2659 2673
2660 String toString() => '$element > $parent'; 2674 String toString() => '$element > $parent';
2661 } 2675 }
2662 2676
2663 class TopScope extends Scope { 2677 class TopScope extends Scope {
2664 LibraryElement get library => element; 2678 LibraryElement get library => element;
2665 2679
2666 TopScope(LibraryElement library) : super(null, library); 2680 TopScope(LibraryElement library) : super(null, library);
2667 Element lookup(SourceString name) { 2681 Element lookup(SourceString name) {
2668 return library.find(name); 2682 return library.find(name);
2669 } 2683 }
2670 2684
2671 Element add(Element newElement) { 2685 Element add(Element newElement) {
2672 throw "Cannot add an element in the top scope"; 2686 throw "Cannot add an element in the top scope";
2673 } 2687 }
2674 String toString() => '$element'; 2688 String toString() => '$element';
2675 } 2689 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698