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

Side by Side Diff: tests/compiler/dart2js/cpa_inference_test.dart

Issue 11093078: - Add support for binary operators (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: sync to head Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 #import("dart:uri"); 1 #import("dart:uri");
2 #import("../../../lib/compiler/implementation/elements/elements.dart"); 2 #import("../../../lib/compiler/implementation/elements/elements.dart");
3 #import('../../../lib/compiler/implementation/scanner/scannerlib.dart'); 3 #import('../../../lib/compiler/implementation/scanner/scannerlib.dart');
4 #import('../../../lib/compiler/implementation/source_file.dart'); 4 #import('../../../lib/compiler/implementation/source_file.dart');
5 #import('../../../lib/compiler/implementation/types/types.dart'); 5 #import('../../../lib/compiler/implementation/types/types.dart');
6 #import('../../../lib/compiler/implementation/tree/tree.dart'); 6 #import('../../../lib/compiler/implementation/tree/tree.dart');
7 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg"); 7 #import("../../../lib/compiler/implementation/leg.dart", prefix: "leg");
8 8
9 #import("parser_helper.dart"); 9 #import("parser_helper.dart");
10 #import("compiler_helper.dart"); 10 #import("compiler_helper.dart");
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 } 35 }
36 36
37 class AnalysisResult { 37 class AnalysisResult {
38 MockCompiler compiler; 38 MockCompiler compiler;
39 ConcreteTypesInferrer inferrer; 39 ConcreteTypesInferrer inferrer;
40 Node ast; 40 Node ast;
41 41
42 BaseType int; 42 BaseType int;
43 BaseType double; 43 BaseType double;
44 BaseType num;
44 BaseType bool; 45 BaseType bool;
45 BaseType string; 46 BaseType string;
46 BaseType list; 47 BaseType list;
47 BaseType map; 48 BaseType map;
48 BaseType nullType; 49 BaseType nullType;
49 50
50 AnalysisResult(MockCompiler compiler) : this.compiler = compiler { 51 AnalysisResult(MockCompiler compiler) : this.compiler = compiler {
51 inferrer = compiler.typesTask.concreteTypesInferrer; 52 inferrer = compiler.typesTask.concreteTypesInferrer;
52 int = inferrer.baseTypes.intBaseType; 53 int = inferrer.baseTypes.intBaseType;
53 double = inferrer.baseTypes.doubleBaseType; 54 double = inferrer.baseTypes.doubleBaseType;
55 num = inferrer.baseTypes.numBaseType;
54 bool = inferrer.baseTypes.boolBaseType; 56 bool = inferrer.baseTypes.boolBaseType;
55 string = inferrer.baseTypes.stringBaseType; 57 string = inferrer.baseTypes.stringBaseType;
56 list = inferrer.baseTypes.listBaseType; 58 list = inferrer.baseTypes.listBaseType;
57 map = inferrer.baseTypes.mapBaseType; 59 map = inferrer.baseTypes.mapBaseType;
58 nullType = new NullBaseType(); 60 nullType = new NullBaseType();
59 Element mainElement = compiler.mainApp.find(buildSourceString('main')); 61 Element mainElement = compiler.mainApp.find(buildSourceString('main'));
60 ast = mainElement.parseNode(compiler); 62 ast = mainElement.parseNode(compiler);
61 } 63 }
62 64
63 BaseType base(String className) { 65 BaseType base(String className) {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 var x = f(); 365 var x = f();
364 var y = g(); 366 var y = g();
365 x; y; 367 x; y;
366 } 368 }
367 """; 369 """;
368 AnalysisResult result = analyze(source); 370 AnalysisResult result = analyze(source);
369 result.checkNodeHasType('x', [result.int, result.nullType]); 371 result.checkNodeHasType('x', [result.int, result.nullType]);
370 result.checkNodeHasType('y', [result.nullType]); 372 result.checkNodeHasType('y', [result.nullType]);
371 } 373 }
372 374
375 testArith() {
karlklose 2012/10/23 10:58:15 testArith -> testArithmethicOperators.
polux 2012/10/25 12:02:01 Done.
376 String source(op) {
377 return """
378 main() {
379 var a = 1 $op 2;
380 var b = 1 $op 2.0;
381 var c = 1.0 $op 2;
382 var d = 1.0 $op 2.0;
383 var e = (1 $op 2.0) $op 1;
384 var f = 1 $op (1 $op 2.0);
385 var g = (1 $op 2.0) $op 1.0;
386 var h = 1.0 $op (1 $op 2);
387 a; b; c; d; e; f; g; h;
karlklose 2012/10/23 10:58:15 Can you add positive nesting tests, like (1 op 2)
polux 2012/10/25 12:02:01 Done.
388 }""";
389 }
390 for (String op in ['+', '*', '-']) {
391 AnalysisResult result = analyze(source(op));
392 result.checkNodeHasType('a', [result.int]);
393 result.checkNodeHasType('b', [result.num]);
394 result.checkNodeHasType('c', [result.num]);
395 result.checkNodeHasType('d', [result.double]);
396 result.checkNodeHasType('e', [result.num]);
397 result.checkNodeHasType('f', [result.num]);
398 result.checkNodeHasType('g', [result.num]);
399 result.checkNodeHasType('h', [result.num]);
400 }
401 }
402
403 testOperators() {
404 final String source = r"""
405 class A {
406 operator <(x) => 42;
407 operator <<(x) => "a";
408 }
409 main() {
410 var x = new A() < "foo";
411 var y = new A() << "foo";
412 x; y;
413 }
414 """;
415 AnalysisResult result = analyze(source);
416 result.checkNodeHasType('x', [result.int]);
417 result.checkNodeHasType('y', [result.string]);
418 }
419
373 void main() { 420 void main() {
374 testLiterals(); 421 testLiterals();
375 testRedefinition(); 422 testRedefinition();
376 testIfThenElse(); 423 testIfThenElse();
377 testTernaryIf(); 424 testTernaryIf();
378 testWhile(); 425 testWhile();
379 testNonRecusiveFunction(); 426 testNonRecusiveFunction();
380 testRecusiveFunction(); 427 testRecusiveFunction();
381 testMutuallyRecusiveFunction(); 428 testMutuallyRecusiveFunction();
382 testConstructor(); 429 testConstructor();
383 testGetters(); 430 testGetters();
384 testSetters(); 431 testSetters();
385 testNamedParameters(); 432 testNamedParameters();
386 testListLiterals(); 433 testListLiterals();
387 testMapLiterals(); 434 testMapLiterals();
388 testReturn(); 435 testReturn();
389 // testNoReturn(); // right now we infer the empty type instead of null 436 // testNoReturn(); // right now we infer the empty type instead of null
437 testArith();
438 testOperators();
390 } 439 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698