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/names.dart' show | 7 import 'common/names.dart' show |
8 Identifiers; | 8 Identifiers; |
9 import 'common/tasks.dart' show | 9 import 'common/tasks.dart' show |
10 CompilerTask; | 10 CompilerTask; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 String get name => 'dynamic'; | 140 String get name => 'dynamic'; |
141 | 141 |
142 DartType computeType(Compiler compiler) => const DynamicType(); | 142 DartType computeType(Compiler compiler) => const DynamicType(); |
143 | 143 |
144 bool isCallable(Compiler compiler) => true; | 144 bool isCallable(Compiler compiler) => true; |
145 | 145 |
146 String toString() => 'DynamicAccess'; | 146 String toString() => 'DynamicAccess'; |
147 } | 147 } |
148 | 148 |
| 149 /// An access of the `assert` method. |
| 150 class AssertAccess implements ElementAccess { |
| 151 const AssertAccess(); |
| 152 |
| 153 Element get element => null; |
| 154 |
| 155 String get name => 'assert'; |
| 156 |
| 157 DartType computeType(Compiler compiler) { |
| 158 return new FunctionType.synthesized( |
| 159 const VoidType(), |
| 160 <DartType>[const DynamicType()]); |
| 161 } |
| 162 |
| 163 bool isCallable(Compiler compiler) => true; |
| 164 |
| 165 String toString() => 'AssertAccess'; |
| 166 } |
| 167 |
149 /** | 168 /** |
150 * An access of a resolved top-level or static property or function, or an | 169 * An access of a resolved top-level or static property or function, or an |
151 * access of a resolved element through [:this:]. | 170 * access of a resolved element through [:this:]. |
152 */ | 171 */ |
153 class ResolvedAccess extends ElementAccess { | 172 class ResolvedAccess extends ElementAccess { |
154 final Element element; | 173 final Element element; |
155 | 174 |
156 ResolvedAccess(Element this.element) { | 175 ResolvedAccess(Element this.element) { |
157 assert(element != null); | 176 assert(element != null); |
158 } | 177 } |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 void pushCascadeType(DartType type) { | 607 void pushCascadeType(DartType type) { |
589 cascadeTypes = cascadeTypes.prepend(type); | 608 cascadeTypes = cascadeTypes.prepend(type); |
590 } | 609 } |
591 | 610 |
592 DartType popCascadeType() { | 611 DartType popCascadeType() { |
593 DartType type = cascadeTypes.head; | 612 DartType type = cascadeTypes.head; |
594 cascadeTypes = cascadeTypes.tail; | 613 cascadeTypes = cascadeTypes.tail; |
595 return type; | 614 return type; |
596 } | 615 } |
597 | 616 |
598 DartType visitAssert(Assert node) { | |
599 analyze(node.condition); | |
600 if (node.hasMessage) analyze(node.message); | |
601 return const StatementType(); | |
602 } | |
603 | |
604 DartType visitBlock(Block node) { | 617 DartType visitBlock(Block node) { |
605 return analyze(node.statements); | 618 return analyze(node.statements); |
606 } | 619 } |
607 | 620 |
608 DartType visitCascade(Cascade node) { | 621 DartType visitCascade(Cascade node) { |
609 analyze(node.expression); | 622 analyze(node.expression); |
610 return popCascadeType(); | 623 return popCascadeType(); |
611 } | 624 } |
612 | 625 |
613 DartType visitCascadeReceiver(CascadeReceiver node) { | 626 DartType visitCascadeReceiver(CascadeReceiver node) { |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 // This should be the case but we double-check. | 1158 // This should be the case but we double-check. |
1146 // TODO(johnniwinther): Ensure that we don't suggest malbounded types. | 1159 // TODO(johnniwinther): Ensure that we don't suggest malbounded types. |
1147 return shownTypeGeneric; | 1160 return shownTypeGeneric; |
1148 } | 1161 } |
1149 } | 1162 } |
1150 return null; | 1163 return null; |
1151 | 1164 |
1152 } | 1165 } |
1153 | 1166 |
1154 DartType visitSend(Send node) { | 1167 DartType visitSend(Send node) { |
| 1168 if (elements.isAssert(node)) { |
| 1169 return analyzeInvocation(node, const AssertAccess()); |
| 1170 } |
| 1171 |
1155 Element element = elements[node]; | 1172 Element element = elements[node]; |
1156 | 1173 |
1157 if (element != null && element.isConstructor) { | 1174 if (element != null && element.isConstructor) { |
1158 DartType receiverType; | 1175 DartType receiverType; |
1159 if (node.receiver != null) { | 1176 if (node.receiver != null) { |
1160 receiverType = analyze(node.receiver); | 1177 receiverType = analyze(node.receiver); |
1161 } else if (node.selector.isSuper()) { | 1178 } else if (node.selector.isSuper()) { |
1162 // TODO(johnniwinther): Lookup super-member in class members. | 1179 // TODO(johnniwinther): Lookup super-member in class members. |
1163 receiverType = superType; | 1180 receiverType = superType; |
1164 } else { | 1181 } else { |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1957 | 1974 |
1958 visitTypedef(Typedef node) { | 1975 visitTypedef(Typedef node) { |
1959 // Do not typecheck [Typedef] nodes. | 1976 // Do not typecheck [Typedef] nodes. |
1960 } | 1977 } |
1961 | 1978 |
1962 visitNode(Node node) { | 1979 visitNode(Node node) { |
1963 compiler.internalError(node, | 1980 compiler.internalError(node, |
1964 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 1981 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
1965 } | 1982 } |
1966 } | 1983 } |
OLD | NEW |