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

Side by Side Diff: frog/tests/leg/src/TypeCheckerTest.dart

Issue 8769012: Start resolving classes and default constructors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #import("../../../leg/leg.dart"); 5 #import("../../../leg/leg.dart");
6 #import("../../../leg/elements/elements.dart"); 6 #import("../../../leg/elements/elements.dart");
7 #import("../../../leg/tree/tree.dart"); 7 #import("../../../leg/tree/tree.dart");
8 #import('../../../leg/scanner/scannerlib.dart'); 8 #import('../../../leg/scanner/scannerlib.dart');
9 #import("../../../leg/util/util.dart"); 9 #import("../../../leg/util/util.dart");
10 #import("mock_compiler.dart");
10 #import("parser_helper.dart"); 11 #import("parser_helper.dart");
11 12
12 main() { 13 main() {
13 testSimpleTypes(); 14 testSimpleTypes();
14 testReturn(); 15 testReturn();
15 testFor(); 16 testFor();
16 testWhile(); 17 testWhile();
17 testOperators(); 18 testOperators();
18 } 19 }
19 20
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 116
116 117
117 final String CORELIB = 118 final String CORELIB =
118 'lt() {} add() {} sub() {} mul() {} div() {} tdiv() {} mod() {}' + 119 'lt() {} add() {} sub() {} mul() {} div() {} tdiv() {} mod() {}' +
119 ' neg() {} shl() {} shr() {} eq() {} le() {} gt() {} ge() {}' + 120 ' neg() {} shl() {} shr() {} eq() {} le() {} gt() {} ge() {}' +
120 ' or() {} and() {} not() {}'; 121 ' or() {} and() {} not() {}';
121 122
122 Node parseExpression(String text) => 123 Node parseExpression(String text) =>
123 parseBodyCode(text, (parser, token) => parser.parseExpression(token)); 124 parseBodyCode(text, (parser, token) => parser.parseExpression(token));
124 125
125 class MockCompiler extends Compiler {
126 List<MessageKind> warnings;
127 Node parsedTree;
128
129 MockCompiler() : super(null), warnings = [];
130
131 void reportWarning(Node node, var warning) {
132 warnings.add(warning.message.kind);
133 }
134
135 void clearWarnings() {
136 warnings = [];
137 }
138
139 parseScript(String text) {
140 for (Link<Element> link = parseUnit(text, this);
141 !link.isEmpty();
142 link = link.tail) {
143 universe.define(link.head);
144 }
145 }
146 }
147
148 // TODO(karlklose): implement with closures instead of global variables. 126 // TODO(karlklose): implement with closures instead of global variables.
149 void setup() { 127 void setup() {
150 compiler = new MockCompiler(); 128 compiler = new MockCompiler();
151 types = new Types(); 129 types = new Types();
152 } 130 }
153 131
154 Types types; 132 Types types;
155 MockCompiler compiler; 133 MockCompiler compiler;
156 134
157 Type analyzeType(String text) { 135 Type analyzeType(String text) {
(...skipping 20 matching lines...) Expand all
178 for (Link<Element> elements = listener.topLevelElements; 156 for (Link<Element> elements = listener.topLevelElements;
179 !elements.isEmpty(); 157 !elements.isEmpty();
180 elements = elements.tail) { 158 elements = elements.tail) {
181 compiler.universe.define(elements.head); 159 compiler.universe.define(elements.head);
182 } 160 }
183 161
184 for (Link<Element> elements = listener.topLevelElements; 162 for (Link<Element> elements = listener.topLevelElements;
185 !elements.isEmpty(); 163 !elements.isEmpty();
186 elements = elements.tail) { 164 elements = elements.tail) {
187 Node node = elements.head.parseNode(compiler, compiler); 165 Node node = elements.head.parseNode(compiler, compiler);
188 FullResolverVisitor visitor = new FullResolverVisitor(compiler); 166 TreeElements mapping = compiler.resolver.resolve(node, elements.head);
189 visitor.visit(node);
190 TypeCheckerVisitor checker = 167 TypeCheckerVisitor checker =
191 new TypeCheckerVisitor(compiler, visitor.mapping, types); 168 new TypeCheckerVisitor(compiler, mapping, types);
192 compiler.clearWarnings(); 169 compiler.clearWarnings();
193 checker.type(node); 170 checker.type(node);
194 compareWarningKinds(text, expectedWarnings, compiler.warnings); 171 compareWarningKinds(text, expectedWarnings, compiler.warnings);
195 } 172 }
196 } 173 }
197 174
198 analyze(String text, [expectedWarnings]) { 175 analyze(String text, [expectedWarnings]) {
199 if (expectedWarnings === null) expectedWarnings = []; 176 if (expectedWarnings === null) expectedWarnings = [];
200 if (expectedWarnings is !List) expectedWarnings = [expectedWarnings]; 177 if (expectedWarnings is !List) expectedWarnings = [expectedWarnings];
201 178
202 Token tokens = scan(text); 179 Token tokens = scan(text);
203 180
204 NodeListener listener = new NodeListener(compiler, compiler); 181 NodeListener listener = new NodeListener(compiler, compiler);
205 182
206 Parser parser = new Parser(listener); 183 Parser parser = new Parser(listener);
207 parser.parseStatement(tokens); 184 parser.parseStatement(tokens);
208 Node node = listener.popNode(); 185 Node node = listener.popNode();
209 186
210 compiler.universe = new Universe(); 187 compiler.universe = new Universe();
211 compiler.parseScript(CORELIB); 188 compiler.parseScript(CORELIB);
212 189
213 FullResolverVisitor visitor = new FullResolverVisitor(compiler); 190 TreeElements elements = compiler.resolveNodeStatement(node);
214 visitor.visit(node);
215 TreeElements elements = visitor.mapping;
216 TypeCheckerVisitor checker = new TypeCheckerVisitor(compiler, elements, 191 TypeCheckerVisitor checker = new TypeCheckerVisitor(compiler, elements,
217 types); 192 types);
218 compiler.clearWarnings(); 193 compiler.clearWarnings();
219 checker.type(node); 194 checker.type(node);
220 compareWarningKinds(text, expectedWarnings, compiler.warnings); 195 compareWarningKinds(text, expectedWarnings, compiler.warnings);
221 } 196 }
222 197
223 void compareWarningKinds(String text, expectedWarnings, foundWarnings) { 198 void compareWarningKinds(String text, expectedWarnings, foundWarnings) {
224 var fail = (message) => Expect.fail('$text: $message'); 199 var fail = (message) => Expect.fail('$text: $message');
225 Iterator<MessageKind> expected = expectedWarnings.iterator(); 200 Iterator<MessageKind> expected = expectedWarnings.iterator();
226 Iterator<MessageKind> found = foundWarnings.iterator(); 201 Iterator<WarningMessage> found = foundWarnings.iterator();
227 while (expected.hasNext() && found.hasNext()) { 202 while (expected.hasNext() && found.hasNext()) {
228 Expect.equals(expected.next(), found.next()); 203 Expect.equals(expected.next(), found.next().message.kind);
229 } 204 }
230 if (expected.hasNext()) { 205 if (expected.hasNext()) {
231 do { 206 do {
232 print('Expected warning "${expected.next()}" did not occur'); 207 print('Expected warning "${expected.next()}" did not occur');
233 } while (expected.hasNext()); 208 } while (expected.hasNext());
234 fail('Too few warnings'); 209 fail('Too few warnings');
235 } 210 }
236 if (found.hasNext()) { 211 if (found.hasNext()) {
237 do { 212 do {
238 print('Additional warning "${found.next()}"'); 213 print('Additional warning "${found.next()}"');
239 } while (found.hasNext()); 214 } while (found.hasNext());
240 fail('Too many warnings'); 215 fail('Too many warnings');
241 } 216 }
242 } 217 }
OLDNEW
« frog/leg/typechecker.dart ('K') | « frog/tests/leg/src/ResolverTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698