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 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 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1076 return resolveTypeAnnotationInContext(scope, node, onFailure, | 1076 return resolveTypeAnnotationInContext(scope, node, onFailure, |
| 1077 whenResolved); | 1077 whenResolved); |
| 1078 } | 1078 } |
| 1079 | 1079 |
| 1080 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node, | 1080 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node, |
| 1081 onFailure, whenResolved) { | 1081 onFailure, whenResolved) { |
| 1082 Element element = resolveTypeName(scope, node); | 1082 Element element = resolveTypeName(scope, node); |
| 1083 DartType type; | 1083 DartType type; |
| 1084 if (element == null) { | 1084 if (element == null) { |
| 1085 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); | 1085 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); |
| 1086 } else if (element.isErroneous()) { | 1086 } else if (element.isAmbiguous()) { |
| 1087 ErroneousElement error = element; | 1087 AmbiguousElement ambiguous = element; |
| 1088 onFailure(node, error.messageKind, error.messageArguments); | 1088 onFailure(node, ambiguous.messageKind, ambiguous.messageArguments); |
| 1089 } else if (!element.impliesType()) { | 1089 } else if (!element.impliesType()) { |
| 1090 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]); | 1090 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]); |
| 1091 } else { | 1091 } else { |
| 1092 if (identical(element, compiler.types.voidType.element) || | 1092 if (identical(element, compiler.types.voidType.element) || |
| 1093 identical(element, compiler.types.dynamicType.element)) { | 1093 identical(element, compiler.types.dynamicType.element)) { |
| 1094 type = element.computeType(compiler); | 1094 type = element.computeType(compiler); |
| 1095 } else if (element.isClass()) { | 1095 } else if (element.isClass()) { |
| 1096 ClassElement cls = element; | 1096 ClassElement cls = element; |
| 1097 cls.ensureResolved(compiler); | 1097 cls.ensureResolved(compiler); |
| 1098 Link<DartType> arguments = | 1098 Link<DartType> arguments = |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 visitInStaticContext(Node node) { | 1236 visitInStaticContext(Node node) { |
| 1237 inStaticContext(() => visit(node)); | 1237 inStaticContext(() => visit(node)); |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 ErroneousElement warnAndCreateErroneousElement(Node node, | 1240 ErroneousElement warnAndCreateErroneousElement(Node node, |
| 1241 SourceString name, | 1241 SourceString name, |
| 1242 MessageKind kind, | 1242 MessageKind kind, |
| 1243 List<Node> arguments) { | 1243 List<Node> arguments) { |
| 1244 return warnOnErroneousElement(node, | 1244 ResolutionWarning warning = new ResolutionWarning(kind, arguments); |
| 1245 new ErroneousElement(kind, arguments, name, enclosingElement)); | |
| 1246 } | |
| 1247 | |
| 1248 ErroneousElement warnOnErroneousElement(Node node, | |
| 1249 ErroneousElement erroneousElement) { | |
| 1250 ResolutionWarning warning = | |
| 1251 new ResolutionWarning(erroneousElement.messageKind, | |
| 1252 erroneousElement.messageArguments); | |
| 1253 compiler.reportWarning(node, warning); | 1245 compiler.reportWarning(node, warning); |
| 1254 return erroneousElement; | 1246 return new ErroneousElement(kind, arguments, name, enclosingElement); |
| 1255 } | 1247 } |
| 1256 | 1248 |
| 1257 Element visitIdentifier(Identifier node) { | 1249 Element visitIdentifier(Identifier node) { |
| 1258 if (node.isThis()) { | 1250 if (node.isThis()) { |
| 1259 if (!inInstanceContext) { | 1251 if (!inInstanceContext) { |
| 1260 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); | 1252 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); |
| 1261 } | 1253 } |
| 1262 return null; | 1254 return null; |
| 1263 } else if (node.isSuper()) { | 1255 } else if (node.isSuper()) { |
| 1264 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC); | 1256 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC); |
| 1265 if ((ElementCategory.SUPER & allowedCategory) == 0) { | 1257 if ((ElementCategory.SUPER & allowedCategory) == 0) { |
| 1266 error(node, MessageKind.INVALID_USE_OF_SUPER); | 1258 error(node, MessageKind.INVALID_USE_OF_SUPER); |
| 1267 } | 1259 } |
| 1268 return null; | 1260 return null; |
| 1269 } else { | 1261 } else { |
| 1270 Element element = lookup(node, node.source); | 1262 Element element = lookup(node, node.source); |
| 1271 if (element == null) { | 1263 if (element == null) { |
| 1272 if (!inInstanceContext) { | 1264 if (!inInstanceContext) { |
| 1273 element = warnAndCreateErroneousElement(node, node.source, | 1265 element = warnAndCreateErroneousElement(node, node.source, |
| 1274 MessageKind.CANNOT_RESOLVE, | 1266 MessageKind.CANNOT_RESOLVE, |
| 1275 [node]); | 1267 [node]); |
| 1276 } | 1268 } |
| 1277 } else if (element.isErroneous()) { | 1269 } else if (element.isAmbiguous()) { |
| 1278 element = warnOnErroneousElement(node, element); | 1270 AmbiguousElement ambiguous = element; |
| 1271 element = warnAndCreateErroneousElement(node, node.source, | |
| 1272 ambiguous.messageKind, ambiguous.messageArguments); | |
|
karlklose
2012/11/07 11:41:24
I would prefer this formatting:
warnAndCreateErr
Johnni Winther
2012/11/07 13:02:01
Done.
| |
| 1279 } else { | 1273 } else { |
| 1280 if ((element.kind.category & allowedCategory) == 0) { | 1274 if ((element.kind.category & allowedCategory) == 0) { |
| 1281 // TODO(ahe): Improve error message. Need UX input. | 1275 // TODO(ahe): Improve error message. Need UX input. |
| 1282 error(node, MessageKind.GENERIC, ["is not an expression $element"]); | 1276 error(node, MessageKind.GENERIC, ["is not an expression $element"]); |
| 1283 } | 1277 } |
| 1284 } | 1278 } |
| 1285 if (!Elements.isUnresolved(element) | 1279 if (!Elements.isUnresolved(element) |
| 1286 && element.kind == ElementKind.CLASS) { | 1280 && element.kind == ElementKind.CLASS) { |
| 1287 ClassElement classElement = element; | 1281 ClassElement classElement = element; |
| 1288 classElement.ensureResolved(compiler); | 1282 classElement.ensureResolved(compiler); |
| (...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3038 return e; | 3032 return e; |
| 3039 } | 3033 } |
| 3040 | 3034 |
| 3041 /// Assumed to be called by [resolveRedirectingFactory]. | 3035 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3042 Element visitReturn(Return node) { | 3036 Element visitReturn(Return node) { |
| 3043 Expression expression = node.expression; | 3037 Expression expression = node.expression; |
| 3044 return finishConstructorReference(visit(expression), | 3038 return finishConstructorReference(visit(expression), |
| 3045 expression, expression); | 3039 expression, expression); |
| 3046 } | 3040 } |
| 3047 } | 3041 } |
| OLD | NEW |