diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-10-18 14:31:53 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:13:11 +0100 |
commit | 6ac7d47338bb8c34f3751be77be05fa9ca456921 (patch) | |
tree | 010051e5b255808267e9dc2e9fd2b9837bb4da84 | |
parent | f1cca5671f928dd749ac14108ff8b01ecfbd634d (diff) | |
download | gcc-6ac7d47338bb8c34f3751be77be05fa9ca456921.zip gcc-6ac7d47338bb8c34f3751be77be05fa9ca456921.tar.gz gcc-6ac7d47338bb8c34f3751be77be05fa9ca456921.tar.bz2 |
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>
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index eb0310c..61c915d 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 |