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

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

Issue 11414130: Naive handling of List#[] and List#[]= (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove dead code Created 7 years, 11 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 // 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 import "dart:uri"; 5 import "dart:uri";
6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt'; 7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt';
8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; 8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart';
9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; 9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart';
10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; 10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart';
(...skipping 30 matching lines...) Expand all
41 class AnalysisResult { 41 class AnalysisResult {
42 MockCompiler compiler; 42 MockCompiler compiler;
43 ConcreteTypesInferrer inferrer; 43 ConcreteTypesInferrer inferrer;
44 Node ast; 44 Node ast;
45 45
46 BaseType int; 46 BaseType int;
47 BaseType double; 47 BaseType double;
48 BaseType num; 48 BaseType num;
49 BaseType bool; 49 BaseType bool;
50 BaseType string; 50 BaseType string;
51 BaseType list; 51 BaseType jsArray;
52 BaseType map; 52 BaseType map;
53 BaseType nullType; 53 BaseType nullType;
54 54
55 AnalysisResult(MockCompiler compiler) : this.compiler = compiler { 55 AnalysisResult(MockCompiler compiler) : this.compiler = compiler {
56 inferrer = compiler.typesTask.concreteTypesInferrer; 56 inferrer = compiler.typesTask.concreteTypesInferrer;
57 int = inferrer.baseTypes.intBaseType; 57 int = inferrer.baseTypes.intBaseType;
58 double = inferrer.baseTypes.doubleBaseType; 58 double = inferrer.baseTypes.doubleBaseType;
59 num = inferrer.baseTypes.numBaseType; 59 num = inferrer.baseTypes.numBaseType;
60 bool = inferrer.baseTypes.boolBaseType; 60 bool = inferrer.baseTypes.boolBaseType;
61 string = inferrer.baseTypes.stringBaseType; 61 string = inferrer.baseTypes.stringBaseType;
62 list = inferrer.baseTypes.listBaseType; 62 jsArray = inferrer.baseTypes.jsArrayBaseType;
63 map = inferrer.baseTypes.mapBaseType; 63 map = inferrer.baseTypes.mapBaseType;
64 nullType = new NullBaseType(); 64 nullType = new NullBaseType();
65 Element mainElement = compiler.mainApp.find(buildSourceString('main')); 65 Element mainElement = compiler.mainApp.find(buildSourceString('main'));
66 ast = mainElement.parseNode(compiler); 66 ast = mainElement.parseNode(compiler);
67 } 67 }
68 68
69 BaseType base(String className) { 69 BaseType base(String className) {
70 final source = buildSourceString(className); 70 final source = buildSourceString(className);
71 return new ClassBaseType(compiler.mainApp.find(source)); 71 return new ClassBaseType(compiler.mainApp.find(source));
72 } 72 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 operator *(x); 151 operator *(x);
152 operator -(x); 152 operator -(x);
153 operator ==(x); 153 operator ==(x);
154 } 154 }
155 abstract class int extends num { } 155 abstract class int extends num { }
156 abstract class double extends num { } 156 abstract class double extends num { }
157 class bool {} 157 class bool {}
158 class String {} 158 class String {}
159 class Object {} 159 class Object {}
160 class Function {} 160 class Function {}
161 abstract class List {} 161 abstract class List<E> {
162 factory List([int length]);
163 E operator [](int index);
164 void operator []=(int index, E value);
165 }
162 abstract class Map {} 166 abstract class Map {}
163 class Closure {} 167 class Closure {}
164 class Null {} 168 class Null {}
165 class Type {} 169 class Type {}
166 class Dynamic_ {} 170 class Dynamic_ {}
167 bool identical(Object a, Object b) {}'''; 171 bool identical(Object a, Object b) {}''';
168 172
169 AnalysisResult analyze(String code, {int maxConcreteTypeSize: 1000}) { 173 AnalysisResult analyze(String code, {int maxConcreteTypeSize: 1000}) {
170 Uri uri = new Uri.fromComponents(scheme: 'source'); 174 Uri uri = new Uri.fromComponents(scheme: 'source');
171 MockCompiler compiler = new MockCompiler( 175 MockCompiler compiler = new MockCompiler(
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 var x; 675 var x;
672 A(this.x); 676 A(this.x);
673 } 677 }
674 main() { 678 main() {
675 var x = []; 679 var x = [];
676 var y = [1, "a", null, new A(42)]; 680 var y = [1, "a", null, new A(42)];
677 x; y; 681 x; y;
678 } 682 }
679 """; 683 """;
680 AnalysisResult result = analyze(source); 684 AnalysisResult result = analyze(source);
681 result.checkNodeHasType('x', [result.list]); 685 result.checkNodeHasType('x', [result.jsArray]);
682 result.checkNodeHasType('y', [result.list]); 686 result.checkNodeHasType('y', [result.jsArray]);
683 result.checkFieldHasType('A', 'x', [result.int]); 687 result.checkFieldHasType('A', 'x', [result.int]);
684 } 688 }
685 689
686 testMapLiterals() { 690 testMapLiterals() {
687 final String source = r""" 691 final String source = r"""
688 class A { 692 class A {
689 var x; 693 var x;
690 A(this.x); 694 A(this.x);
691 } 695 }
692 main() { 696 main() {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 var bar = new A() != 2; 887 var bar = new A() != 2;
884 var baz = new B() != 2; 888 var baz = new B() != 2;
885 foo; bar; baz; 889 foo; bar; baz;
886 } 890 }
887 """; 891 """;
888 AnalysisResult result = analyze(source); 892 AnalysisResult result = analyze(source);
889 result.checkNodeHasType('foo', [result.bool]); 893 result.checkNodeHasType('foo', [result.bool]);
890 result.checkNodeHasType('bar', [result.bool]); 894 result.checkNodeHasType('bar', [result.bool]);
891 result.checkNodeHasType('baz', []); 895 result.checkNodeHasType('baz', []);
892 // TODO(polux): the following result should be [:[null, string]:], see 896 // TODO(polux): the following result should be [:[null, string]:], see
893 // fieldInitialization(). 897 // testFieldInitialization().
894 result.checkFieldHasType('A', 'witness', [result.string]); 898 result.checkFieldHasType('A', 'witness', [result.string]);
895 } 899 }
896 900
897 testFieldInitialization() { 901 testFieldInitialization() {
898 final String source = r""" 902 final String source = r"""
899 class A { 903 class A {
900 var x; 904 var x;
901 var y = 1; 905 var y = 1;
902 } 906 }
903 main () { 907 main () {
904 new A(); 908 new A();
905 } 909 }
906 """; 910 """;
907 AnalysisResult result = analyze(source); 911 AnalysisResult result = analyze(source);
908 result.checkFieldHasType('A', 'x', [result.nullType]); 912 result.checkFieldHasType('A', 'x', [result.nullType]);
909 result.checkFieldHasType('A', 'y', [result.int]); 913 result.checkFieldHasType('A', 'y', [result.int]);
910 } 914 }
911 915
916 testLists() {
917 final String source = r"""
918 main() {
919 new List();
920 var l1 = [1.2];
921 var l2 = [];
922 l1['a'] = 42; // raises an error, so int should not be recorded
923 l1[1] = 'abc';
924 "__dynamic_for_test"[1] = true;
925 var x = l1[1];
926 var y = l2[1];
927 var z = l1['foo'];
928 x; y; z;
929 }""";
930 AnalysisResult result = analyze(source);
931 result.checkNodeHasType('x', [result.double, result.string, result.bool]);
932 result.checkNodeHasType('y', [result.double, result.string, result.bool]);
933 result.checkNodeHasType('z', []);
934 }
935
936 testListWithCapacity() {
karlklose 2013/01/23 13:16:55 Can you add a test with elements like in testLists
937 final String source = r"""
938 main() {
939 var l = new List(10);
940 var x = l[0];
941 x;
942 }""";
943 AnalysisResult result = analyze(source);
944 result.checkNodeHasType('x', [result.nullType]);
945 }
946
947 testEmptyList() {
948 final String source = r"""
949 main() {
950 var l = new List();
951 var x = l[0];
952 x;
953 }""";
954 AnalysisResult result = analyze(source);
955 result.checkNodeHasType('x', []);
956 }
957
912 testSendWithWrongArity() { 958 testSendWithWrongArity() {
913 final String source = r""" 959 final String source = r"""
914 f(x) { } 960 f(x) { }
915 class A { g(x) { } } 961 class A { g(x) { } }
916 main () { 962 main () {
917 var x = f(); 963 var x = f();
918 var y = f(1, 2); 964 var y = f(1, 2);
919 var z = new A().g(); 965 var z = new A().g();
920 var w = new A().g(1, 2); 966 var w = new A().g(1, 2);
921 x; y; z; w; 967 x; y; z; w;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 testOperators(); 1053 testOperators();
1008 testCompoundOperators1(); 1054 testCompoundOperators1();
1009 testCompoundOperators2(); 1055 testCompoundOperators2();
1010 testSetIndexOperator(); 1056 testSetIndexOperator();
1011 testInequality(); 1057 testInequality();
1012 // testFieldInitialization(); // TODO(polux) 1058 // testFieldInitialization(); // TODO(polux)
1013 testSendWithWrongArity(); 1059 testSendWithWrongArity();
1014 testBigTypesWidening1(); 1060 testBigTypesWidening1();
1015 testBigTypesWidening2(); 1061 testBigTypesWidening2();
1016 testDynamicIsAbsorbing(); 1062 testDynamicIsAbsorbing();
1063 testLists();
1064 testListWithCapacity();
1065 testEmptyList();
1017 } 1066 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698