public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] ast: Add use declarations TokenStream visitors
@ 2023-04-06 21:34 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:34 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3d9dbf5c004b4ab2206b86c68c2c824229aeee34
commit 3d9dbf5c004b4ab2206b86c68c2c824229aeee34
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu Mar 23 16:46:51 2023 +0100
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>
Diff:
---
gcc/rust/ast/rust-ast-tokenstream.cc | 77 ++++++++++++++++++++++++++++++++----
gcc/rust/ast/rust-item.h | 11 ++++++
2 files changed, 80 insertions(+), 8 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc
index f5d04450dbc..9fb9f931202 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)
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 56cc13dce0f..49e340ed393 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1280,6 +1280,8 @@ public:
void accept_vis (ASTVisitor &vis) override;
+ PathType get_glob_type () { return glob_type; }
+
Kind get_kind () const override { return Glob; }
SimplePath get_path () const
@@ -1367,6 +1369,8 @@ public:
std::string as_string () const override;
+ PathType get_path_type () { return path_type; }
+
void accept_vis (ASTVisitor &vis) override;
Kind get_kind () const override { return List; }
@@ -1376,6 +1380,8 @@ public:
return path;
}
+ std::vector<std::unique_ptr<UseTree>> &get_trees () { return trees; }
+
const std::vector<std::unique_ptr<UseTree>> &get_trees () const
{
return trees;
@@ -1424,6 +1430,8 @@ public:
std::string as_string () const override;
+ NewBindType get_new_bind_type () { return bind_type; }
+
void accept_vis (ASTVisitor &vis) override;
Kind get_kind () const override { return Rebind; }
@@ -1497,6 +1505,9 @@ public:
UseDeclaration &operator= (UseDeclaration &&other) = default;
Location get_locus () const override final { return locus; }
+
+ std::unique_ptr<UseTree> &get_tree () { return use_tree; }
+
const std::unique_ptr<UseTree> &get_tree () const { return use_tree; }
void accept_vis (ASTVisitor &vis) override;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-06 21:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:34 [gcc/devel/rust/master] ast: Add use declarations TokenStream visitors Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).