| OLD | NEW |
| 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 abstract class TreeElements { | 5 abstract class 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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 return arguments.toLink(); | 1022 return arguments.toLink(); |
| 1023 } | 1023 } |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 class ResolverVisitor extends CommonResolverVisitor<Element> { | 1026 class ResolverVisitor extends CommonResolverVisitor<Element> { |
| 1027 final TreeElementMapping mapping; | 1027 final TreeElementMapping mapping; |
| 1028 final Element enclosingElement; | 1028 final Element enclosingElement; |
| 1029 final TypeResolver typeResolver; | 1029 final TypeResolver typeResolver; |
| 1030 bool inInstanceContext; | 1030 bool inInstanceContext; |
| 1031 bool inCheckContext; | 1031 bool inCheckContext; |
| 1032 bool inCatchBlock; |
| 1032 Scope scope; | 1033 Scope scope; |
| 1033 ClassElement currentClass; | 1034 ClassElement currentClass; |
| 1034 ExpressionStatement currentExpressionStatement; | 1035 ExpressionStatement currentExpressionStatement; |
| 1035 bool typeRequired = false; | 1036 bool typeRequired = false; |
| 1036 StatementScope statementScope; | 1037 StatementScope statementScope; |
| 1037 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION; | 1038 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION; |
| 1038 | 1039 |
| 1039 ResolverVisitor(Compiler compiler, Element element) | 1040 ResolverVisitor(Compiler compiler, Element element) |
| 1040 : this.mapping = new TreeElementMapping(element), | 1041 : this.mapping = new TreeElementMapping(element), |
| 1041 this.enclosingElement = element, | 1042 this.enclosingElement = element, |
| 1042 // When the element is a field, we are actually resolving its | 1043 // When the element is a field, we are actually resolving its |
| 1043 // initial value, which should not have access to instance | 1044 // initial value, which should not have access to instance |
| 1044 // fields. | 1045 // fields. |
| 1045 inInstanceContext = (element.isInstanceMember() && !element.isField()) | 1046 inInstanceContext = (element.isInstanceMember() && !element.isField()) |
| 1046 || element.isGenerativeConstructor(), | 1047 || element.isGenerativeConstructor(), |
| 1047 this.currentClass = element.isMember() ? element.getEnclosingClass() | 1048 this.currentClass = element.isMember() ? element.getEnclosingClass() |
| 1048 : null, | 1049 : null, |
| 1049 this.statementScope = new StatementScope(), | 1050 this.statementScope = new StatementScope(), |
| 1050 typeResolver = new TypeResolver(compiler), | 1051 typeResolver = new TypeResolver(compiler), |
| 1051 scope = element.buildScope(), | 1052 scope = element.buildScope(), |
| 1052 inCheckContext = compiler.enableTypeAssertions, | 1053 inCheckContext = compiler.enableTypeAssertions, |
| 1054 inCatchBlock = false, |
| 1053 super(compiler); | 1055 super(compiler); |
| 1054 | 1056 |
| 1055 Enqueuer get world => compiler.enqueuer.resolution; | 1057 Enqueuer get world => compiler.enqueuer.resolution; |
| 1056 | 1058 |
| 1057 Element lookup(Node node, SourceString name) { | 1059 Element lookup(Node node, SourceString name) { |
| 1058 Element result = scope.lookup(name); | 1060 Element result = scope.lookup(name); |
| 1059 if (!inInstanceContext && result != null && result.isInstanceMember()) { | 1061 if (!inInstanceContext && result != null && result.isInstanceMember()) { |
| 1060 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); | 1062 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); |
| 1061 } | 1063 } |
| 1062 return result; | 1064 return result; |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 | 1677 |
| 1676 visitOperator(Operator node) { | 1678 visitOperator(Operator node) { |
| 1677 unimplemented(node, 'operator'); | 1679 unimplemented(node, 'operator'); |
| 1678 } | 1680 } |
| 1679 | 1681 |
| 1680 visitReturn(Return node) { | 1682 visitReturn(Return node) { |
| 1681 visit(node.expression); | 1683 visit(node.expression); |
| 1682 } | 1684 } |
| 1683 | 1685 |
| 1684 visitThrow(Throw node) { | 1686 visitThrow(Throw node) { |
| 1687 if (!inCatchBlock && node.expression === null) { |
| 1688 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); |
| 1689 } |
| 1685 visit(node.expression); | 1690 visit(node.expression); |
| 1686 } | 1691 } |
| 1687 | 1692 |
| 1688 visitVariableDefinitions(VariableDefinitions node) { | 1693 visitVariableDefinitions(VariableDefinitions node) { |
| 1689 visit(node.type); | 1694 visit(node.type); |
| 1690 VariableDefinitionsVisitor visitor = | 1695 VariableDefinitionsVisitor visitor = |
| 1691 new VariableDefinitionsVisitor(compiler, node, this, | 1696 new VariableDefinitionsVisitor(compiler, node, this, |
| 1692 ElementKind.VARIABLE); | 1697 ElementKind.VARIABLE); |
| 1693 visitor.visit(node.definitions); | 1698 visitor.visit(node.definitions); |
| 1694 } | 1699 } |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2104 } | 2109 } |
| 2105 } | 2110 } |
| 2106 } | 2111 } |
| 2107 | 2112 |
| 2108 Scope blockScope = new BlockScope(scope); | 2113 Scope blockScope = new BlockScope(scope); |
| 2109 var wasTypeRequired = typeRequired; | 2114 var wasTypeRequired = typeRequired; |
| 2110 typeRequired = true; | 2115 typeRequired = true; |
| 2111 doInCheckContext(() => visitIn(node.type, blockScope)); | 2116 doInCheckContext(() => visitIn(node.type, blockScope)); |
| 2112 typeRequired = wasTypeRequired; | 2117 typeRequired = wasTypeRequired; |
| 2113 visitIn(node.formals, blockScope); | 2118 visitIn(node.formals, blockScope); |
| 2119 var oldInCatchBlock = inCatchBlock; |
| 2120 inCatchBlock = true; |
| 2114 visitIn(node.block, blockScope); | 2121 visitIn(node.block, blockScope); |
| 2122 inCatchBlock = oldInCatchBlock; |
| 2115 } | 2123 } |
| 2116 | 2124 |
| 2117 visitTypedef(Typedef node) { | 2125 visitTypedef(Typedef node) { |
| 2118 unimplemented(node, 'typedef'); | 2126 unimplemented(node, 'typedef'); |
| 2119 } | 2127 } |
| 2120 } | 2128 } |
| 2121 | 2129 |
| 2122 class TypeDefinitionVisitor extends CommonResolverVisitor<DartType> { | 2130 class TypeDefinitionVisitor extends CommonResolverVisitor<DartType> { |
| 2123 Scope scope; | 2131 Scope scope; |
| 2124 TypeDeclarationElement element; | 2132 TypeDeclarationElement element; |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3047 return result; | 3055 return result; |
| 3048 } | 3056 } |
| 3049 Element lookup(SourceString name) => localLookup(name); | 3057 Element lookup(SourceString name) => localLookup(name); |
| 3050 Element lexicalLookup(SourceString name) => localLookup(name); | 3058 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3051 | 3059 |
| 3052 Element add(Element newElement) { | 3060 Element add(Element newElement) { |
| 3053 throw "Cannot add an element in a patch library scope"; | 3061 throw "Cannot add an element in a patch library scope"; |
| 3054 } | 3062 } |
| 3055 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3063 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3056 } | 3064 } |
| OLD | NEW |