Skip to content

Commit 4d0cf5b

Browse files
committed
Add support for consecutive function arg lists like f(1)(2), closes #179
1 parent dfcf7e6 commit 4d0cf5b

10 files changed

+42
-12
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
main: () -> int = {
3+
std::cout << std::hash<int>()(0) << std::endl;
4+
return 0;
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

regression-tests/test-results/clang-12/pure2-repeated-call.cpp.output

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

regression-tests/test-results/gcc-10/pure2-repeated-call.cpp.output

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1268118805
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pure2-repeated-call.cpp
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ----- Cpp2 support -----
2+
#define CPP2_USE_MODULES Yes
3+
#include "cpp2util.h"
4+
5+
6+
#line 2 "pure2-repeated-call.cpp2"
7+
[[nodiscard]] auto main() -> int;
8+
9+
//=== Cpp2 definitions ==========================================================
10+
11+
#line 1 "pure2-repeated-call.cpp2"
12+
13+
[[nodiscard]] auto main() -> int{
14+
std::cout << std::hash<int>()(0) << std::endl;
15+
return 0;
16+
}
17+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-repeated-call.cpp2... ok (all Cpp2, passes safety checks)
2+

source/cppfront.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,17 @@ class cppfront
17411741

17421742
auto args = std::optional<text_chunks_with_parens_position>{};
17431743

1744+
auto flush_args = [&] {
1745+
if (args) {
1746+
suffix.emplace_back(")", args.value().close_pos);
1747+
for (auto&& e: args.value().text_chunks) {
1748+
suffix.push_back(e);
1749+
}
1750+
suffix.emplace_back("(", args.value().open_pos);
1751+
args.reset();
1752+
}
1753+
};
1754+
17441755
auto print_to_string = [&](auto& i, auto... more) {
17451756
auto print = std::string{};
17461757
printer.emit_to_string(&print);
@@ -1793,7 +1804,8 @@ class cppfront
17931804
if (!i->expr_list->expressions.empty()) {
17941805
local_args.text_chunks = print_to_text_chunks(*i->expr_list);
17951806
}
1796-
1807+
1808+
flush_args();
17971809
args.emplace(std::move(local_args));
17981810
}
17991811
// Going backwards if we found Dot and there is args variable
@@ -1933,17 +1945,7 @@ class cppfront
19331945
}
19341946
suppress_move_from_last_use = false;
19351947

1936-
if (args) {
1937-
// if after printing core expression args is defined
1938-
// it means that the chaining started by function call
1939-
// we need to print its arguments
1940-
suffix.emplace_back(")", args.value().close_pos);
1941-
for (auto&& e: args.value().text_chunks) {
1942-
suffix.push_back(e);
1943-
}
1944-
suffix.emplace_back("(", args.value().open_pos);
1945-
args.reset();
1946-
}
1948+
flush_args();
19471949

19481950
// Print the suffixes (in reverse order)
19491951
while (!suffix.empty()) {

0 commit comments

Comments
 (0)