aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-ast-fragment.cc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-10-19 14:53:43 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2023-02-21 12:36:37 +0100
commitb326cced19e5f4d240369fa1f6dc4a4417fd4f6d (patch)
tree42ce041702158c062150bb7cac671b5efb1daa17 /gcc/rust/ast/rust-ast-fragment.cc
parent68e743090df65d936305620bacfa1e766011d027 (diff)
downloadgcc-b326cced19e5f4d240369fa1f6dc4a4417fd4f6d.zip
gcc-b326cced19e5f4d240369fa1f6dc4a4417fd4f6d.tar.gz
gcc-b326cced19e5f4d240369fa1f6dc4a4417fd4f6d.tar.bz2
gccrs: ast: Improve Fragment API
gcc/rust/ChangeLog: * ast/rust-ast-fragment.cc (Fragment::Fragment): Add better APIs. (Fragment::complete): New function. (Fragment::unexpanded): New function. * ast/rust-ast-fragment.h: Declare new APIs and add documentation. * expand/rust-attribute-visitor.h: Use new Fragment API. * expand/rust-macro-builtins.cc (MacroBuiltin::file): Likewise. (MacroBuiltin::column): Likewise. (MacroBuiltin::include_bytes): Likewise. (MacroBuiltin::include_str): Likewise. (MacroBuiltin::concat): Likewise. (MacroBuiltin::env): Likewise. (MacroBuiltin::cfg): Likewise. (MacroBuiltin::include): Likewise. (MacroBuiltin::line): Likewise. * expand/rust-macro-expand.cc (parse_many): Likewise. (transcribe_expression): Likewise. (transcribe_type): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Likewise.
Diffstat (limited to 'gcc/rust/ast/rust-ast-fragment.cc')
-rw-r--r--gcc/rust/ast/rust-ast-fragment.cc31
1 files changed, 17 insertions, 14 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> &