public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8126] gccrs: Parse variadic functions Date: Tue, 16 Jan 2024 18:15:50 +0000 (GMT) [thread overview] Message-ID: <20240116181550.AEEBA385DC0A@sourceware.org> (raw) https://gcc.gnu.org/g:6ac7d47338bb8c34f3751be77be05fa9ca456921 commit r14-8126-g6ac7d47338bb8c34f3751be77be05fa9ca456921 Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> Date: Wed Oct 18 14:31:53 2023 +0200 gccrs: Parse variadic functions Variadic functions were not parsed because it is an unstable feature. While it is still unstable, it is required in order to parse libcore. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function_param): Parse variadic functions. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> Diff: --- gcc/rust/parse/rust-parse-impl.h | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index eb0310c888f..61c915db997 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3584,6 +3584,13 @@ Parser<ManagedTokenSource>::parse_function_param () // TODO: should saved location be at start of outer attributes or pattern? location_t locus = lexer.peek_token ()->get_locus (); + + if (lexer.peek_token ()->get_id () == ELLIPSIS) // Unnamed variadic + { + lexer.skip_token (); // Skip ellipsis + return AST::FunctionParam (std::move (outer_attrs), locus); + } + std::unique_ptr<AST::Pattern> param_pattern = parse_pattern (); // create error function param if it doesn't exist @@ -3599,15 +3606,24 @@ Parser<ManagedTokenSource>::parse_function_param () return AST::FunctionParam::create_error (); } - std::unique_ptr<AST::Type> param_type = parse_type (); - if (param_type == nullptr) + if (lexer.peek_token ()->get_id () == ELLIPSIS) // Named variadic { - // skip? - return AST::FunctionParam::create_error (); + lexer.skip_token (); // Skip ellipsis + return AST::FunctionParam (std::move (param_pattern), + std::move (outer_attrs), locus); + } + else + { + std::unique_ptr<AST::Type> param_type = parse_type (); + if (param_type == nullptr) + { + // skip? + return AST::FunctionParam::create_error (); + } + return AST::FunctionParam (std::move (param_pattern), + std::move (param_type), + std::move (outer_attrs), locus); } - - return AST::FunctionParam (std::move (param_pattern), std::move (param_type), - std::move (outer_attrs), locus); } /* Parses a function or method return type syntactical construction. Also
reply other threads:[~2024-01-16 18:15 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240116181550.AEEBA385DC0A@sourceware.org \ --to=cohenarthur@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).