OLD | NEW |
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 // Test that parameters keep their names in the output. | 4 // Test that parameters keep their names in the output. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import 'compiler_helper.dart'; | 7 import 'compiler_helper.dart'; |
8 | 8 |
9 const String FOO = r""" | 9 const String FOO = r""" |
10 void foo(var a, var b) { | 10 void foo(var a, var b) { |
11 } | 11 } |
12 """; | 12 """; |
13 | 13 |
14 const String BAR = r""" | 14 const String BAR = r""" |
15 void bar(var eval, var $eval) { | 15 void bar(var eval, var $eval) { |
16 } | 16 } |
17 """; | 17 """; |
18 | 18 |
19 const String PARAMETER_AND_TEMP = r""" | 19 const String PARAMETER_AND_TEMP = r""" |
20 void bar(var t0, var b) { | 20 void bar(var t0, var b) { |
21 { | 21 { |
22 var t0 = 2; | 22 var t0 = 2; |
23 if (b) { | 23 if (b) { |
| 24 bar(1, 2); |
24 t0 = 4; | 25 t0 = 4; |
25 } else { | 26 } else { |
26 t0 = 3; | 27 t0 = 3; |
27 } | 28 } |
28 print(t0); | 29 print(t0); |
29 } | 30 } |
30 print(t0); | 31 print(t0); |
31 } | 32 } |
32 """; | 33 """; |
33 | 34 |
(...skipping 21 matching lines...) Expand all Loading... |
55 print(a); | 56 print(a); |
56 } | 57 } |
57 print(a); | 58 print(a); |
58 } | 59 } |
59 """; | 60 """; |
60 | 61 |
61 const String PARAMETER_INIT = r""" | 62 const String PARAMETER_INIT = r""" |
62 int foo(var start, bool test) { | 63 int foo(var start, bool test) { |
63 var result = start; | 64 var result = start; |
64 if (test) { | 65 if (test) { |
| 66 foo(1, 2); |
65 result = 42; | 67 result = 42; |
66 } | 68 } |
67 print(result); | 69 print(result); |
68 } | 70 } |
69 """; | 71 """; |
70 | 72 |
71 main() { | 73 main() { |
72 String generated = compile(FOO, entry: 'foo'); | 74 String generated = compile(FOO, entry: 'foo'); |
73 Expect.isTrue(generated.contains(r"function(a, b) {")); | 75 Expect.isTrue(generated.contains(r"function(a, b) {")); |
74 | 76 |
75 generated = compile(BAR, entry: 'bar'); | 77 generated = compile(BAR, entry: 'bar'); |
76 Expect.isTrue(generated.contains(r"function($eval, $$eval) {")); | 78 Expect.isTrue(generated.contains(r"function($eval, $$eval) {")); |
77 | 79 |
78 generated = compile(PARAMETER_AND_TEMP, entry: 'bar'); | 80 generated = compile(PARAMETER_AND_TEMP, entry: 'bar'); |
79 Expect.isTrue(generated.contains(r"print(t00)")); | 81 Expect.isTrue(generated.contains(r"print(t00)")); |
80 // Check that the second 't0' got another name. | 82 // Check that the second 't0' got another name. |
81 Expect.isTrue(generated.contains(r"print(t01)")); | 83 Expect.isTrue(generated.contains(r"print(t01)")); |
82 | 84 |
83 generated = compile(MULTIPLE_PHIS_ONE_LOCAL, entry: 'foo'); | 85 generated = compile(MULTIPLE_PHIS_ONE_LOCAL, entry: 'foo'); |
84 Expect.isTrue(generated.contains("var a;")); | 86 Expect.isTrue(generated.contains("var a;")); |
85 // Check that there is only one var declaration. | 87 // Check that there is only one var declaration. |
86 checkNumberOfMatches(new RegExp("var").allMatches(generated).iterator, 1); | 88 checkNumberOfMatches(new RegExp("var").allMatches(generated).iterator, 1); |
87 | 89 |
88 generated = compile(NO_LOCAL, entry: 'foo'); | 90 generated = compile(NO_LOCAL, entry: 'foo'); |
89 Expect.isFalse(generated.contains('var')); | 91 Expect.isFalse(generated.contains('var')); |
90 | 92 |
91 generated = compile(PARAMETER_INIT, entry: 'foo'); | 93 generated = compile(PARAMETER_INIT, entry: 'foo'); |
92 Expect.isTrue(generated.contains('var result = test === true ? 42 : start')); | |
93 // Check that there is only one var declaration. | 94 // Check that there is only one var declaration. |
94 checkNumberOfMatches(new RegExp("var").allMatches(generated).iterator, 1); | 95 checkNumberOfMatches(new RegExp("var").allMatches(generated).iterator, 1); |
95 } | 96 } |
OLD | NEW |