aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2025-01-03 14:27:38 +0000
committerCohenArthur <arthur.cohen@embecosm.com>2025-01-20 12:09:26 +0000
commit78d4fe9d2505636c9db207cfa0fccd000dbceab7 (patch)
tree578a2839cfa1c1a0c9bf76b79b6c956fb3824870 /gcc
parent43747f4062a81e3b3f0e10b8ff2573eab9acca35 (diff)
downloadgcc-78d4fe9d2505636c9db207cfa0fccd000dbceab7.zip
gcc-78d4fe9d2505636c9db207cfa0fccd000dbceab7.tar.gz
gcc-78d4fe9d2505636c9db207cfa0fccd000dbceab7.tar.bz2
ast-builder: Add new methods for building structs
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-builder.cc12
-rw-r--r--gcc/rust/ast/rust-ast-builder.h5
2 files changed, 15 insertions, 2 deletions
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 728d5c0..eccc474 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -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 {
@@ -262,9 +263,16 @@ 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>
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 86279b0..7e224d3 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -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>