Skip to content

Commit 20fb8cb

Browse files
munificentcommit-bot@chromium.org
authored andcommitted
Migrate language_2/rewrite to NNBD.
Change-Id: I9a8e4fddebeb7a4e467e86256cd89204bfedf07d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150696 Auto-Submit: Bob Nystrom <[email protected]> Commit-Queue: Erik Ernst <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent 7c9f7f4 commit 20fb8cb

17 files changed

+1458
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import "package:expect/expect.dart";
6+
7+
bar(x, y) {}
8+
9+
foo(b) {
10+
var x, y;
11+
if (b) {
12+
x = 1;
13+
y = 2;
14+
} else {
15+
x = 2;
16+
y = 1;
17+
}
18+
bar(x, y);
19+
bar(x, y);
20+
return x;
21+
}
22+
23+
main() {
24+
Expect.equals(1, foo(true));
25+
Expect.equals(2, foo(false));
26+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import "package:expect/expect.dart";
6+
7+
var global = 0;
8+
9+
class Foo {
10+
var field = 0;
11+
static var staticField = 0;
12+
}
13+
14+
field_compound1(obj) {
15+
return obj.field = obj.field + 5;
16+
}
17+
18+
field_compound2(obj) {
19+
return obj.field = obj.field + 1;
20+
}
21+
22+
field_compound3(obj) {
23+
return obj.field = obj.field - 1;
24+
}
25+
26+
field_compound4(obj) {
27+
return obj.field = obj.field * 1;
28+
}
29+
30+
static_compound1() {
31+
return Foo.staticField = Foo.staticField + 5;
32+
}
33+
34+
static_compound2() {
35+
return Foo.staticField = Foo.staticField + 1;
36+
}
37+
38+
static_compound3() {
39+
return Foo.staticField = Foo.staticField - 1;
40+
}
41+
42+
static_compound4() {
43+
return Foo.staticField = Foo.staticField * 1;
44+
}
45+
46+
global_compound1() {
47+
return global = global + 5;
48+
}
49+
50+
global_compound2() {
51+
return global = global + 1;
52+
}
53+
54+
global_compound3() {
55+
return global = global - 1;
56+
}
57+
58+
global_compound4() {
59+
return global = global * 1;
60+
}
61+
62+
local_compound1(x) {
63+
x = x + 5;
64+
if (x > 0) {
65+
return x;
66+
}
67+
return -x;
68+
}
69+
70+
local_compound2(x) {
71+
x = x + 1;
72+
if (x > 0) {
73+
return x;
74+
}
75+
return -x;
76+
}
77+
78+
local_compound3(x) {
79+
x = x - 1;
80+
if (x > 0) {
81+
return x;
82+
}
83+
return -x;
84+
}
85+
86+
local_compound4(x) {
87+
x = x * 1;
88+
if (x > 0) {
89+
return x;
90+
}
91+
return -x;
92+
}
93+
94+
main() {
95+
var obj = new Foo();
96+
Expect.equals(5, field_compound1(obj));
97+
Expect.equals(5, obj.field);
98+
Expect.equals(6, field_compound2(obj));
99+
Expect.equals(6, obj.field);
100+
Expect.equals(5, field_compound3(obj));
101+
Expect.equals(5, obj.field);
102+
Expect.equals(5, field_compound4(obj));
103+
Expect.equals(5, obj.field);
104+
105+
Expect.equals(5, static_compound1());
106+
Expect.equals(5, Foo.staticField);
107+
Expect.equals(6, static_compound2());
108+
Expect.equals(6, Foo.staticField);
109+
Expect.equals(5, static_compound3());
110+
Expect.equals(5, Foo.staticField);
111+
Expect.equals(5, static_compound4());
112+
Expect.equals(5, Foo.staticField);
113+
114+
Expect.equals(5, global_compound1());
115+
Expect.equals(5, global);
116+
Expect.equals(6, global_compound2());
117+
Expect.equals(6, global);
118+
Expect.equals(5, global_compound3());
119+
Expect.equals(5, global);
120+
Expect.equals(5, global_compound4());
121+
Expect.equals(5, global);
122+
123+
Expect.equals(8, local_compound1(3));
124+
Expect.equals(3, local_compound1(-8));
125+
Expect.equals(4, local_compound2(3));
126+
Expect.equals(7, local_compound2(-8));
127+
Expect.equals(2, local_compound3(3));
128+
Expect.equals(9, local_compound3(-8));
129+
Expect.equals(3, local_compound4(3));
130+
Expect.equals(8, local_compound4(-8));
131+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'package:expect/expect.dart';
6+
7+
var global = 0;
8+
9+
bar() {
10+
global += 1;
11+
}
12+
13+
baz() {
14+
global += 100;
15+
}
16+
17+
foo(x, y, z) {
18+
if ((x ? false : true) ? y : z) {
19+
bar();
20+
bar();
21+
} else {
22+
baz();
23+
baz();
24+
}
25+
}
26+
27+
foo2(x, y, z) {
28+
return (x ? false : true) ? y : z;
29+
}
30+
31+
foo3(x, y, z) {
32+
if (x ? (z ? false : true) : (y ? false : true)) {
33+
baz();
34+
baz();
35+
} else {
36+
bar();
37+
bar();
38+
}
39+
}
40+
41+
main() {
42+
foo(true, true, true);
43+
Expect.equals(2, global);
44+
45+
foo(true, true, false);
46+
Expect.equals(202, global);
47+
48+
foo(true, false, true);
49+
Expect.equals(204, global);
50+
51+
foo(true, false, false);
52+
Expect.equals(404, global);
53+
54+
foo(false, true, true);
55+
Expect.equals(406, global);
56+
57+
foo(false, true, false);
58+
Expect.equals(408, global);
59+
60+
foo(false, false, true);
61+
Expect.equals(608, global);
62+
63+
foo(false, false, false);
64+
Expect.equals(808, global);
65+
66+
Expect.equals(true, foo2(true, true, true));
67+
Expect.equals(false, foo2(true, true, false));
68+
Expect.equals(true, foo2(true, false, true));
69+
Expect.equals(false, foo2(true, false, false));
70+
Expect.equals(true, foo2(false, true, true));
71+
Expect.equals(true, foo2(false, true, false));
72+
Expect.equals(false, foo2(false, false, true));
73+
Expect.equals(false, foo2(false, false, false));
74+
75+
global = 0;
76+
foo3(true, true, true);
77+
Expect.equals(2, global);
78+
79+
foo3(true, true, false);
80+
Expect.equals(202, global);
81+
82+
foo3(true, false, true);
83+
Expect.equals(204, global);
84+
85+
foo3(true, false, false);
86+
Expect.equals(404, global);
87+
88+
foo3(false, true, true);
89+
Expect.equals(406, global);
90+
91+
foo3(false, true, false);
92+
Expect.equals(408, global);
93+
94+
foo3(false, false, true);
95+
Expect.equals(608, global);
96+
97+
foo3(false, false, false);
98+
Expect.equals(808, global);
99+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import "package:expect/expect.dart";
6+
7+
var counter = 0;
8+
var global = 0;
9+
10+
test() {
11+
++counter;
12+
return counter <= 2;
13+
}
14+
15+
first() {
16+
global = global + 1;
17+
}
18+
19+
second() {
20+
global = global * 2;
21+
}
22+
23+
foo() {
24+
while (test()) {
25+
first();
26+
second();
27+
}
28+
}
29+
30+
main() {
31+
foo();
32+
Expect.equals(6, global);
33+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import "package:expect/expect.dart";
6+
7+
var global = 0;
8+
9+
effect() {
10+
global = 1;
11+
}
12+
13+
baz(b) {
14+
return b;
15+
}
16+
17+
foo(b) {
18+
if (b) {
19+
// do nothing
20+
} else {
21+
effect();
22+
}
23+
return baz(b);
24+
}
25+
26+
foo2(b) {
27+
if (b) {
28+
// do nothing (but implicit return may get inlined up here)
29+
} else {
30+
effect();
31+
}
32+
}
33+
34+
main() {
35+
global = 0;
36+
Expect.equals(true, foo(true));
37+
Expect.equals(0, global);
38+
39+
global = 0;
40+
Expect.equals(false, foo(false));
41+
Expect.equals(1, global);
42+
43+
global = 0;
44+
foo2(true);
45+
Expect.equals(0, global);
46+
47+
global = 0;
48+
foo2(false);
49+
Expect.equals(1, global);
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import "package:expect/expect.dart";
6+
7+
var global = 0;
8+
9+
bar() {
10+
global = 1;
11+
}
12+
13+
baz() {
14+
global = 2;
15+
}
16+
17+
return_const(b) {
18+
if (b) {
19+
bar();
20+
return 1;
21+
} else {
22+
baz();
23+
return 1;
24+
}
25+
}
26+
27+
return_var(b, x) {
28+
if (b) {
29+
bar();
30+
return x;
31+
} else {
32+
baz();
33+
return x;
34+
}
35+
}
36+
37+
main() {
38+
return_const(true);
39+
Expect.equals(1, global);
40+
return_const(false);
41+
Expect.equals(2, global);
42+
43+
Expect.equals(4, return_var(true, 4));
44+
Expect.equals(1, global);
45+
Expect.equals(5, return_var(false, 5));
46+
Expect.equals(2, global);
47+
}

0 commit comments

Comments
 (0)