From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id AEEBA385DC0A; Tue, 16 Jan 2024 18:15:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AEEBA385DC0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428950; bh=FkZ2HB5CdGWiA5WswMpX479VspsyCnKiWneBizkGwJs=; h=From:To:Subject:Date:From; b=W2i8lhnyXudsjlgw+p71o/S/M/IbtjN2PAAkHYPvmjYCCl3zXpHmnyVvCZaELhj6U 0LdmskX04EabwEYTvhThW/87WfBN1ZQ1hQsMkJho8fvJVOB8pPtmLMRR7TBGKqzWrs PM0PqqjLmqXK4PSx2eirXqkBd1UfJtEg5k1zpAcE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8126] gccrs: Parse variadic functions X-Act-Checkin: gcc X-Git-Author: Pierre-Emmanuel Patry X-Git-Refname: refs/heads/trunk X-Git-Oldrev: f1cca5671f928dd749ac14108ff8b01ecfbd634d X-Git-Newrev: 6ac7d47338bb8c34f3751be77be05fa9ca456921 Message-Id: <20240116181550.AEEBA385DC0A@sourceware.org> Date: Tue, 16 Jan 2024 18:15:50 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6ac7d47338bb8c34f3751be77be05fa9ca456921 commit r14-8126-g6ac7d47338bb8c34f3751be77be05fa9ca456921 Author: Pierre-Emmanuel Patry 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 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::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 param_pattern = parse_pattern (); // create error function param if it doesn't exist @@ -3599,15 +3606,24 @@ Parser::parse_function_param () return AST::FunctionParam::create_error (); } - std::unique_ptr 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 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