Skip to content

Commit 928186e

Browse files
committed
Add statement (including block) scope in/inout parameters, and apply that syntax to for (remove : and =), closes hsutter#386
1 parent 1886ed2 commit 928186e

26 files changed

+241
-97
lines changed

regression-tests/mixed-bounds-safety-with-assert-2.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main: () -> int = {
33
v: std::vector<int> = (1, 2, 3, 4, 5);
44
add_42_to_subrange(v, 1, 3);
55

6-
for v do :(i) =
6+
for v do (i)
77
std::cout << i << "\n";
88
}
99

@@ -15,7 +15,7 @@ add_42_to_subrange: (inout rng:_, start:int, end:int)
1515
count := 0;
1616
for rng
1717
next count++
18-
do :(inout i) =
18+
do (inout i)
1919
if start <= count <= end {
2020
i += 42;
2121
}

regression-tests/mixed-bounds-safety-with-assert.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ print_subrange: (rng:_, start:int, end:int) = {
1111
count := 0;
1212
for rng
1313
next count++
14-
do: (i:_) =
14+
do (i)
1515
if start <= count && count <= end {
1616
std::cout << i << "\n";
1717
}

regression-tests/mixed-fixed-type-aliases.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ main: (args) -> int = {
1919
z: u16 = 42;
2020
test(z);
2121

22-
for args do :(arg) =
22+
for args do (arg)
2323
std::cout << arg << "\n";
2424
}

regression-tests/mixed-function-expression-and-std-for-each.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main: () -> int = {
2424
callback
2525
);
2626

27-
for view do :(str:_) = {
27+
for view do (str) {
2828
std::cout << str << "\n";
2929
}
3030
}

regression-tests/mixed-function-expression-and-std-ranges-for-each-with-capture.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <iostream>
77

88
main: () -> int = {
9-
vec: std::vector<std::string>
9+
vec: std::vector<std::string>
1010
= ("hello", "2022");
1111
view: std::span = vec;
1212

@@ -17,6 +17,6 @@ main: () -> int = {
1717
callback := :(inout x:_) = x += "-ish";
1818
std::ranges::for_each( view, callback );
1919

20-
for view do :(str:_) =
20+
for view do (str)
2121
std::cout << str << "\n";
2222
}

regression-tests/mixed-function-expression-and-std-ranges-for-each.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <iostream>
77

88
main: () -> int = {
9-
vec: std::vector<std::string>
9+
vec: std::vector<std::string>
1010
= ("hello", "2022");
1111
view: std::span = vec;
1212

@@ -16,6 +16,6 @@ main: () -> int = {
1616
callback := :(inout x:_) = x += "-ish";
1717
std::ranges::for_each( view, callback );
1818

19-
for view do :(str:_) =
19+
for view do (str)
2020
std::cout << str << "\n";
2121
}

regression-tests/mixed-function-expression-with-pointer-capture.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <iostream>
77

88
main: () -> int = {
9-
vec: std::vector<std::string>
9+
vec: std::vector<std::string>
1010
= ("hello", "2023");
1111
view: std::span = vec;
1212

@@ -18,6 +18,6 @@ main: () -> int = {
1818
callback := :(inout x:_) = x += "-ish";
1919
std::ranges::for_each( view, callback );
2020

21-
for view do :(str:_) =
21+
for view do (str)
2222
std::cout << str << "\n";
2323
}

regression-tests/mixed-function-expression-with-repeated-capture.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <iostream>
77

88
main: () -> int = {
9-
vec: std::vector<std::string>
9+
vec: std::vector<std::string>
1010
= ("hello", "2022");
1111
view: std::span = vec;
1212

@@ -17,6 +17,6 @@ main: () -> int = {
1717
callback := :(inout x:_) = x += "-ish";
1818
std::ranges::for_each( view, callback );
1919

20-
for view do :(str:_) =
20+
for view do (str)
2121
std::cout << str << "\n";
2222
}

regression-tests/mixed-intro-for-with-counter-include-last.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main: () -> int
33
= {
44
v: std::vector<int> = (1, 2, 3, 4, 5);
55
counter := 42;
6-
for v next counter *= 2 do: (i:_) = {
6+
for v next counter *= 2 do (i) {
77
std::cout << i << " " << counter << "\n";
88
}
99
}

regression-tests/pure2-break-continue.cpp2

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ for_continue_inner: () =
161161
{
162162
vi: std::vector = ( 0, 1, 2 );
163163
counter := 0;
164-
for vi next counter++ do :(i) = {
164+
for vi next counter++ do (i) {
165165
vj: std::vector = ( 0, 1, 2 );
166-
inner: for vj do :(j) = {
166+
inner: for vj do (j) {
167167
std::cout << i << j << " ";
168168
if j == 1 {
169169
continue inner;
@@ -179,9 +179,9 @@ for_continue_outer: () =
179179
{
180180
vi: std::vector = ( 0, 1, 2 );
181181
counter := 0;
182-
outer: for vi next counter++ do :(i) = {
182+
outer: for vi next counter++ do (i) {
183183
vj: std::vector = ( 0, 1, 2 );
184-
for vj do :(j) = {
184+
for vj do (j) {
185185
std::cout << i << j << " ";
186186
if j == 1 {
187187
continue outer;
@@ -197,9 +197,9 @@ for_break_inner: () =
197197
{
198198
vi: std::vector = ( 0, 1, 2 );
199199
counter := 0;
200-
for vi next counter++ do :(i) = {
200+
for vi next counter++ do (i) {
201201
vj: std::vector = ( 0, 1, 2 );
202-
inner: for vj do :(j) = {
202+
inner: for vj do (j) {
203203
std::cout << i << j << " ";
204204
if j == 1 {
205205
break inner;
@@ -215,9 +215,9 @@ for_break_outer: () =
215215
{
216216
vi: std::vector = ( 0, 1, 2 );
217217
counter := 0;
218-
outer: for vi next counter++ do :(i) = {
218+
outer: for vi next counter++ do (i) {
219219
vj: std::vector = ( 0, 1, 2 );
220-
for vj do :(j) = {
220+
for vj do (j) {
221221
std::cout << i << j << " ";
222222
if j == 1 {
223223
break outer;

0 commit comments

Comments
 (0)