From: Pierre-Emmanuel Patry <[email protected]>
Those metadata files are meant to be read by the parser and not by humans
Although it may help during compiler development, they could still get
expanded by any rust pretty printer.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::Dump): Add a default indentation level of
four and dump newlines.
* ast/rust-ast-dump.h: Add newline and indentation level configuration
options.
* metadata/rust-export-metadata.cc (ExportContext::emit_crate): Do not
export indentation and newlines.
* rust-session-manager.cc (Session::dump_ast_pretty_internal): Use an
indentation level of 4 and dump newlines.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/01db3a43fa53e87186dcaf20780f69d2892da339
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4694
gcc/rust/ast/rust-ast-dump.cc | 2 ++
gcc/rust/ast/rust-ast-dump.h | 17 +++++++++++++++--
gcc/rust/metadata/rust-export-metadata.cc | 10 +++++++++-
gcc/rust/rust-session-manager.cc | 2 ++
4 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index e813ea9d7..24c58e593 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -28,6 +28,8 @@ Dump::Dump (std::ostream &stream)
Configuration::InternalComment::Hide,
Configuration::NodeDescription::Hide,
Configuration::Comment::Dump,
+ Configuration::Newline::Dump,
+ Configuration::Indentation::Space4,
})
{}
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index cb281de8e..a59e224df 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -49,6 +49,16 @@ public:
Dump,
Hide,
} dump_comments;
+ enum class Newline
+ {
+ Dump,
+ Hide,
+ } newline;
+ enum class Indentation
+ {
+ Space4,
+ None,
+ } indentation;
};
Dump (std::ostream &stream);
@@ -87,11 +97,14 @@ public:
case AST::CollectItem::Kind::Indentation:
for (size_t i = 0; i < item.get_indent_level (); i++)
{
- stream << " ";
+ if (configuration.indentation
+ == Configuration::Indentation::Space4)
+ stream << " ";
}
break;
case AST::CollectItem::Kind::Newline:
- stream << "\n";
+ if (configuration.newline == Configuration::Newline::Dump)
+ stream << "\n";
previous = nullptr;
break;
case AST::CollectItem::Kind::BeginNodeDescription:
diff --git a/gcc/rust/metadata/rust-export-metadata.cc
b/gcc/rust/metadata/rust-export-metadata.cc
index 5d01c5425..4c36be9f5 100644
--- a/gcc/rust/metadata/rust-export-metadata.cc
+++ b/gcc/rust/metadata/rust-export-metadata.cc
@@ -42,7 +42,15 @@ void
ExportContext::emit_crate (AST::Crate &c)
{
std::stringstream oss;
- AST::Dump dumper (oss);
+ using AST::Dump;
+ AST::Dump dumper (
+ oss,
+ Dump::Configuration{Dump::Configuration::InternalComment::Hide,
+ Dump::Configuration::NodeDescription::Hide,
+ Dump::Configuration::Comment::Hide,
+ Dump::Configuration::Newline::Hide,
+ Dump::Configuration::Indentation::None},
+ {});
dumper.process (c);
public_interface_buffer += oss.str ();
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 6a56c956d..f6fabb3bf 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -1181,6 +1181,8 @@ Session::dump_ast_pretty_internal (AST::Crate &crate)
const
AST::Dump::Configuration::InternalComment::Dump,
AST::Dump::Configuration::NodeDescription::Dump,
AST::Dump::Configuration::Comment::Dump,
+ AST::Dump::Configuration::Newline::Dump,
+ AST::Dump::Configuration::Indentation::Space4,
},
str_tmp)
.go (crate);
--
2.54.0