public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] ast: Add trailing comma formatting option
@ 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:439c05ae3a8563a49cdf292f1ca0a84c0b43eb58
commit 439c05ae3a8563a49cdf292f1ca0a84c0b43eb58
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Wed Mar 22 14:39:34 2023 +0100
ast: Add trailing comma formatting option
Add an option to output trailing commas depending on the configuration
of the TokenStream.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::trailing_comma):
Output a trailing comma to the token stream according to the
configuration.
* ast/rust-ast-tokenstream.h: Add function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
gcc/rust/ast/rust-ast-tokenstream.cc | 9 +++++++++
gcc/rust/ast/rust-ast-tokenstream.h | 2 ++
2 files changed, 11 insertions(+)
diff --git a/gcc/rust/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc
index a7fee13a1ae..d68c19a44fe 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.cc
+++ b/gcc/rust/ast/rust-ast-tokenstream.cc
@@ -92,6 +92,15 @@ TokenStream::visit_items_as_block (T &collection,
tokens.push_back (Rust::Token::make (right_brace, Location ()));
}
+void
+TokenStream::trailing_comma ()
+{
+ if (output_trailing_commas)
+ {
+ tokens.push_back (Rust::Token::make (COMMA, Location ()));
+ }
+}
+
void
TokenStream::visit (FunctionParam ¶m)
{
diff --git a/gcc/rust/ast/rust-ast-tokenstream.h b/gcc/rust/ast/rust-ast-tokenstream.h
index 70ef24637ff..58459c6317a 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.h
+++ b/gcc/rust/ast/rust-ast-tokenstream.h
@@ -31,6 +31,7 @@ class TokenStream : public ASTVisitor
{
public:
TokenStream (std::vector<TokenPtr> &container);
+ bool output_trailing_commas = false;
void go (AST::Crate &crate);
void go (AST::Item &item);
@@ -86,6 +87,7 @@ private:
TokenId left_brace = LEFT_CURLY,
TokenId right_brace = RIGHT_CURLY);
+ void trailing_comma ();
/**
* Visit common items of functions: Parameters, return type, block
*/
^ 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 trailing comma formatting option 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).