public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] ast: Add Meta items TokenStream visitor
@ 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:cc5d198e6cd893132bf844622e17da0a5c2b0e54
commit cc5d198e6cd893132bf844622e17da0a5c2b0e54
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu Mar 23 19:24:59 2023 +0100
ast: Add Meta items TokenStream visitor
Add visitor implementation for all remaining meta items.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor
implementation.
* ast/rust-ast-tokenstream.h: Add additional function prototype.
* ast/rust-item.h: Add some getters.
* ast/rust-macro.h: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
gcc/rust/ast/rust-ast-tokenstream.cc | 91 +++++++++++++++++++++++++++++-------
gcc/rust/ast/rust-ast-tokenstream.h | 1 +
gcc/rust/ast/rust-item.h | 2 +
gcc/rust/ast/rust-macro.h | 14 ++++++
4 files changed, 92 insertions(+), 16 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc
index 9fb9f931202..1bc1cab58c0 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.cc
+++ b/gcc/rust/ast/rust-ast-tokenstream.cc
@@ -2047,8 +2047,22 @@ TokenStream::visit (ExternalTypeItem &type)
}
void
-TokenStream::visit (ExternalStaticItem &)
-{}
+TokenStream::visit (ExternalStaticItem &item)
+{
+ auto id = item.get_identifier ();
+ visit_items_as_lines (item.get_outer_attrs ());
+ if (item.has_visibility ())
+ visit (item.get_visibility ());
+ tokens.push_back (Rust::Token::make (STATIC_TOK, item.get_locus ()));
+ if (item.is_mut ())
+ tokens.push_back (Rust::Token::make (MUT, Location ()));
+ tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
+ tokens.push_back (Rust::Token::make (COLON, Location ()));
+ visit (item.get_type ());
+ // TODO: No expr ? The "(= Expression)?" part from the reference seems missing
+ // in the ast.
+ tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+}
void
TokenStream::visit (ExternalFunctionItem &function)
@@ -2188,32 +2202,77 @@ TokenStream::visit (MacroRulesDefinition &rules_def)
}
void
-TokenStream::visit (MacroInvocation &)
-{}
+TokenStream::visit (MacroInvocation &invocation)
+{
+ auto data = invocation.get_invoc_data ();
+ visit (data.get_path ());
+ tokens.push_back (Rust::Token::make (EXCLAM, Location ()));
+ visit (data.get_delim_tok_tree ());
+ if (invocation.has_semicolon ())
+ tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
+}
void
-TokenStream::visit (MetaItemPath &)
-{}
+TokenStream::visit (MetaItemPath &item)
+{
+ auto path = item.to_path_item ();
+ visit (path);
+}
void
-TokenStream::visit (MetaItemSeq &)
-{}
+TokenStream::visit (MetaItemSeq &item)
+{
+ visit (item.get_path ());
+ // TODO: Double check this, there is probably a mistake.
+ tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
+ visit_items_joined_by_separator (item.get_seq (), COMMA);
+ tokens.push_back (Rust::Token::make (RIGHT_PAREN, Location ()));
+}
void
-TokenStream::visit (MetaWord &)
-{}
+TokenStream::visit (MetaWord &word)
+{
+ auto id = word.get_ident ();
+ tokens.push_back (
+ Rust::Token::make_identifier (word.get_locus (), std::move (id)));
+}
void
-TokenStream::visit (MetaNameValueStr &)
-{}
+TokenStream::visit (MetaNameValueStr &name)
+{
+ auto pair = name.get_name_value_pair ();
+ auto id = std::get<0> (pair);
+ auto value = std::get<1> (pair);
+ tokens.push_back (
+ Rust::Token::make_identifier (name.get_locus (), std::move (id)));
+ tokens.push_back (Rust::Token::make (EQUAL, name.get_locus ()));
+ tokens.push_back (Rust::Token::make (DOUBLE_QUOTE, Location ()));
+ tokens.push_back (
+ Rust::Token::make_identifier (name.get_locus (), std::move (value)));
+ tokens.push_back (Rust::Token::make (DOUBLE_QUOTE, Location ()));
+}
void
-TokenStream::visit (MetaListPaths &)
-{}
+TokenStream::visit (MetaListPaths &list)
+{
+ auto id = list.get_ident ();
+ tokens.push_back (
+ Rust::Token::make_identifier (list.get_locus (), std::move (id)));
+ tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
+ visit_items_joined_by_separator (list.get_paths (), COMMA);
+ tokens.push_back (Rust::Token::make (RIGHT_PAREN, Location ()));
+}
void
-TokenStream::visit (MetaListNameValueStr &)
-{}
+TokenStream::visit (MetaListNameValueStr &list)
+{
+ auto id = list.get_ident ();
+ tokens.push_back (
+ Rust::Token::make_identifier (list.get_locus (), std::move (id)));
+ tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
+ visit_items_joined_by_separator (list.get_values (), COMMA);
+ tokens.push_back (Rust::Token::make (RIGHT_PAREN, Location ()));
+}
// rust-pattern.h
void
diff --git a/gcc/rust/ast/rust-ast-tokenstream.h b/gcc/rust/ast/rust-ast-tokenstream.h
index bf3e0b2cf6a..1c9328e7dbe 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.h
+++ b/gcc/rust/ast/rust-ast-tokenstream.h
@@ -245,6 +245,7 @@ private:
void visit (MacroMatchRepetition &match);
void visit (MacroMatcher &matcher);
void visit (MacroRulesDefinition &rules_def);
+ void visit (MacroInvocData &invoc_data);
void visit (MacroInvocation ¯o_invoc);
void visit (MetaItemPath &meta_item);
void visit (MetaItemSeq &meta_item);
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 49e340ed393..3e865f188c5 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -4087,6 +4087,8 @@ public:
Identifier get_identifier () const { return item_name; }
+ Visibility &get_visibility () { return visibility; }
+
const Visibility &get_visibility () const { return visibility; }
bool is_mut () const { return has_mut; }
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index f667a0a57b1..0a3db1c68fd 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -904,6 +904,10 @@ public:
std::string as_string () const override;
+ SimplePath &get_path () { return path; }
+
+ std::vector<std::unique_ptr<MetaItemInner>> &get_seq () { return seq; }
+
void accept_vis (ASTVisitor &vis) override;
Location get_locus () const override { return path.get_locus (); }
@@ -935,6 +939,8 @@ public:
void accept_vis (ASTVisitor &vis) override;
+ Identifier get_ident () const { return ident; }
+
Location get_locus () const override { return ident_locus; }
bool check_cfg_predicate (const Session &session) const override;
@@ -1019,6 +1025,10 @@ public:
void accept_vis (ASTVisitor &vis) override;
+ Identifier get_ident () const { return ident; }
+
+ std::vector<SimplePath> &get_paths () { return paths; };
+
Location get_locus () const override { return ident_locus; }
bool check_cfg_predicate (const Session &session) const override;
@@ -1055,6 +1065,10 @@ public:
void accept_vis (ASTVisitor &vis) override;
+ Identifier get_ident () { return ident; }
+
+ std::vector<MetaNameValueStr> &get_values () { return strs; }
+
Location get_locus () const override { return ident_locus; }
bool check_cfg_predicate (const Session &session) const 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 Meta items TokenStream visitor 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).