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 2227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2238 | 2238 |
2239 ResolutionResult visitIdentifier(Identifier node) { | 2239 ResolutionResult visitIdentifier(Identifier node) { |
2240 if (node.isThis()) { | 2240 if (node.isThis()) { |
2241 if (!inInstanceContext) { | 2241 if (!inInstanceContext) { |
2242 error(node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node}); | 2242 error(node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node}); |
2243 } | 2243 } |
2244 return null; | 2244 return null; |
2245 } else if (node.isSuper()) { | 2245 } else if (node.isSuper()) { |
2246 if (!inInstanceContext) { | 2246 if (!inInstanceContext) { |
2247 error(node, MessageKind.NO_SUPER_IN_STATIC); | 2247 error(node, MessageKind.NO_SUPER_IN_STATIC); |
2248 // TODO(ahe): Don't throw, recover from error. | |
2249 throw new CompilerCancelledException(null); | |
2250 } | 2248 } |
2251 if ((ElementCategory.SUPER & allowedCategory) == 0) { | 2249 if ((ElementCategory.SUPER & allowedCategory) == 0) { |
2252 error(node, MessageKind.INVALID_USE_OF_SUPER); | 2250 error(node, MessageKind.INVALID_USE_OF_SUPER); |
2253 } | 2251 } |
2254 return null; | 2252 return null; |
2255 } else { | 2253 } else { |
2256 String name = node.source; | 2254 String name = node.source; |
2257 Element element = lookupInScope(compiler, node, scope, name); | 2255 Element element = lookupInScope(compiler, node, scope, name); |
2258 if (Elements.isUnresolved(element) && name == 'dynamic') { | 2256 if (Elements.isUnresolved(element) && name == 'dynamic') { |
2259 // TODO(johnniwinther): Remove this hack when we can return more complex | 2257 // TODO(johnniwinther): Remove this hack when we can return more complex |
2260 // objects than [Element] from this method. | 2258 // objects than [Element] from this method. |
2261 element = compiler.typeClass; | 2259 element = compiler.typeClass; |
2262 // Set the type to be `dynamic` to mark that this is a type literal. | 2260 // Set the type to be `dynamic` to mark that this is a type literal. |
2263 registry.setType(node, const DynamicType()); | 2261 registry.setType(node, const DynamicType()); |
2264 } | 2262 } |
2265 element = reportLookupErrorIfAny(element, node, node.source); | 2263 element = reportLookupErrorIfAny(element, node, node.source); |
2266 if (element == null) { | 2264 if (element == null) { |
2267 if (!inInstanceContext) { | 2265 if (!inInstanceContext) { |
2268 element = warnAndCreateErroneousElement( | 2266 element = warnAndCreateErroneousElement( |
2269 node, node.source, MessageKind.CANNOT_RESOLVE, | 2267 node, node.source, MessageKind.CANNOT_RESOLVE, |
2270 {'name': node}); | 2268 {'name': node}); |
2271 registry.registerThrowNoSuchMethod(); | 2269 registry.registerThrowNoSuchMethod(); |
2272 } | 2270 } |
2273 } else if (element.isErroneous) { | 2271 } else if (element.isErroneous) { |
2274 // Use the erroneous element. | 2272 // Use the erroneous element. |
2275 } else { | 2273 } else { |
2276 if ((element.kind.category & allowedCategory) == 0) { | 2274 if ((element.kind.category & allowedCategory) == 0) { |
2277 // TODO(ahe): Improve error message. Need UX input. | 2275 element = warnAndCreateErroneousElement( |
Johnni Winther
2015/01/09 08:44:17
Add a TODO to create a more precise erroneous elem
ahe
2015/01/09 10:43:46
Are you suggesting that we decode allowedCategory
Johnni Winther
2015/01/09 11:12:47
Yes.
ahe
2015/01/09 11:43:24
Done in CL 837563004.
| |
2278 error(node, MessageKind.GENERIC, | 2276 node, name, |
2279 {'text': "is not an expression $element"}); | 2277 MessageKind.GENERIC, |
2280 // TODO(ahe): Don't throw, recover from error. | 2278 // TODO(ahe): Improve error message. Need UX input. |
2281 throw new CompilerCancelledException(null); | 2279 {'text': "is not an expression $element"}); |
2282 } | 2280 } |
2283 } | 2281 } |
2284 if (!Elements.isUnresolved(element) && element.isClass) { | 2282 if (!Elements.isUnresolved(element) && element.isClass) { |
2285 ClassElement classElement = element; | 2283 ClassElement classElement = element; |
2286 classElement.ensureResolved(compiler); | 2284 classElement.ensureResolved(compiler); |
2287 } | 2285 } |
2288 return new ElementResult(registry.useElement(node, element)); | 2286 return new ElementResult(registry.useElement(node, element)); |
2289 } | 2287 } |
2290 } | 2288 } |
2291 | 2289 |
(...skipping 2625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4917 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. | 4915 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. |
4918 if (element == null) { | 4916 if (element == null) { |
4919 return failOrReturnErroneousElement(resolver.enclosingElement, node, name, | 4917 return failOrReturnErroneousElement(resolver.enclosingElement, node, name, |
4920 MessageKind.CANNOT_RESOLVE, | 4918 MessageKind.CANNOT_RESOLVE, |
4921 {'name': name}); | 4919 {'name': name}); |
4922 } else if (element.isErroneous) { | 4920 } else if (element.isErroneous) { |
4923 return element; | 4921 return element; |
4924 } else if (element.isTypedef) { | 4922 } else if (element.isTypedef) { |
4925 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, | 4923 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, |
4926 {'typedefName': name}); | 4924 {'typedefName': name}); |
4925 element = new ErroneousElementX( | |
Johnni Winther
2015/01/09 08:44:18
Ditto.
ahe
2015/01/09 10:43:46
Are you thinking of an element like this:
class E
Johnni Winther
2015/01/09 11:12:47
Yes.
ahe
2015/01/09 11:43:24
Done in CL 837563004.
| |
4926 MessageKind.CANNOT_INSTANTIATE_TYPEDEF, | |
4927 {'typedefName': name}, name, resolver.enclosingElement); | |
4927 } else if (element.isTypeVariable) { | 4928 } else if (element.isTypeVariable) { |
4928 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, | 4929 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, |
4929 {'typeVariableName': name}); | 4930 {'typeVariableName': name}); |
4930 // TODO(ahe): Don't throw, recover from error. | 4931 element = new ErroneousElementX( |
Johnni Winther
2015/01/09 08:44:18
Ditto.
ahe
2015/01/09 11:43:24
Done in CL 837563004.
| |
4931 throw new CompilerCancelledException(null); | 4932 MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, |
4933 {'typeVariableName': name}, name, resolver.enclosingElement); | |
4932 } else if (!element.isClass && !element.isPrefix) { | 4934 } else if (!element.isClass && !element.isPrefix) { |
4933 error(node, MessageKind.NOT_A_TYPE, {'node': name}); | 4935 error(node, MessageKind.NOT_A_TYPE, {'node': name}); |
4934 // TODO(ahe): Don't throw, recover from error. | 4936 element = new ErroneousElementX( |
Johnni Winther
2015/01/09 08:44:18
Ditto.
ahe
2015/01/09 11:43:24
Done in CL 837563004.
| |
4935 throw new CompilerCancelledException(null); | 4937 MessageKind.NOT_A_TYPE, {'node': name}, name, |
4938 resolver.enclosingElement); | |
4936 } | 4939 } |
4937 return element; | 4940 return element; |
4938 } | 4941 } |
4939 | 4942 |
4940 /// Assumed to be called by [resolveRedirectingFactory]. | 4943 /// Assumed to be called by [resolveRedirectingFactory]. |
4941 Element visitRedirectingFactoryBody(RedirectingFactoryBody node) { | 4944 Element visitRedirectingFactoryBody(RedirectingFactoryBody node) { |
4942 Node constructorReference = node.constructorReference; | 4945 Node constructorReference = node.constructorReference; |
4943 return finishConstructorReference(visit(constructorReference), | 4946 return finishConstructorReference(visit(constructorReference), |
4944 constructorReference, node); | 4947 constructorReference, node); |
4945 } | 4948 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5008 } | 5011 } |
5009 | 5012 |
5010 /// The result for the resolution of the `assert` method. | 5013 /// The result for the resolution of the `assert` method. |
5011 class AssertResult implements ResolutionResult { | 5014 class AssertResult implements ResolutionResult { |
5012 const AssertResult(); | 5015 const AssertResult(); |
5013 | 5016 |
5014 Element get element => null; | 5017 Element get element => null; |
5015 | 5018 |
5016 String toString() => 'AssertResult()'; | 5019 String toString() => 'AssertResult()'; |
5017 } | 5020 } |
OLD | NEW |