diff options
author | David Faust <david.faust@oracle.com> | 2022-10-06 11:32:02 -0700 |
---|---|---|
committer | David Faust <david.faust@oracle.com> | 2022-10-06 13:47:32 -0700 |
commit | b64b889e15ee6119605f4d52b2b3703083b835cc (patch) | |
tree | 50dec3f57c43b572eaaa8e613f395dd40bae5e5b | |
parent | b4096017e3b9ca499b56988b67e05667a02ca202 (diff) | |
download | gcc-b64b889e15ee6119605f4d52b2b3703083b835cc.zip gcc-b64b889e15ee6119605f4d52b2b3703083b835cc.tar.gz gcc-b64b889e15ee6119605f4d52b2b3703083b835cc.tar.bz2 |
ast: dump: add emit_generic_params helper
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.cc | 30 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.h | 3 |
2 files changed, 20 insertions, 13 deletions
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index bc4f7a3..b192556 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -141,6 +141,22 @@ Dump::emit_indented_string (const std::string &value, } void +Dump::emit_generic_params (std::vector<std::unique_ptr<GenericParam>> ¶ms) +{ + stream << "<"; + for (size_t i = 0; i < params.size (); i++) + { + auto ¶m = params.at (i); + param->accept_vis (*this); + + bool has_next = (i + 1) < params.size (); + if (has_next) + stream << ", "; + } + stream << ">"; +} + +void Dump::visit (Token &tok) {} @@ -679,19 +695,7 @@ Dump::visit (Function &function) stream << "fn " << function.get_function_name (); if (function.has_generics ()) - { - stream << "<"; - for (size_t i = 0; i < function.get_generic_params ().size (); i++) - { - auto ¶m = function.get_generic_params ().at (i); - param->accept_vis (*this); - - bool has_next = (i + 1) < function.get_generic_params ().size (); - if (has_next) - stream << ", "; - } - stream << ">"; - } + emit_generic_params (function.get_generic_params ()); stream << '('; auto ¶ms = function.get_function_params (); diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index a5a99f2..1bbefb3 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -97,6 +97,9 @@ private: std::ostream &emit_indented_string (const std::string &value, const std::string &comment = ""); + // Emit formatted string for generic parameters. + void emit_generic_params (std::vector<std::unique_ptr<GenericParam>> ¶ms); + // rust-ast.h void visit (Token &tok); void visit (DelimTokenTree &delim_tok_tree); |