Skip to content

Commit f06c673

Browse files
committed
Correctly cpp2::-qualify unique.new and shared.new
Closes #939
1 parent 269b661 commit f06c673

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.3.0 Build 9115:1948
2+
cppfront compiler v0.3.0 Build 9116:1001
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"9115:1948"
1+
"9116:1001"

source/lex.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,46 @@ auto lex_line(
810810
};
811811

812812

813+
auto qualify_cpp2_special_names = [&]
814+
{
815+
auto i = std::ssize(tokens)-1;
816+
817+
// If the last three tokens are "unique/shared" "." "new", add "cpp2::"
818+
819+
if (
820+
i >= 2
821+
&& (tokens[i-2] == "unique" || tokens[i-2] == "shared")
822+
&& tokens[i-1] == "."
823+
&& tokens[i] == "new"
824+
)
825+
{
826+
auto pos = tokens[i-2].position();
827+
828+
generated_text.push_back( "cpp2" );
829+
tokens.insert(
830+
tokens.end()-3,
831+
token{
832+
&generated_text.back()[0],
833+
std::ssize(generated_text.back()),
834+
pos,
835+
lexeme::Identifier
836+
}
837+
);
838+
839+
generated_text.push_back( "::" );
840+
tokens.insert(
841+
tokens.end()-3,
842+
token{
843+
&generated_text.back()[0],
844+
std::ssize(generated_text.back()),
845+
pos,
846+
lexeme::Scope
847+
}
848+
);
849+
}
850+
};
851+
852+
813853
// Local helper functions for readability
814854
//
815855
auto peek = [&](int num) {
@@ -831,6 +871,7 @@ auto lex_line(
831871

832872
merge_cpp1_multi_token_fundamental_type_names();
833873
merge_operator_function_names();
874+
qualify_cpp2_special_names();
834875
};
835876

836877

source/to_cpp1.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,7 @@ class cppfront
17431743
)
17441744
-> void
17451745
{ STACKINSTR
1746+
assert( n.identifier );
17461747
auto last_use = is_definite_last_use(n.identifier);
17471748

17481749
bool add_forward =
@@ -1862,20 +1863,6 @@ class cppfront
18621863
return;
18631864
}
18641865

1865-
// Implicit "cpp2::" qualification of "unique.new" and "shared.new"
1866-
if (
1867-
n.ids.size() == 2
1868-
&& (
1869-
*n.ids[0].id->identifier == "unique"
1870-
|| *n.ids[0].id->identifier == "shared"
1871-
)
1872-
&& *n.ids[1].scope_op == "."
1873-
&& *n.ids[1].id->identifier == "new"
1874-
)
1875-
{
1876-
printer.print_cpp2("cpp2::", n.position());
1877-
}
1878-
18791866
auto ident = std::string{};
18801867
printer.emit_to_string(&ident);
18811868

0 commit comments

Comments
 (0)