]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Parse variadic functions
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 18 Oct 2023 12:31:53 +0000 (14:31 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:13:11 +0000 (19:13 +0100)
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>
gcc/rust/parse/rust-parse-impl.h

index eb0310c888f7363fdf2295a7c98249c12c3a6b35..61c915db99723970c0ede5b1e15d7f3f19c51ab5 100644 (file)
@@ -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