diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-10-19 14:53:43 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-10-19 15:01:53 +0200 |
commit | 89490980726d298311107a452bdebeb43a2ff7e6 (patch) | |
tree | 29a06a0125db7dd6a057f5ff367d00e99cade8d4 /gcc/rust/ast | |
parent | 540d896c3fa745efdc96ad34e7e5c585f9b7b93f (diff) | |
download | gcc-89490980726d298311107a452bdebeb43a2ff7e6.zip gcc-89490980726d298311107a452bdebeb43a2ff7e6.tar.gz gcc-89490980726d298311107a452bdebeb43a2ff7e6.tar.bz2 |
ast: Improve Fragment API
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r-- | gcc/rust/ast/rust-ast-fragment.cc | 31 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-fragment.h | 18 |
2 files changed, 33 insertions, 16 deletions
diff --git a/gcc/rust/ast/rust-ast-fragment.cc b/gcc/rust/ast/rust-ast-fragment.cc index 1a2dd99..c491609 100644 --- a/gcc/rust/ast/rust-ast-fragment.cc +++ b/gcc/rust/ast/rust-ast-fragment.cc @@ -21,22 +21,13 @@ namespace Rust { namespace AST { -Fragment::Fragment (std::vector<SingleASTNode> nodes, bool fragment_is_error) - : kind (fragment_is_error ? FragmentKind::Error : FragmentKind::Complete), - nodes (std::move (nodes)) -{ - if (fragment_is_error) - rust_assert (nodes.empty ()); -} +Fragment::Fragment (FragmentKind kind, std::vector<SingleASTNode> nodes) + : kind (kind), nodes (std::move (nodes)) +{} Fragment::Fragment (Fragment const &other) : kind (other.get_kind ()) { - nodes.clear (); - nodes.reserve (other.nodes.size ()); - for (auto &n : other.nodes) - { - nodes.push_back (n); - } + *this = other; } Fragment & @@ -56,7 +47,19 @@ Fragment::operator= (Fragment const &other) Fragment Fragment::create_error () { - return Fragment ({}, true); + return Fragment (FragmentKind::Error, {}); +} + +Fragment +Fragment::complete (std::vector<AST::SingleASTNode> nodes) +{ + return Fragment (FragmentKind::Complete, std::move (nodes)); +} + +Fragment +Fragment::unexpanded () +{ + return Fragment (FragmentKind::Unexpanded, {}); } std::vector<SingleASTNode> & diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h index ee6ab0d..3ef4ba1 100644 --- a/gcc/rust/ast/rust-ast-fragment.h +++ b/gcc/rust/ast/rust-ast-fragment.h @@ -57,11 +57,23 @@ enum class FragmentKind class Fragment { public: - Fragment (std::vector<SingleASTNode> nodes, bool fragment_is_error = false); Fragment (Fragment const &other); + Fragment &operator= (Fragment const &other); + + /** + * Create an error fragment + */ static Fragment create_error (); - Fragment &operator= (Fragment const &other); + /** + * Create a complete AST fragment + */ + static Fragment complete (std::vector<AST::SingleASTNode> nodes); + + /** + * Create a fragment which contains unexpanded nodes + */ + static Fragment unexpanded (); FragmentKind get_kind () const; std::vector<SingleASTNode> &get_nodes (); @@ -78,6 +90,8 @@ public: void accept_vis (ASTVisitor &vis); private: + Fragment (FragmentKind kind, std::vector<SingleASTNode> nodes); + FragmentKind kind; /** |