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 library dart2js.typechecker; | 5 library dart2js.typechecker; |
6 | 6 |
7 import 'common.dart'; | 7 import 'common.dart'; |
8 import 'common/names.dart' show | 8 import 'common/names.dart' show |
9 Identifiers; | 9 Identifiers; |
10 import 'common/resolution.dart' show | 10 import 'common/resolution.dart' show |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 } | 1016 } |
1017 } | 1017 } |
1018 | 1018 |
1019 /** | 1019 /** |
1020 * Computes the [ElementAccess] for [name] on the [node] possibly using the | 1020 * Computes the [ElementAccess] for [name] on the [node] possibly using the |
1021 * [element] provided for [node] by the resolver. | 1021 * [element] provided for [node] by the resolver. |
1022 */ | 1022 */ |
1023 ElementAccess computeAccess(Send node, String name, Element element, | 1023 ElementAccess computeAccess(Send node, String name, Element element, |
1024 MemberKind memberKind, | 1024 MemberKind memberKind, |
1025 {bool lookupClassMember: false}) { | 1025 {bool lookupClassMember: false}) { |
1026 if (element != null && element.isErroneous) { | 1026 if (Elements.isMalformed(element)) { |
1027 // An error has already been reported for this node. | |
1028 return const DynamicAccess(); | 1027 return const DynamicAccess(); |
1029 } | 1028 } |
1030 if (node.receiver != null) { | 1029 if (node.receiver != null) { |
1031 Element receiverElement = elements[node.receiver]; | 1030 Element receiverElement = elements[node.receiver]; |
1032 if (receiverElement != null) { | 1031 if (receiverElement != null) { |
1033 if (receiverElement.isPrefix) { | 1032 if (receiverElement.isPrefix) { |
1034 if (node.isConditional) { | 1033 if (node.isConditional) { |
1035 // Skip cases like `prefix?.topLevel`. | 1034 // Skip cases like `prefix?.topLevel`. |
1036 return const DynamicAccess(); | 1035 return const DynamicAccess(); |
1037 } | 1036 } |
(...skipping 18 matching lines...) Expand all Loading... |
1056 | 1055 |
1057 /** | 1056 /** |
1058 * Computes the [ElementAccess] for [name] on the [node] using the [element] | 1057 * Computes the [ElementAccess] for [name] on the [node] using the [element] |
1059 * provided for [node] by the resolver. | 1058 * provided for [node] by the resolver. |
1060 */ | 1059 */ |
1061 ElementAccess computeResolvedAccess(Send node, String name, | 1060 ElementAccess computeResolvedAccess(Send node, String name, |
1062 Element element, MemberKind memberKind) { | 1061 Element element, MemberKind memberKind) { |
1063 if (element == null) { | 1062 if (element == null) { |
1064 // foo() where foo is unresolved. | 1063 // foo() where foo is unresolved. |
1065 return lookupMember(node, thisType, name, memberKind, null); | 1064 return lookupMember(node, thisType, name, memberKind, null); |
1066 } else if (element.isErroneous) { | 1065 } else if (element.isMalformed) { |
1067 // foo() where foo is erroneous. | 1066 // foo() where foo is erroneous. |
1068 return const DynamicAccess(); | 1067 return const DynamicAccess(); |
1069 } else if (element.impliesType) { | 1068 } else if (element.impliesType) { |
1070 // The literal `Foo` where Foo is a class, a typedef, or a type variable. | 1069 // The literal `Foo` where Foo is a class, a typedef, or a type variable. |
1071 if (elements.isTypeLiteral(node)) { | 1070 if (elements.isTypeLiteral(node)) { |
1072 return new TypeLiteralAccess(elements.getTypeLiteralType(node)); | 1071 return new TypeLiteralAccess(elements.getTypeLiteralType(node)); |
1073 } | 1072 } |
1074 return createResolvedAccess(node, name, element); | 1073 return createResolvedAccess(node, name, element); |
1075 } else if (element.isClassMember) { | 1074 } else if (element.isClassMember) { |
1076 // foo() where foo is a member. | 1075 // foo() where foo is a member. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 Identifier selector = node.selector.asIdentifier(); | 1198 Identifier selector = node.selector.asIdentifier(); |
1200 if (Elements.isClosureSend(node, element)) { | 1199 if (Elements.isClosureSend(node, element)) { |
1201 if (element != null) { | 1200 if (element != null) { |
1202 // foo() where foo is a local or a parameter. | 1201 // foo() where foo is a local or a parameter. |
1203 return analyzeInvocation(node, createPromotedAccess(element)); | 1202 return analyzeInvocation(node, createPromotedAccess(element)); |
1204 } else { | 1203 } else { |
1205 // exp() where exp is some complex expression like (o) or foo(). | 1204 // exp() where exp is some complex expression like (o) or foo(). |
1206 DartType type = analyze(node.selector); | 1205 DartType type = analyze(node.selector); |
1207 return analyzeInvocation(node, new TypeAccess(type)); | 1206 return analyzeInvocation(node, new TypeAccess(type)); |
1208 } | 1207 } |
1209 } else if (Elements.isErroneous(element) && selector == null) { | 1208 } else if (Elements.isMalformed(element) && selector == null) { |
1210 // exp() where exp is an erroneous construct like `new Unresolved()`. | 1209 // exp() where exp is an erroneous construct like `new Unresolved()`. |
1211 DartType type = analyze(node.selector); | 1210 DartType type = analyze(node.selector); |
1212 return analyzeInvocation(node, new TypeAccess(type)); | 1211 return analyzeInvocation(node, new TypeAccess(type)); |
1213 } | 1212 } |
1214 | 1213 |
1215 String name = selector.source; | 1214 String name = selector.source; |
1216 | 1215 |
1217 if (node.isOperator && identical(name, 'is')) { | 1216 if (node.isOperator && identical(name, 'is')) { |
1218 analyze(node.receiver); | 1217 analyze(node.receiver); |
1219 if (!node.isIsNotCheck) { | 1218 if (!node.isIsNotCheck) { |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 | 1998 |
2000 visitTypedef(Typedef node) { | 1999 visitTypedef(Typedef node) { |
2001 // Do not typecheck [Typedef] nodes. | 2000 // Do not typecheck [Typedef] nodes. |
2002 } | 2001 } |
2003 | 2002 |
2004 visitNode(Node node) { | 2003 visitNode(Node node) { |
2005 reporter.internalError(node, | 2004 reporter.internalError(node, |
2006 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 2005 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
2007 } | 2006 } |
2008 } | 2007 } |
OLD | NEW |