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

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

Issue 10918078: Revert r11881. metadata_test fails for yet to be discover reasons. (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.buildScope(), 974 scope = element.buildEnclosingScope(),
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 // If [function] is the [enclosingElement], the [scope] has 1071 scope = new MethodScope(scope, function);
1072 // already been set in the constructor of [ResolverVisitor].
1073 if (function != enclosingElement) scope = new MethodScope(scope, function);
1074
1075 // Put the parameters in scope. 1072 // Put the parameters in scope.
1076 FunctionSignature functionParameters = 1073 FunctionSignature functionParameters =
1077 function.computeSignature(compiler); 1074 function.computeSignature(compiler);
1078 Link<Node> parameterNodes = (node.parameters === null) 1075 Link<Node> parameterNodes = (node.parameters === null)
1079 ? const EmptyLink<Node>() : node.parameters.nodes; 1076 ? const EmptyLink<Node>() : node.parameters.nodes;
1080 functionParameters.forEachParameter((Element element) { 1077 functionParameters.forEachParameter((Element element) {
1081 if (element == functionParameters.optionalParameters.head) { 1078 if (element == functionParameters.optionalParameters.head) {
1082 NodeList nodes = parameterNodes.head; 1079 NodeList nodes = parameterNodes.head;
1083 parameterNodes = nodes.nodes; 1080 parameterNodes = nodes.nodes;
1084 } 1081 }
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2556 2553
2557 class Scope { 2554 class Scope {
2558 final Element element; 2555 final Element element;
2559 final Scope parent; 2556 final Scope parent;
2560 2557
2561 Scope(this.parent, this.element); 2558 Scope(this.parent, this.element);
2562 abstract Element add(Element element); 2559 abstract Element add(Element element);
2563 abstract Element lookup(SourceString name); 2560 abstract Element lookup(SourceString name);
2564 } 2561 }
2565 2562
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
2578 /** 2563 /**
2579 * [TypeDeclarationScope] defines the outer scope of a type declaration in 2564 * [TypeDeclarationScope] defines the outer scope of a type declaration in
2580 * which the declared type variables and the entities in the enclosing scope are 2565 * which the declared type variables and the entities in the enclosing scope are
2581 * available but where declared and inherited members are not available. This 2566 * available but where declared and inherited members are not available. This
2582 * scope is only used for class/interface declarations during resolution of the 2567 * scope is only used for class/interface declarations during resolution of the
2583 * class hierarchy. In all other cases [ClassScope] is used. 2568 * class hierarchy. In all other cases [ClassScope] is used.
2584 */ 2569 */
2585 class TypeDeclarationScope extends Scope { 2570 class TypeDeclarationScope extends Scope {
2586 TypeDeclarationElement get element => super.element; 2571 TypeDeclarationElement get element => super.element;
2587 2572
2588 TypeDeclarationScope(parent, TypeDeclarationElement element) 2573 TypeDeclarationScope(parent, TypeDeclarationElement element)
2589 : super(parent, element) { 2574 : super(parent, element) {
2590 assert(parent !== null); 2575 assert(parent !== null);
2591 } 2576 }
2592 2577
2593 Element add(Element newElement) { 2578 Element add(Element newElement) {
2594 throw "Cannot add element to TypeDeclarationScope"; 2579 throw "Cannot add element to TypeDeclarationScope";
2595 } 2580 }
2596 2581
2582 /**
2583 * Looks up [name] within the type variables declared in [element].
2584 */
2585 Element lookupTypeVariable(SourceString name) {
2586 return null;
2587 }
2588
2597 Element lookup(SourceString name) { 2589 Element lookup(SourceString name) {
2598 Link<DartType> typeVariableLink = element.typeVariables; 2590 Link<DartType> typeVariableLink = element.typeVariables;
2599 while (!typeVariableLink.isEmpty()) { 2591 while (!typeVariableLink.isEmpty()) {
2600 TypeVariableType typeVariable = typeVariableLink.head; 2592 TypeVariableType typeVariable = typeVariableLink.head;
2601 if (typeVariable.name == name) { 2593 if (typeVariable.name == name) {
2602 return typeVariable.element; 2594 return typeVariable.element;
2603 } 2595 }
2604 typeVariableLink = typeVariableLink.tail; 2596 typeVariableLink = typeVariableLink.tail;
2605 } 2597 }
2606 2598
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2642 2634
2643 String toString() => 'block${elements.getKeys()} > $parent'; 2635 String toString() => 'block${elements.getKeys()} > $parent';
2644 } 2636 }
2645 2637
2646 /** 2638 /**
2647 * [ClassScope] defines the inner scope of a class/interface declaration in 2639 * [ClassScope] defines the inner scope of a class/interface declaration in
2648 * which declared members, declared type variables, entities in the enclosing 2640 * which declared members, declared type variables, entities in the enclosing
2649 * scope and inherited members are available, in the given order. 2641 * scope and inherited members are available, in the given order.
2650 */ 2642 */
2651 class ClassScope extends TypeDeclarationScope { 2643 class ClassScope extends TypeDeclarationScope {
2652 bool inStaticContext = false;
2653
2654 ClassScope(Scope parentScope, ClassElement element) 2644 ClassScope(Scope parentScope, ClassElement element)
2655 : super(parentScope, element); 2645 : super(parentScope, element);
2656 2646
2657 Element lookup(SourceString name) { 2647 Element lookup(SourceString name) {
2658 ClassElement cls = element; 2648 ClassElement cls = element;
2659 Element result = cls.lookupLocalMember(name); 2649 Element result = cls.lookupLocalMember(name);
2660 if (result !== null) return result; 2650 if (result !== null) return result;
2661 if (!inStaticContext) { 2651 result = super.lookup(name);
2662 // If not in a static context, we can lookup in the
2663 // TypeDeclaration scope, which contains the type variables of
2664 // the class.
2665 result = super.lookup(name);
2666 } else {
2667 result = parent.lookup(name);
2668 }
2669 if (result != null) return result; 2652 if (result != null) return result;
2670 return cls.lookupSuperMember(name); 2653 return cls.lookupSuperMember(name);
2671 } 2654 }
2672 2655
2673 Element add(Element newElement) { 2656 Element add(Element newElement) {
2674 throw "Cannot add an element in a class scope"; 2657 throw "Cannot add an element in a class scope";
2675 } 2658 }
2676 2659
2677 String toString() => '$element > $parent'; 2660 String toString() => '$element > $parent';
2678 } 2661 }
2679 2662
2680 class TopScope extends Scope { 2663 class TopScope extends Scope {
2681 LibraryElement get library => element; 2664 LibraryElement get library => element;
2682 2665
2683 TopScope(LibraryElement library) : super(null, library); 2666 TopScope(LibraryElement library) : super(null, library);
2684 Element lookup(SourceString name) { 2667 Element lookup(SourceString name) {
2685 return library.find(name); 2668 return library.find(name);
2686 } 2669 }
2687 2670
2688 Element add(Element newElement) { 2671 Element add(Element newElement) {
2689 throw "Cannot add an element in the top scope"; 2672 throw "Cannot add an element in the top scope";
2690 } 2673 }
2691 String toString() => '$element'; 2674 String toString() => '$element';
2692 } 2675 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698