aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2025-01-03 14:27:38 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:57:51 +0100
commit8dedd0d11ddb3c999530edf6c810b1aa7ca7378b (patch)
tree1ebc8eaf431c1179a040f16fabddad12c5de6819 /gcc
parent4cbbaa71c1a2d438c9ac534ef6b2bf6c1887bf8e (diff)
downloadgcc-8dedd0d11ddb3c999530edf6c810b1aa7ca7378b.zip
gcc-8dedd0d11ddb3c999530edf6c810b1aa7ca7378b.tar.gz
gcc-8dedd0d11ddb3c999530edf6c810b1aa7ca7378b.tar.bz2
gccrs: 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 fe80924..47044df 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 624cd71..e5bae6e 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>