From: Arthur Cohen <arthur.co...@embecosm.com>

gcc/rust/ChangeLog:

        * ast/rust-ast-builder.cc (Builder::qualified_path_in_expression): New.
        (Builder::function): Change the return type.
        * ast/rust-ast-builder.h: Declare qualified_path_in_expression 
functions.
        * expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Adapt to 
new APIs.
---
 gcc/rust/ast/rust-ast-builder.cc     | 32 +++++++++++++++++++++++-----
 gcc/rust/ast/rust-ast-builder.h      | 16 +++++++++++---
 gcc/rust/expand/rust-derive-debug.cc |  4 ++--
 3 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index aef0e110ce0..4c42b5bddae 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -64,6 +64,27 @@ Builder::array (std::vector<std::unique_ptr<Expr>> 
&&members) const
   return std::unique_ptr<Expr> (new ArrayExpr (std::move (elts), {}, {}, loc));
 }
 
+std::unique_ptr<Expr>
+Builder::qualified_path_in_expression (std::unique_ptr<Type> &&type,
+                                      TypePath trait,
+                                      PathExprSegment segment) const
+{
+  auto segments = {segment};
+
+  return qualified_path_in_expression (std::move (type), trait, segments);
+}
+
+std::unique_ptr<Expr>
+Builder::qualified_path_in_expression (
+  std::unique_ptr<Type> &&type, TypePath trait,
+  std::vector<PathExprSegment> &&segments) const
+{
+  auto qual_type = QualifiedPathType (std::move (type), loc, trait);
+
+  return std::unique_ptr<QualifiedPathInExpression> (
+    new QualifiedPathInExpression (qual_type, std::move (segments), {}, loc));
+}
+
 std::unique_ptr<Expr>
 Builder::identifier (std::string name) const
 {
@@ -111,17 +132,18 @@ Builder::fn_qualifiers () const
   return FunctionQualifiers (loc, Async::No, Const::No, Unsafety::Normal);
 }
 
-Function
-Builder::function (Identifier function_name,
+std::unique_ptr<Function>
+Builder::function (std::string function_name,
                   std::vector<std::unique_ptr<Param>> params,
                   std::unique_ptr<Type> return_type,
                   std::unique_ptr<BlockExpr> block,
                   FunctionQualifiers qualifiers, WhereClause where_clause,
                   Visibility visibility) const
 {
-  return Function (function_name, qualifiers, {}, std::move (params),
-                  std::move (return_type), where_clause, std::move (block),
-                  visibility, {}, loc);
+  return std::unique_ptr<Function> (
+    new Function (function_name, qualifiers, {}, std::move (params),
+                 std::move (return_type), where_clause, std::move (block),
+                 visibility, {}, loc));
 }
 
 PathExprSegment
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 90a878791df..21da13f14c8 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -104,7 +104,8 @@ public:
    * arguments (`path(arg0, arg1, arg2)`)
    */
   std::unique_ptr<Expr> call (std::unique_ptr<Expr> &&path,
-                             std::vector<std::unique_ptr<Expr>> &&args) const;
+                             std::vector<std::unique_ptr<Expr>> &&args
+                             = {}) const;
   std::unique_ptr<Expr> call (std::unique_ptr<Expr> &&path,
                              std::unique_ptr<Expr> &&arg) const;
 
@@ -114,6 +115,15 @@ public:
   std::unique_ptr<Expr>
   array (std::vector<std::unique_ptr<Expr>> &&members) const;
 
+  /* Create a qualified path in expression (`<type as Trait>::seg::expr`) */
+  std::unique_ptr<Expr>
+  qualified_path_in_expression (std::unique_ptr<Type> &&type, TypePath trait,
+                               PathExprSegment segment) const;
+  std::unique_ptr<Expr>
+  qualified_path_in_expression (std::unique_ptr<Type> &&type, TypePath trait,
+                               std::vector<PathExprSegment> &&segments
+                               = {}) const;
+
   /* Self parameter for a function definition (`&self`) */
   std::unique_ptr<Param> self_ref_param (bool mutability = false) const;
   /* A regular named function parameter for a definition (`a: type`) */
@@ -123,8 +133,8 @@ public:
   /* Empty function qualifiers, with no specific qualifiers */
   FunctionQualifiers fn_qualifiers () const;
 
-  Function
-  function (Identifier function_name,
+  std::unique_ptr<Function>
+  function (std::string function_name,
            std::vector<std::unique_ptr<Param>> params,
            std::unique_ptr<Type> return_type, std::unique_ptr<BlockExpr> block,
            FunctionQualifiers qualifiers
diff --git a/gcc/rust/expand/rust-derive-debug.cc 
b/gcc/rust/expand/rust-derive-debug.cc
index 910f27c67b2..f37547459a0 100644
--- a/gcc/rust/expand/rust-derive-debug.cc
+++ b/gcc/rust/expand/rust-derive-debug.cc
@@ -77,10 +77,10 @@ DeriveDebug::stub_debug_fn ()
 
   auto params = vec (std::move (self), std::move (fmt));
 
-  auto function = builder.function ({"fmt"}, std::move (params),
+  auto function = builder.function ("fmt", std::move (params),
                                    std::move (return_type), std::move (block));
 
-  return ptrify (function);
+  return function;
 }
 
 std::unique_ptr<Item>
-- 
2.45.2

Reply via email to