Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: pkg/compiler/lib/src/typechecker.dart

Issue 1342213003: Add optional message to assert in Dart2js - continued (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add --assert-message flag Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/tree/unparser.dart ('k') | pkg/compiler/lib/src/universe/selector.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
168 /** 149 /**
169 * An access of a resolved top-level or static property or function, or an 150 * An access of a resolved top-level or static property or function, or an
170 * access of a resolved element through [:this:]. 151 * access of a resolved element through [:this:].
171 */ 152 */
172 class ResolvedAccess extends ElementAccess { 153 class ResolvedAccess extends ElementAccess {
173 final Element element; 154 final Element element;
174 155
175 ResolvedAccess(Element this.element) { 156 ResolvedAccess(Element this.element) {
176 assert(element != null); 157 assert(element != null);
177 } 158 }
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 void pushCascadeType(DartType type) { 588 void pushCascadeType(DartType type) {
608 cascadeTypes = cascadeTypes.prepend(type); 589 cascadeTypes = cascadeTypes.prepend(type);
609 } 590 }
610 591
611 DartType popCascadeType() { 592 DartType popCascadeType() {
612 DartType type = cascadeTypes.head; 593 DartType type = cascadeTypes.head;
613 cascadeTypes = cascadeTypes.tail; 594 cascadeTypes = cascadeTypes.tail;
614 return type; 595 return type;
615 } 596 }
616 597
598 DartType visitAssert(Assert node) {
599 analyze(node.condition);
600 if (node.hasMessage) analyze(node.message);
601 return const StatementType();
602 }
603
617 DartType visitBlock(Block node) { 604 DartType visitBlock(Block node) {
618 return analyze(node.statements); 605 return analyze(node.statements);
619 } 606 }
620 607
621 DartType visitCascade(Cascade node) { 608 DartType visitCascade(Cascade node) {
622 analyze(node.expression); 609 analyze(node.expression);
623 return popCascadeType(); 610 return popCascadeType();
624 } 611 }
625 612
626 DartType visitCascadeReceiver(CascadeReceiver node) { 613 DartType visitCascadeReceiver(CascadeReceiver node) {
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 // This should be the case but we double-check. 1145 // This should be the case but we double-check.
1159 // TODO(johnniwinther): Ensure that we don't suggest malbounded types. 1146 // TODO(johnniwinther): Ensure that we don't suggest malbounded types.
1160 return shownTypeGeneric; 1147 return shownTypeGeneric;
1161 } 1148 }
1162 } 1149 }
1163 return null; 1150 return null;
1164 1151
1165 } 1152 }
1166 1153
1167 DartType visitSend(Send node) { 1154 DartType visitSend(Send node) {
1168 if (elements.isAssert(node)) {
1169 return analyzeInvocation(node, const AssertAccess());
1170 }
1171
1172 Element element = elements[node]; 1155 Element element = elements[node];
1173 1156
1174 if (element != null && element.isConstructor) { 1157 if (element != null && element.isConstructor) {
1175 DartType receiverType; 1158 DartType receiverType;
1176 if (node.receiver != null) { 1159 if (node.receiver != null) {
1177 receiverType = analyze(node.receiver); 1160 receiverType = analyze(node.receiver);
1178 } else if (node.selector.isSuper()) { 1161 } else if (node.selector.isSuper()) {
1179 // TODO(johnniwinther): Lookup super-member in class members. 1162 // TODO(johnniwinther): Lookup super-member in class members.
1180 receiverType = superType; 1163 receiverType = superType;
1181 } else { 1164 } else {
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 1957
1975 visitTypedef(Typedef node) { 1958 visitTypedef(Typedef node) {
1976 // Do not typecheck [Typedef] nodes. 1959 // Do not typecheck [Typedef] nodes.
1977 } 1960 }
1978 1961
1979 visitNode(Node node) { 1962 visitNode(Node node) {
1980 compiler.internalError(node, 1963 compiler.internalError(node,
1981 'Unexpected node ${node.getObjectDescription()} in the type checker.'); 1964 'Unexpected node ${node.getObjectDescription()} in the type checker.');
1982 } 1965 }
1983 } 1966 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/tree/unparser.dart ('k') | pkg/compiler/lib/src/universe/selector.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698