[gcc r14-7417] gccrs: ast: Add trailing comma formatting option
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:32:57 GMT 2024
https://gcc.gnu.org/g:06dcc5fdf4d72e4c43beb1a2eb3376c4e252e1f4
commit r14-7417-g06dcc5fdf4d72e4c43beb1a2eb3376c4e252e1f4
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Wed Mar 22 14:39:34 2023 +0100
gccrs: 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
*/
More information about the Gcc-cvs
mailing list