[gcc r14-8125] gccrs: Change FunctionParam to represent variadic params

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:15:45 GMT 2024


https://gcc.gnu.org/g:f1cca5671f928dd749ac14108ff8b01ecfbd634d

commit r14-8125-gf1cca5671f928dd749ac14108ff8b01ecfbd634d
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed Oct 18 14:24:31 2023 +0200

    gccrs: Change FunctionParam to represent variadic params
    
    Variadic were represented at the function level while retaining most
    informations of a given parameter.
    
    gcc/rust/ChangeLog:
    
            * ast/rust-item.h (class FunctionParam): Add some informations to
            function parameters in order to be able to store variadic argument as
            a function parameter.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/ast/rust-item.h | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 5af51bc35fc..38d8b53a43c 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -528,6 +528,7 @@ class FunctionParam
   location_t locus;
   std::unique_ptr<Pattern> param_name;
   std::unique_ptr<Type> type;
+  bool variadic;
 
 public:
   FunctionParam (std::unique_ptr<Pattern> param_name,
@@ -535,12 +536,26 @@ public:
 		 std::vector<Attribute> outer_attrs, location_t locus)
     : outer_attrs (std::move (outer_attrs)), locus (locus),
       param_name (std::move (param_name)), type (std::move (param_type)),
+      variadic (false),
+      node_id (Analysis::Mappings::get ()->get_next_node_id ())
+  {}
+
+  FunctionParam (std::vector<Attribute> outer_attrs, location_t locus)
+    : outer_attrs (std::move (outer_attrs)), locus (locus),
+      param_name (nullptr), type (nullptr), variadic (true),
+      node_id (Analysis::Mappings::get ()->get_next_node_id ())
+  {}
+
+  FunctionParam (std::unique_ptr<Pattern> param_name,
+		 std::vector<Attribute> outer_attrs, location_t locus)
+    : outer_attrs (std::move (outer_attrs)), locus (locus),
+      param_name (std::move (param_name)), type (nullptr), variadic (true),
       node_id (Analysis::Mappings::get ()->get_next_node_id ())
   {}
 
   // Copy constructor uses clone
   FunctionParam (FunctionParam const &other)
-    : locus (other.locus), node_id (other.node_id)
+    : locus (other.locus), variadic (other.variadic), node_id (other.node_id)
   {
     // guard to prevent nullptr dereference
     if (other.param_name != nullptr)
@@ -554,6 +569,7 @@ public:
   {
     locus = other.locus;
     node_id = other.node_id;
+    variadic = other.variadic;
 
     // guard to prevent nullptr dereference
     if (other.param_name != nullptr)
@@ -573,7 +589,13 @@ public:
   FunctionParam &operator= (FunctionParam &&other) = default;
 
   // Returns whether FunctionParam is in an invalid state.
-  bool is_error () const { return param_name == nullptr || type == nullptr; }
+  bool is_error () const
+  {
+    if (variadic)
+      return false;
+    else
+      return param_name == nullptr || type == nullptr;
+  }
 
   // Creates an error FunctionParam.
   static FunctionParam create_error ()
@@ -602,6 +624,9 @@ public:
     rust_assert (type != nullptr);
     return type;
   }
+
+  bool is_variadic () const { return variadic; }
+
   NodeId get_node_id () const { return node_id; }
 
 protected:


More information about the Gcc-cvs mailing list