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 #import("dart:uri"); | 5 #import("dart:uri"); |
6 | 6 |
7 #import("../../../lib/compiler/implementation/ssa/ssa.dart"); | 7 #import("../../../lib/compiler/implementation/ssa/ssa.dart"); |
8 | 8 |
9 #import('compiler_helper.dart'); | 9 #import('compiler_helper.dart'); |
10 #import('parser_helper.dart'); | 10 #import('parser_helper.dart'); |
11 | 11 |
12 void compileAndFind(String code, | 12 void compileAndFind(String code, |
13 String className, | 13 String className, |
14 String memberName, | 14 String memberName, |
15 check(compiler, element)) { | 15 check(compiler, element)) { |
16 Uri uri = new Uri.fromComponents(scheme: 'source'); | 16 Uri uri = new Uri.fromComponents(scheme: 'source'); |
17 var compiler = compilerFor(code, uri); | 17 var compiler = compilerFor(code, uri); |
18 compiler.runCompiler(uri); | 18 compiler.runCompiler(uri); |
19 var cls = findElement(compiler, className); | 19 var cls = findElement(compiler, className); |
20 var member = cls.lookupLocalMember(buildSourceString(memberName)); | 20 var member = cls.lookupLocalMember(buildSourceString(memberName)); |
21 return check(compiler.backend, member); | 21 return check(compiler.backend, member); |
22 } | 22 } |
23 | 23 |
24 final String TEST_ONE = @""" | 24 const String TEST_ONE = @""" |
25 class A { | 25 class A { |
26 x(p) => p; | 26 x(p) => p; |
27 } | 27 } |
28 main() { new A().x("s"); } | 28 main() { new A().x("s"); } |
29 """; | 29 """; |
30 | 30 |
31 final String TEST_TWO = @""" | 31 const String TEST_TWO = @""" |
32 class A { | 32 class A { |
33 x(p) => p; | 33 x(p) => p; |
34 } | 34 } |
35 main() { new A().x(1); } | 35 main() { new A().x(1); } |
36 """; | 36 """; |
37 | 37 |
38 final String TEST_THREE = @""" | 38 const String TEST_THREE = @""" |
39 class A { | 39 class A { |
40 x(p) => x(p - 1); | 40 x(p) => x(p - 1); |
41 } | 41 } |
42 main() { new A().x(1); } | 42 main() { new A().x(1); } |
43 """; | 43 """; |
44 | 44 |
45 final String TEST_FOUR = @""" | 45 const String TEST_FOUR = @""" |
46 class A { | 46 class A { |
47 x(p) => x(p - 1); | 47 x(p) => x(p - 1); |
48 } | 48 } |
49 main() { new A().x(1.0); } | 49 main() { new A().x(1.0); } |
50 """; | 50 """; |
51 | 51 |
52 final String TEST_FIVE = @""" | 52 const String TEST_FIVE = @""" |
53 class A { | 53 class A { |
54 x(p) => p; | 54 x(p) => p; |
55 } | 55 } |
56 main() { | 56 main() { |
57 new A().x(1); | 57 new A().x(1); |
58 new A().x(1.0); | 58 new A().x(1.0); |
59 } | 59 } |
60 """; | 60 """; |
61 | 61 |
62 final String TEST_SIX = @""" | 62 const String TEST_SIX = @""" |
63 class A { | 63 class A { |
64 x(p) => p; | 64 x(p) => p; |
65 } | 65 } |
66 main() { | 66 main() { |
67 new A().x(1.0); | 67 new A().x(1.0); |
68 new A().x(1); | 68 new A().x(1); |
69 } | 69 } |
70 """; | 70 """; |
71 | 71 |
72 final String TEST_SEVEN = @""" | 72 const String TEST_SEVEN = @""" |
73 class A { | 73 class A { |
74 x(p) => x("x"); | 74 x(p) => x("x"); |
75 } | 75 } |
76 main() { | 76 main() { |
77 new A().x(1); | 77 new A().x(1); |
78 } | 78 } |
79 """; | 79 """; |
80 | 80 |
81 final String TEST_EIGHT = @""" | 81 const String TEST_EIGHT = @""" |
82 class A { | 82 class A { |
83 x(p1, p2) => x(p1, "x"); | 83 x(p1, p2) => x(p1, "x"); |
84 } | 84 } |
85 main() { | 85 main() { |
86 new A().x(1, 2); | 86 new A().x(1, 2); |
87 } | 87 } |
88 """; | 88 """; |
89 | 89 |
90 final String TEST_NINE = @""" | 90 const String TEST_NINE = @""" |
91 class A { | 91 class A { |
92 x(p1, p2) => x(p1, p2); | 92 x(p1, p2) => x(p1, p2); |
93 } | 93 } |
94 main() { | 94 main() { |
95 new A().x(1, 2); | 95 new A().x(1, 2); |
96 } | 96 } |
97 """; | 97 """; |
98 | 98 |
99 final String TEST_TEN = @""" | 99 const String TEST_TEN = @""" |
100 class A { | 100 class A { |
101 x(p1, p2) => x(p1, p2); | 101 x(p1, p2) => x(p1, p2); |
102 } | 102 } |
103 void f(p) { | 103 void f(p) { |
104 p.x("x", "y"); | 104 p.x("x", "y"); |
105 } | 105 } |
106 main() { | 106 main() { |
107 f(null); | 107 f(null); |
108 new A().x(1, 2); | 108 new A().x(1, 2); |
109 } | 109 } |
110 """; | 110 """; |
111 | 111 |
112 final String TEST_ELEVEN = @""" | 112 const String TEST_ELEVEN = @""" |
113 class A { | 113 class A { |
114 x(p1, p2) => x(1, 2); | 114 x(p1, p2) => x(1, 2); |
115 } | 115 } |
116 main() { | 116 main() { |
117 new A().x("x", "y"); | 117 new A().x("x", "y"); |
118 } | 118 } |
119 """; | 119 """; |
120 | 120 |
121 final String TEST_TWELVE = @""" | 121 const String TEST_TWELVE = @""" |
122 class A { | 122 class A { |
123 x(p1, p2) => 1; | 123 x(p1, p2) => 1; |
124 } | 124 } |
125 class B { | 125 class B { |
126 x(p1, p2) => x(1, 2); | 126 x(p1, p2) => x(1, 2); |
127 } | 127 } |
128 f(p) => p.x(1); | 128 f(p) => p.x(1); |
129 main() { | 129 main() { |
130 var x; | 130 var x; |
131 new A().x("x", "y"); | 131 new A().x("x", "y"); |
132 f(x); | 132 f(x); |
133 } | 133 } |
134 """; | 134 """; |
135 | 135 |
136 final String TEST_13 = @""" | 136 const String TEST_13 = @""" |
137 class A { | 137 class A { |
138 x(p1, [p2 = 1]) => 1; | 138 x(p1, [p2 = 1]) => 1; |
139 } | 139 } |
140 main() { | 140 main() { |
141 new A().x("x", 1); | 141 new A().x("x", 1); |
142 new A().x("x"); | 142 new A().x("x"); |
143 } | 143 } |
144 """; | 144 """; |
145 | 145 |
146 void runTest(String test, [List<HType> expectedTypes = null]) { | 146 void runTest(String test, [List<HType> expectedTypes = null]) { |
(...skipping 24 matching lines...) Expand all Loading... |
171 runTest(TEST_NINE, [HType.INTEGER, HType.INTEGER]); | 171 runTest(TEST_NINE, [HType.INTEGER, HType.INTEGER]); |
172 runTest(TEST_TEN); | 172 runTest(TEST_TEN); |
173 runTest(TEST_ELEVEN); | 173 runTest(TEST_ELEVEN); |
174 runTest(TEST_TWELVE); | 174 runTest(TEST_TWELVE); |
175 runTest(TEST_13); | 175 runTest(TEST_13); |
176 } | 176 } |
177 | 177 |
178 void main() { | 178 void main() { |
179 test(); | 179 test(); |
180 } | 180 } |
OLD | NEW |