From: Pierre-Emmanuel Patry Date: Wed, 22 Mar 2023 13:39:34 +0000 (+0100) Subject: gccrs: ast: Add trailing comma formatting option X-Git-Tag: basepoints/gcc-15~2722 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=06dcc5fdf4d72e4c43beb1a2eb3376c4e252e1f4;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc index a7fee13a1aea..d68c19a44fed 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 70ef24637ff8..58459c6317a5 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 &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 */