]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast-builder: Add new methods for building structs
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 3 Jan 2025 14:27:38 +0000 (14:27 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:57:51 +0000 (12:57 +0100)
gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: Add new methods for constructing struct exprs.
* ast/rust-ast-builder.h: Mention how to build tuple expressions.

gcc/rust/ast/rust-ast-builder.cc
gcc/rust/ast/rust-ast-builder.h

index fe80924fece7332500517caf5c3c9e4afdcafd48..47044df91714ebf9b5cae4122ca408f7bb1a4ff1 100644 (file)
@@ -24,6 +24,7 @@
 #include "rust-path.h"
 #include "rust-item.h"
 #include "rust-path.h"
+#include "rust-system.h"
 #include "rust-token.h"
 
 namespace Rust {
@@ -261,10 +262,17 @@ std::unique_ptr<Expr>
 Builder::struct_expr (
   std::string struct_name,
   std::vector<std::unique_ptr<StructExprField>> &&fields) const
+{
+  return struct_expr (path_in_expression ({struct_name}), std::move (fields));
+}
+
+std::unique_ptr<Expr>
+Builder::struct_expr (
+  PathInExpression struct_name,
+  std::vector<std::unique_ptr<StructExprField>> &&fields) const
 {
   return std::unique_ptr<Expr> (
-    new StructExprStructFields (path_in_expression ({struct_name}),
-                               std::move (fields), loc));
+    new StructExprStructFields (struct_name, std::move (fields), loc));
 }
 
 std::unique_ptr<StructExprField>
index 624cd715181d996ec864545ea90a40e8a5115022..e5bae6ed6e95aa9b0e2801ea9276e8ec2034de89 100644 (file)
@@ -160,10 +160,15 @@ public:
 
   /**
    * Create an expression for struct instantiation with fields (`S { a, b: c }`)
+   * Tuple expressions are call expressions and can thus be constructed with
+   * `call`
    */
   std::unique_ptr<Expr>
   struct_expr (std::string struct_name,
               std::vector<std::unique_ptr<StructExprField>> &&fields) const;
+  std::unique_ptr<Expr>
+  struct_expr (PathInExpression struct_name,
+              std::vector<std::unique_ptr<StructExprField>> &&fields) const;
 
   /* Create a field expression for struct instantiation (`field_name: value`) */
   std::unique_ptr<StructExprField>