Skip to content

Add .. syntax to select a member function only #1101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions regression-tests/pure2-ufcs-member-access-and-chaining.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ main: () -> int = {
42.no_return();

res.no_return();

obj: mytype = ();
obj..hun(42); // explicit non-UFCS
}

no_return: (_) = { }
Expand All @@ -41,3 +44,7 @@ get_i: (r:_) -> int = {
// And a test for non-local UFCS, which shouldn't do a [&] capture
f: (_)->int = 0;
y: int = 0.f();

mytype: type = {
hun: (i: int) = { }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Microsoft (R) C/C++ Optimizing Compiler Version 19.39.33523 for x86
Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33811 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

13 changes: 8 additions & 5 deletions source/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum class lexeme : std::int8_t {
Semicolon,
Comma,
Dot,
DotDot,
Ellipsis,
QuestionMark,
At,
Expand Down Expand Up @@ -180,6 +181,7 @@ auto _as(lexeme l)
break;case lexeme::Semicolon: return "Semicolon";
break;case lexeme::Comma: return "Comma";
break;case lexeme::Dot: return "Dot";
break;case lexeme::DotDot: return "DotDot";
break;case lexeme::Ellipsis: return "Ellipsis";
break;case lexeme::QuestionMark: return "QuestionMark";
break;case lexeme::At: return "At";
Expand Down Expand Up @@ -845,9 +847,9 @@ auto lex_line(

if (
i >= 3
&& (tokens[i-3] != "::" && tokens[i-3] != ".")
&& (tokens[i-3] != "::" && tokens[i-3].type() != lexeme::Dot && tokens[i - 3].type() != lexeme::DotDot)
&& (tokens[i-2] == "unique" || tokens[i-2] == "shared")
&& tokens[i-1] == "."
&& tokens[i-1].type() == lexeme::Dot
&& tokens[i] == "new"
)
{
Expand Down Expand Up @@ -1402,10 +1404,11 @@ auto lex_line(

//G
//G punctuator: one of
//G '...' '.'
//G '.' '..' '...'
break;case '.':
if (peek1 == '.' && peek2 == '.') { store(3, lexeme::Ellipsis); }
else { store(1, lexeme::Dot); }
if (peek1 == '.' && peek2 == '.') { store(3, lexeme::Ellipsis); }
else if (peek1 == '.') { store(2, lexeme::DotDot); }
else { store(1, lexeme::Dot); }

//G '::' ':'
break;case ':':
Expand Down
15 changes: 8 additions & 7 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ auto violates_lifetime_safety = false;
auto is_prefix_operator(token const& tok)
-> bool
{
//if (to_passing_style(tok) != passing_style::invalid) {
// return true;
//}

switch (tok.type()) {
break;case lexeme::Not:
case lexeme::Minus:
Expand Down Expand Up @@ -1682,7 +1678,7 @@ auto postfix_expression_node::get_first_token_ignoring_this() const
expr->get_token()
&& *expr->get_token() == "this"
&& std::ssize(ops) == 1
&& ops[0].op->type() == lexeme::Dot
&& (ops[0].op->type() == lexeme::Dot || ops[0].op->type() == lexeme::DotDot)
)
{
return ops[0].id_expr->get_token();
Expand Down Expand Up @@ -5820,6 +5816,7 @@ class parser
//G postfix-expression '[' expression-list? ','? ']'
//G postfix-expression '(' expression-list? ','? ')'
//G postfix-expression '.' id-expression
//G postfix-expression '..' id-expression
//G
auto postfix_expression()
-> std::unique_ptr<postfix_expression_node>
Expand All @@ -5837,7 +5834,8 @@ class parser
|| curr().type() == lexeme::LeftBracket
|| curr().type() == lexeme::LeftParen
|| curr().type() == lexeme::Dot
)
|| curr().type() == lexeme::DotDot
)
)
{
// * and & can't be unary operators if followed by a (, identifier, or literal
Expand Down Expand Up @@ -5916,7 +5914,10 @@ class parser
break;
}
}
else if (term.op->type() == lexeme::Dot)
else if (
term.op->type() == lexeme::Dot
|| term.op->type() == lexeme::DotDot
)
{
term.id_expr = id_expression();
if (!term.id_expr) {
Expand Down
Loading
Loading