diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-12-26 10:49:16 +0000 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2025-01-20 12:09:26 +0000 |
commit | cd7930c162fc9e5557d589957063a51e9d02dee7 (patch) | |
tree | 2cf0ab7885f763062d374a35e00af344d373eef5 /gcc/rust/ast/rust-ast-builder.h | |
parent | 3351befe04d041e57f345075727346573c78560e (diff) | |
download | gcc-cd7930c162fc9e5557d589957063a51e9d02dee7.zip gcc-cd7930c162fc9e5557d589957063a51e9d02dee7.tar.gz gcc-cd7930c162fc9e5557d589957063a51e9d02dee7.tar.bz2 |
builder: Allow generating struct statements
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::struct_struct): New function.
* ast/rust-ast-builder.h (vec): New function.
Diffstat (limited to 'gcc/rust/ast/rust-ast-builder.h')
-rw-r--r-- | gcc/rust/ast/rust-ast-builder.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h index 2c7b3f8..bb00377 100644 --- a/gcc/rust/ast/rust-ast-builder.h +++ b/gcc/rust/ast/rust-ast-builder.h @@ -21,10 +21,35 @@ #include "rust-ast-full.h" #include "rust-expr.h" +#include "rust-ast.h" +#include "rust-item.h" namespace Rust { namespace AST { +template <typename T> +std::vector<std::unique_ptr<T>> +vec (std::unique_ptr<T> &&t) +{ + auto v = std::vector<std::unique_ptr<T>> (); + + v.emplace_back (std::move (t)); + + return v; +} + +template <typename T> +std::vector<std::unique_ptr<T>> +vec (std::unique_ptr<T> &&t1, std::unique_ptr<T> &&t2) +{ + auto v = std::vector<std::unique_ptr<T>> (); + + v.emplace_back (std::move (t1)); + v.emplace_back (std::move (t2)); + + return v; +} + // TODO: Use this builder when expanding regular macros /* Builder class with helper methods to create AST nodes. This builder is * tailored towards generating multiple AST nodes from a single location, and @@ -113,6 +138,12 @@ public: */ PathInExpression path_in_expression (LangItem::Kind lang_item) const; + /* Create a new struct */ + std::unique_ptr<Stmt> + struct_struct (std::string struct_name, + std::vector<std::unique_ptr<GenericParam>> &&generics, + std::vector<StructField> &&fields); + /* Create a struct expression for unit structs (`S`) */ std::unique_ptr<Expr> struct_expr_struct (std::string struct_name) const; |