OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.engine.internal.resolver; | 14 package com.google.dart.engine.internal.resolver; |
15 | 15 |
16 import com.google.dart.engine.ast.ASTNode; | 16 import com.google.dart.engine.ast.ASTNode; |
17 import com.google.dart.engine.ast.ConstructorName; | 17 import com.google.dart.engine.ast.ConstructorName; |
18 import com.google.dart.engine.ast.FunctionDeclaration; | 18 import com.google.dart.engine.ast.FunctionDeclaration; |
19 import com.google.dart.engine.ast.FunctionExpression; | 19 import com.google.dart.engine.ast.FunctionExpression; |
20 import com.google.dart.engine.ast.Label; | 20 import com.google.dart.engine.ast.Label; |
21 import com.google.dart.engine.ast.MethodInvocation; | 21 import com.google.dart.engine.ast.MethodInvocation; |
22 import com.google.dart.engine.ast.PrefixedIdentifier; | 22 import com.google.dart.engine.ast.PrefixedIdentifier; |
23 import com.google.dart.engine.ast.PropertyAccess; | 23 import com.google.dart.engine.ast.PropertyAccess; |
24 import com.google.dart.engine.ast.SimpleIdentifier; | 24 import com.google.dart.engine.ast.SimpleIdentifier; |
25 import com.google.dart.engine.element.Element; | 25 import com.google.dart.engine.element.Element; |
26 import com.google.dart.engine.element.ElementKind; | 26 import com.google.dart.engine.element.ElementKind; |
27 import com.google.dart.engine.element.ExecutableElement; | 27 import com.google.dart.engine.element.ExecutableElement; |
| 28 import com.google.dart.engine.element.LibraryElement; |
28 import com.google.dart.engine.element.VariableElement; | 29 import com.google.dart.engine.element.VariableElement; |
| 30 import com.google.dart.engine.error.AnalysisErrorListener; |
29 import com.google.dart.engine.internal.element.LocalVariableElementImpl; | 31 import com.google.dart.engine.internal.element.LocalVariableElementImpl; |
30 import com.google.dart.engine.internal.element.ParameterElementImpl; | 32 import com.google.dart.engine.internal.element.ParameterElementImpl; |
| 33 import com.google.dart.engine.internal.scope.Scope; |
31 import com.google.dart.engine.source.Source; | 34 import com.google.dart.engine.source.Source; |
32 import com.google.dart.engine.utilities.general.ObjectUtilities; | 35 import com.google.dart.engine.utilities.general.ObjectUtilities; |
33 | 36 |
34 /** | 37 /** |
35 * Instances of the class {@code VariableResolverVisitor} are used to resolve | 38 * Instances of the class {@code VariableResolverVisitor} are used to resolve |
36 * {@link SimpleIdentifier}s to local variables and formal parameters. | 39 * {@link SimpleIdentifier}s to local variables and formal parameters. |
37 * | 40 * |
38 * @coverage dart.engine.resolver | 41 * @coverage dart.engine.resolver |
39 */ | 42 */ |
40 public class VariableResolverVisitor extends ScopedVisitor { | 43 public class VariableResolverVisitor extends ScopedVisitor { |
41 /** | 44 /** |
42 * The method or function that we are currently visiting, or {@code null} if w
e are not inside a | 45 * The method or function that we are currently visiting, or {@code null} if w
e are not inside a |
43 * method or function. | 46 * method or function. |
44 */ | 47 */ |
45 private ExecutableElement enclosingFunction; | 48 private ExecutableElement enclosingFunction; |
46 | 49 |
47 /** | 50 /** |
48 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 51 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
49 * | 52 * |
50 * @param library the library containing the compilation unit being resolved | 53 * @param library the library containing the compilation unit being resolved |
51 * @param source the source representing the compilation unit being visited | 54 * @param source the source representing the compilation unit being visited |
52 * @param typeProvider the object used to access the types from the core libra
ry | 55 * @param typeProvider the object used to access the types from the core libra
ry |
53 */ | 56 */ |
54 public VariableResolverVisitor(Library library, Source source, TypeProvider ty
peProvider) { | 57 public VariableResolverVisitor(Library library, Source source, TypeProvider ty
peProvider) { |
55 super(library, source, typeProvider); | 58 super(library, source, typeProvider); |
56 } | 59 } |
57 | 60 |
| 61 /** |
| 62 * Initialize a newly created visitor to resolve the nodes in an AST node. |
| 63 * |
| 64 * @param definingLibrary the element for the library containing the node bein
g visited |
| 65 * @param source the source representing the compilation unit containing the n
ode being visited |
| 66 * @param typeProvider the object used to access the types from the core libra
ry |
| 67 * @param nameScope the scope used to resolve identifiers in the node that wil
l first be visited |
| 68 * @param errorListener the error listener that will be informed of any errors
that are found |
| 69 * during resolution |
| 70 */ |
| 71 public VariableResolverVisitor(LibraryElement definingLibrary, Source source, |
| 72 TypeProvider typeProvider, Scope nameScope, AnalysisErrorListener errorLis
tener) { |
| 73 super(definingLibrary, source, typeProvider, nameScope, errorListener); |
| 74 } |
| 75 |
58 @Override | 76 @Override |
59 public Void visitFunctionDeclaration(FunctionDeclaration node) { | 77 public Void visitFunctionDeclaration(FunctionDeclaration node) { |
60 ExecutableElement outerFunction = enclosingFunction; | 78 ExecutableElement outerFunction = enclosingFunction; |
61 try { | 79 try { |
62 enclosingFunction = node.getElement(); | 80 enclosingFunction = node.getElement(); |
63 return super.visitFunctionDeclaration(node); | 81 return super.visitFunctionDeclaration(node); |
64 } finally { | 82 } finally { |
65 enclosingFunction = outerFunction; | 83 enclosingFunction = outerFunction; |
66 } | 84 } |
67 } | 85 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // If we are in some closure, check if it is not the same as where varia
ble is declared. | 147 // If we are in some closure, check if it is not the same as where varia
ble is declared. |
130 if (enclosingFunction != null | 148 if (enclosingFunction != null |
131 && !ObjectUtilities.equals(element.getEnclosingElement(), enclosingF
unction)) { | 149 && !ObjectUtilities.equals(element.getEnclosingElement(), enclosingF
unction)) { |
132 parameterImpl.markPotentiallyMutatedInClosure(); | 150 parameterImpl.markPotentiallyMutatedInClosure(); |
133 } | 151 } |
134 } | 152 } |
135 } | 153 } |
136 return null; | 154 return null; |
137 } | 155 } |
138 } | 156 } |
OLD | NEW |