aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-22 14:39:34 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-03-30 16:48:26 +0200
commit439c05ae3a8563a49cdf292f1ca0a84c0b43eb58 (patch)
tree653f391677ed67579eeaaa6cbbc1f85f917ae833 /gcc
parentf0ed95a8b9758e172e5e3e945a393b6295037507 (diff)
downloadgcc-439c05ae3a8563a49cdf292f1ca0a84c0b43eb58.zip
gcc-439c05ae3a8563a49cdf292f1ca0a84c0b43eb58.tar.gz
gcc-439c05ae3a8563a49cdf292f1ca0a84c0b43eb58.tar.bz2
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-tokenstream.cc9
-rw-r--r--gcc/rust/ast/rust-ast-tokenstream.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc
index a7fee13..d68c19a 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.cc
+++ b/gcc/rust/ast/rust-ast-tokenstream.cc
@@ -93,6 +93,15 @@ TokenStream::visit_items_as_block (T &collection,
}
void
+TokenStream::trailing_comma ()
+{
+ if (output_trailing_commas)
+ {
+ tokens.push_back (Rust::Token::make (COMMA, Location ()));
+ }
+}
+
+void
TokenStream::visit (FunctionParam &param)
{
visit (param.get_pattern ());
diff --git a/gcc/rust/ast/rust-ast-tokenstream.h b/gcc/rust/ast/rust-ast-tokenstream.h
index 70ef246..58459c6 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
*/