aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-ast-tokenstream.cc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-23 16:46:51 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-03-30 16:48:27 +0200
commit3d9dbf5c004b4ab2206b86c68c2c824229aeee34 (patch)
tree3e1ad8d53e6675a59051cf51230f9e9a9486691f /gcc/rust/ast/rust-ast-tokenstream.cc
parentc34e05d01cfb3ffd5f2adb51eb6ab4d40aa3330f (diff)
downloadgcc-3d9dbf5c004b4ab2206b86c68c2c824229aeee34.zip
gcc-3d9dbf5c004b4ab2206b86c68c2c824229aeee34.tar.gz
gcc-3d9dbf5c004b4ab2206b86c68c2c824229aeee34.tar.bz2
ast: Add use declarations TokenStream visitors
Add UseDeclaration (and it's childrens) visitor implementation. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor. * ast/rust-item.h: Add missing getters. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/ast/rust-ast-tokenstream.cc')
-rw-r--r--gcc/rust/ast/rust-ast-tokenstream.cc77
1 files changed, 69 insertions, 8 deletions
diff --git a/gcc/rust/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc
index f5d0445..9fb9f93 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.cc
+++ b/gcc/rust/ast/rust-ast-tokenstream.cc
@@ -1586,20 +1586,81 @@ TokenStream::visit (ExternCrate &crate)
}
void
-TokenStream::visit (UseTreeGlob &)
-{}
+TokenStream::visit (UseTreeGlob &use_tree)
+{
+ switch (use_tree.get_glob_type ())
+ {
+ case UseTreeGlob::PathType::PATH_PREFIXED: {
+ auto path = use_tree.get_path ();
+ visit (path);
+ tokens.push_back (Rust::Token::make (SCOPE_RESOLUTION, Location ()));
+ }
+ break;
+ case UseTreeGlob::PathType::NO_PATH:
+ tokens.push_back (Rust::Token::make (SCOPE_RESOLUTION, Location ()));
+ break;
+ case UseTreeGlob::PathType::GLOBAL:
+ break;
+ }
+ tokens.push_back (Rust::Token::make (ASTERISK, Location ()));
+}
void
-TokenStream::visit (UseTreeList &)
-{}
+TokenStream::visit (UseTreeList &use_tree)
+{
+ switch (use_tree.get_path_type ())
+ {
+ case UseTreeList::PathType::PATH_PREFIXED: {
+ auto path = use_tree.get_path ();
+ visit (path);
+ tokens.push_back (Rust::Token::make (SCOPE_RESOLUTION, Location ()));
+ }
+ break;
+ case UseTreeList::PathType::NO_PATH:
+ tokens.push_back (Rust::Token::make (SCOPE_RESOLUTION, Location ()));
+ break;
+ case UseTreeList::PathType::GLOBAL:
+ break;
+ }
+
+ tokens.push_back (Rust::Token::make (LEFT_CURLY, Location ()));
+ if (use_tree.has_trees ())
+ {
+ visit_items_joined_by_separator (use_tree.get_trees (), COMMA);
+ }
+ tokens.push_back (Rust::Token::make (RIGHT_CURLY, Location ()));
+}
void
-TokenStream::visit (UseTreeRebind &)
-{}
+TokenStream::visit (UseTreeRebind &use_tree)
+{
+ auto path = use_tree.get_path ();
+ visit (path);
+ switch (use_tree.get_new_bind_type ())
+ {
+ case UseTreeRebind::NewBindType::IDENTIFIER: {
+ tokens.push_back (Rust::Token::make (AS, Location ()));
+ auto id = use_tree.get_identifier ();
+ tokens.push_back (
+ Rust::Token::make_identifier (use_tree.get_locus (), std::move (id)));
+ }
+ break;
+ case UseTreeRebind::NewBindType::WILDCARD:
+ tokens.push_back (Rust::Token::make (AS, Location ()));
+ tokens.push_back (Rust::Token::make (UNDERSCORE, use_tree.get_locus ()));
+ break;
+ case UseTreeRebind::NewBindType::NONE:
+ break;
+ }
+}
void
-TokenStream::visit (UseDeclaration &)
-{}
+TokenStream::visit (UseDeclaration &decl)
+{
+ tokens.push_back (Rust::Token::make (USE, decl.get_locus ()));
+ visit (*decl.get_tree ());
+ tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+}
void
TokenStream::visit (Function &function)