Chromium Code Reviews| 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 part of resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 AnalyzableElement get analyzedElement; | 8 AnalyzableElement get analyzedElement; |
| 9 Iterable<Node> get superUses; | 9 Iterable<Node> get superUses; |
| 10 | 10 |
| (...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2105 * Do not subclass or instantiate this class outside this library | 2105 * Do not subclass or instantiate this class outside this library |
| 2106 * except for testing. | 2106 * except for testing. |
| 2107 */ | 2107 */ |
| 2108 class ResolverVisitor extends MappingVisitor<ResolutionResult> { | 2108 class ResolverVisitor extends MappingVisitor<ResolutionResult> { |
| 2109 /** | 2109 /** |
| 2110 * The current enclosing element for the visited AST nodes. | 2110 * The current enclosing element for the visited AST nodes. |
| 2111 * | 2111 * |
| 2112 * This field is updated when nested closures are visited. | 2112 * This field is updated when nested closures are visited. |
| 2113 */ | 2113 */ |
| 2114 Element enclosingElement; | 2114 Element enclosingElement; |
| 2115 | |
| 2116 /// Whether we are in a context where `this` is accessible (this will be false | |
| 2117 /// in static contexts, factory methods, and field initializers). | |
| 2115 bool inInstanceContext; | 2118 bool inInstanceContext; |
| 2116 bool inCheckContext; | 2119 bool inCheckContext; |
| 2117 bool inCatchBlock; | 2120 bool inCatchBlock; |
| 2118 | 2121 |
| 2119 Scope scope; | 2122 Scope scope; |
| 2120 ClassElement currentClass; | 2123 ClassElement currentClass; |
| 2121 ExpressionStatement currentExpressionStatement; | 2124 ExpressionStatement currentExpressionStatement; |
| 2122 bool sendIsMemberAccess = false; | 2125 bool sendIsMemberAccess = false; |
| 2123 StatementScope statementScope; | 2126 StatementScope statementScope; |
| 2124 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION | 2127 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2297 // Set the type to be `dynamic` to mark that this is a type literal. | 2300 // Set the type to be `dynamic` to mark that this is a type literal. |
| 2298 registry.setType(node, const DynamicType()); | 2301 registry.setType(node, const DynamicType()); |
| 2299 } | 2302 } |
| 2300 element = reportLookupErrorIfAny(element, node, node.source); | 2303 element = reportLookupErrorIfAny(element, node, node.source); |
| 2301 if (element == null) { | 2304 if (element == null) { |
| 2302 if (!inInstanceContext) { | 2305 if (!inInstanceContext) { |
| 2303 element = warnAndCreateErroneousElement( | 2306 element = warnAndCreateErroneousElement( |
| 2304 node, node.source, MessageKind.CANNOT_RESOLVE, | 2307 node, node.source, MessageKind.CANNOT_RESOLVE, |
| 2305 {'name': node}); | 2308 {'name': node}); |
| 2306 registry.registerThrowNoSuchMethod(); | 2309 registry.registerThrowNoSuchMethod(); |
| 2310 | |
| 2311 // We also report an error within initializers because `this` is | |
| 2312 // implicitly accessed when unqualified identifiers are not resolved. | |
| 2313 // For details, see section 16.14.3 of the spec (2nd edition): | |
| 2314 // An unqualified invocation `i` of the form `id(a1, ...)` | |
| 2315 // ... | |
| 2316 // If `i` does not occur inside a top level or static function, `i` | |
| 2317 // is equivalent to `this.id(a1 , ...)`. | |
| 2318 if ((enclosingElement.isInstanceMember && enclosingElement.isField) || | |
| 2319 (enclosingElement.isGenerativeConstructor)) { | |
| 2320 compiler.reportError( | |
|
Johnni Winther
2015/04/10 07:55:50
From a users perspective, it might be better to ha
Siggi Cherem (dart-lang)
2015/04/10 18:56:26
I have it a try. WDYT?
| |
| 2321 node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node.source}); | |
| 2322 } | |
| 2307 } | 2323 } |
| 2308 } else if (element.isErroneous) { | 2324 } else if (element.isErroneous) { |
| 2309 // Use the erroneous element. | 2325 // Use the erroneous element. |
| 2310 } else { | 2326 } else { |
| 2311 if ((element.kind.category & allowedCategory) == 0) { | 2327 if ((element.kind.category & allowedCategory) == 0) { |
| 2312 element = warnAndCreateErroneousElement( | 2328 element = warnAndCreateErroneousElement( |
| 2313 node, name, | 2329 node, name, |
| 2314 MessageKind.GENERIC, | 2330 MessageKind.GENERIC, |
| 2315 // TODO(ahe): Improve error message. Need UX input. | 2331 // TODO(ahe): Improve error message. Need UX input. |
| 2316 {'text': "is not an expression $element"}); | 2332 {'text': "is not an expression $element"}); |
| (...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5077 } | 5093 } |
| 5078 | 5094 |
| 5079 /// The result for the resolution of the `assert` method. | 5095 /// The result for the resolution of the `assert` method. |
| 5080 class AssertResult implements ResolutionResult { | 5096 class AssertResult implements ResolutionResult { |
| 5081 const AssertResult(); | 5097 const AssertResult(); |
| 5082 | 5098 |
| 5083 Element get element => null; | 5099 Element get element => null; |
| 5084 | 5100 |
| 5085 String toString() => 'AssertResult()'; | 5101 String toString() => 'AssertResult()'; |
| 5086 } | 5102 } |
| OLD | NEW |