| 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 Element operator[](Node node); | 8 Element operator[](Node node); |
| 9 Selector getSelector(Send send); | 9 Selector getSelector(Send send); |
| 10 DartType getType(Node node); | 10 DartType getType(Node node); |
| (...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 typeResolver = new TypeResolver(compiler), | 1192 typeResolver = new TypeResolver(compiler), |
| 1193 scope = element.buildScope(), | 1193 scope = element.buildScope(), |
| 1194 inCheckContext = compiler.enableTypeAssertions, | 1194 inCheckContext = compiler.enableTypeAssertions, |
| 1195 inCatchBlock = false, | 1195 inCatchBlock = false, |
| 1196 super(compiler); | 1196 super(compiler); |
| 1197 | 1197 |
| 1198 Enqueuer get world => compiler.enqueuer.resolution; | 1198 Enqueuer get world => compiler.enqueuer.resolution; |
| 1199 | 1199 |
| 1200 Element lookup(Node node, SourceString name) { | 1200 Element lookup(Node node, SourceString name) { |
| 1201 Element result = scope.lookup(name); | 1201 Element result = scope.lookup(name); |
| 1202 if (!inInstanceContext && result != null && result.isInstanceMember()) { | 1202 if (!Elements.isUnresolved(result)) { |
| 1203 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); | 1203 if (!inInstanceContext && result.isInstanceMember()) { |
| 1204 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); |
| 1205 // TODO(johnniwinther): Create an ErroneousElement. |
| 1206 } else if (result.isAmbiguous()) { |
| 1207 AmbiguousElement ambiguous = result; |
| 1208 compiler.reportMessage(compiler.spanFromNode(node), |
| 1209 ambiguous.messageKind.error(ambiguous.messageArguments), |
| 1210 Diagnostic.ERROR); |
| 1211 return new ErroneousElement(ambiguous.messageKind, |
| 1212 ambiguous.messageArguments, |
| 1213 name, enclosingElement); |
| 1214 } |
| 1204 } | 1215 } |
| 1205 return result; | 1216 return result; |
| 1206 } | 1217 } |
| 1207 | 1218 |
| 1208 // Create, or reuse an already created, statement element for a statement. | 1219 // Create, or reuse an already created, statement element for a statement. |
| 1209 TargetElement getOrCreateTargetElement(Node statement) { | 1220 TargetElement getOrCreateTargetElement(Node statement) { |
| 1210 TargetElement element = mapping[statement]; | 1221 TargetElement element = mapping[statement]; |
| 1211 if (element == null) { | 1222 if (element == null) { |
| 1212 element = new TargetElement(statement, | 1223 element = new TargetElement(statement, |
| 1213 statementScope.nestingLevel, | 1224 statementScope.nestingLevel, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 } | 1270 } |
| 1260 return null; | 1271 return null; |
| 1261 } else { | 1272 } else { |
| 1262 Element element = lookup(node, node.source); | 1273 Element element = lookup(node, node.source); |
| 1263 if (element == null) { | 1274 if (element == null) { |
| 1264 if (!inInstanceContext) { | 1275 if (!inInstanceContext) { |
| 1265 element = warnAndCreateErroneousElement(node, node.source, | 1276 element = warnAndCreateErroneousElement(node, node.source, |
| 1266 MessageKind.CANNOT_RESOLVE, | 1277 MessageKind.CANNOT_RESOLVE, |
| 1267 [node]); | 1278 [node]); |
| 1268 } | 1279 } |
| 1269 } else if (element.isAmbiguous()) { | 1280 } else if (element.isErroneous()) { |
| 1270 AmbiguousElement ambiguous = element; | 1281 // Use the erroneous element. |
| 1271 element = warnAndCreateErroneousElement(node, node.source, | |
| 1272 ambiguous.messageKind, | |
| 1273 ambiguous.messageArguments); | |
| 1274 } else { | 1282 } else { |
| 1275 if ((element.kind.category & allowedCategory) == 0) { | 1283 if ((element.kind.category & allowedCategory) == 0) { |
| 1276 // TODO(ahe): Improve error message. Need UX input. | 1284 // TODO(ahe): Improve error message. Need UX input. |
| 1277 error(node, MessageKind.GENERIC, ["is not an expression $element"]); | 1285 error(node, MessageKind.GENERIC, ["is not an expression $element"]); |
| 1278 } | 1286 } |
| 1279 } | 1287 } |
| 1280 if (!Elements.isUnresolved(element) | 1288 if (!Elements.isUnresolved(element) |
| 1281 && element.kind == ElementKind.CLASS) { | 1289 && element.kind == ElementKind.CLASS) { |
| 1282 ClassElement classElement = element; | 1290 ClassElement classElement = element; |
| 1283 classElement.ensureResolved(compiler); | 1291 classElement.ensureResolved(compiler); |
| (...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2924 } | 2932 } |
| 2925 | 2933 |
| 2926 failOrReturnErroneousElement(Element enclosing, Node diagnosticNode, | 2934 failOrReturnErroneousElement(Element enclosing, Node diagnosticNode, |
| 2927 SourceString targetName, MessageKind kind, | 2935 SourceString targetName, MessageKind kind, |
| 2928 List arguments) { | 2936 List arguments) { |
| 2929 if (inConstContext) { | 2937 if (inConstContext) { |
| 2930 error(diagnosticNode, kind, arguments); | 2938 error(diagnosticNode, kind, arguments); |
| 2931 } else { | 2939 } else { |
| 2932 ResolutionWarning warning = new ResolutionWarning(kind, arguments); | 2940 ResolutionWarning warning = new ResolutionWarning(kind, arguments); |
| 2933 compiler.reportWarning(diagnosticNode, warning); | 2941 compiler.reportWarning(diagnosticNode, warning); |
| 2934 return new ErroneousFunctionElement(kind, arguments, targetName, | 2942 return new ErroneousElement(kind, arguments, targetName, enclosing); |
| 2935 enclosing); | |
| 2936 } | 2943 } |
| 2937 } | 2944 } |
| 2938 | 2945 |
| 2939 Selector createConstructorSelector(SourceString constructorName) { | 2946 Selector createConstructorSelector(SourceString constructorName) { |
| 2940 return constructorName == const SourceString('') | 2947 return constructorName == const SourceString('') |
| 2941 ? new Selector.callDefaultConstructor( | 2948 ? new Selector.callDefaultConstructor( |
| 2942 resolver.enclosingElement.getLibrary()) | 2949 resolver.enclosingElement.getLibrary()) |
| 2943 : new Selector.callConstructor( | 2950 : new Selector.callConstructor( |
| 2944 constructorName, | 2951 constructorName, |
| 2945 resolver.enclosingElement.getLibrary()); | 2952 resolver.enclosingElement.getLibrary()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3043 return e; | 3050 return e; |
| 3044 } | 3051 } |
| 3045 | 3052 |
| 3046 Element visitIdentifier(Identifier node) { | 3053 Element visitIdentifier(Identifier node) { |
| 3047 SourceString name = node.source; | 3054 SourceString name = node.source; |
| 3048 Element e = resolver.lookup(node, name); | 3055 Element e = resolver.lookup(node, name); |
| 3049 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. | 3056 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. |
| 3050 if (e == null) { | 3057 if (e == null) { |
| 3051 return failOrReturnErroneousElement(resolver.enclosingElement, node, name, | 3058 return failOrReturnErroneousElement(resolver.enclosingElement, node, name, |
| 3052 MessageKind.CANNOT_RESOLVE, [name]); | 3059 MessageKind.CANNOT_RESOLVE, [name]); |
| 3060 } else if (e.isErroneous()) { |
| 3061 return e; |
| 3053 } else if (identical(e.kind, ElementKind.TYPEDEF)) { | 3062 } else if (identical(e.kind, ElementKind.TYPEDEF)) { |
| 3054 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); | 3063 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); |
| 3055 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { | 3064 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { |
| 3056 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); | 3065 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); |
| 3057 } else if (!identical(e.kind, ElementKind.CLASS) | 3066 } else if (!identical(e.kind, ElementKind.CLASS) |
| 3058 && !identical(e.kind, ElementKind.PREFIX)) { | 3067 && !identical(e.kind, ElementKind.PREFIX)) { |
| 3059 error(node, MessageKind.NOT_A_TYPE, [name]); | 3068 error(node, MessageKind.NOT_A_TYPE, [name]); |
| 3060 } | 3069 } |
| 3061 return e; | 3070 return e; |
| 3062 } | 3071 } |
| 3063 | 3072 |
| 3064 /// Assumed to be called by [resolveRedirectingFactory]. | 3073 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3065 Element visitReturn(Return node) { | 3074 Element visitReturn(Return node) { |
| 3066 Node expression = node.expression; | 3075 Node expression = node.expression; |
| 3067 return finishConstructorReference(visit(expression), | 3076 return finishConstructorReference(visit(expression), |
| 3068 expression, expression); | 3077 expression, expression); |
| 3069 } | 3078 } |
| 3070 } | 3079 } |
| OLD | NEW |