[COMMITTED 68/77] gccrs: Do not export indentation levels within metadata

[email protected]
Newsgroups gmane.comp.gcc.rust,gmane.comp.gcc.patches
Message-ID <[email protected]>
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]>
---
 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 e813ea9d7f5..24c58e59341 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 cb281de8eee..a59e224dfb0 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 5d01c5425f4..4c36be9f5ae 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 6a56c956d9e..f6fabb3bff5 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.50.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.