]> gcc.gnu.org Git - gcc.git/commitdiff
Allow variadic NamedFunctionParam
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 18 Oct 2023 13:30:57 +0000 (15:30 +0200)
committerPhilip Herron <philip.herron@embecosm.com>
Thu, 9 Nov 2023 15:39:45 +0000 (15:39 +0000)
This was made to align NamedFunctionParam with FunctionParam.

gcc/rust/ChangeLog:

* ast/rust-item.h (class NamedFunctionParam): Add variadic boolean and
another constructor.
* hir/rust-ast-lower-extern.h: Avoid last parameter when variadic.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ast/rust-item.h
gcc/rust/hir/rust-ast-lower-extern.h

index c4653d95fb497e83ee0fa57ff02fc95b3e61ebe9..90249351c2d37d9a51d1b44cf8457c5c4f2787c1 100644 (file)
@@ -4166,6 +4166,7 @@ class NamedFunctionParam
 
   NodeId node_id;
   location_t locus;
+  bool variadic;
 
 public:
   /* Returns whether the named function parameter has a name (i.e. name is not
@@ -4178,7 +4179,7 @@ public:
   bool is_error () const
   {
     // also if identifier is "" but that is probably more costly to compute
-    return param_type == nullptr;
+    return param_type == nullptr && !variadic;
   }
 
   std::string get_name () const { return name; }
@@ -4195,17 +4196,35 @@ public:
                      std::vector<Attribute> outer_attrs, location_t locus)
     : name (std::move (name)), param_type (std::move (param_type)),
       outer_attrs (std::move (outer_attrs)),
-      node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus)
+      node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus),
+      variadic (false)
+  {}
+
+  NamedFunctionParam (std::string name, std::vector<Attribute> outer_attrs,
+                     location_t locus)
+    : name (std::move (name)), param_type (nullptr),
+      outer_attrs (std::move (outer_attrs)),
+      node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus),
+      variadic (true)
+  {}
+
+  NamedFunctionParam (std::vector<Attribute> outer_attrs, location_t locus)
+    : name (""), param_type (nullptr), outer_attrs (std::move (outer_attrs)),
+      node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus),
+      variadic (true)
   {}
 
   // Copy constructor
   NamedFunctionParam (NamedFunctionParam const &other)
-    : name (other.name), outer_attrs (other.outer_attrs)
+    : name (other.name), outer_attrs (other.outer_attrs),
+      variadic (other.variadic)
   {
     node_id = other.node_id;
     // guard to prevent null dereference (only required if error state)
     if (other.param_type != nullptr)
       param_type = other.param_type->clone_type ();
+    else
+      param_type = nullptr;
   }
 
   ~NamedFunctionParam () = default;
index 7690a77864ed87dadf9e904e7768b60cb7116fd3..1a0ba3d5c7d999c3cef6c98f5f8abb6d34237144 100644 (file)
@@ -79,15 +79,20 @@ public:
          ? ASTLoweringType::translate (function.get_return_type ().get ())
          : nullptr;
 
+    bool is_variadic = function.is_variadic ();
+    auto begin = function.get_function_params ().begin ();
+    auto end = is_variadic ? function.get_function_params ().end () - 1
+                          : function.get_function_params ().end ();
+
     std::vector<HIR::NamedFunctionParam> function_params;
-    for (auto &param : function.get_function_params ())
+    for (auto it = begin; it != end; it++)
       {
        HIR::Type *param_type
-         = ASTLoweringType::translate (param.get_type ().get ());
-       Identifier param_name = param.get_name ();
+         = ASTLoweringType::translate (it->get_type ().get ());
+       Identifier param_name = it->get_name ();
 
        auto crate_num = mappings->get_current_crate ();
-       Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
+       Analysis::NodeMapping mapping (crate_num, it->get_node_id (),
                                       mappings->get_next_hir_id (crate_num),
                                       mappings->get_next_localdef_id (
                                         crate_num));
This page took 0.068695 seconds and 5 git commands to generate.