From: Benjamin Thos <[email protected]>

Use an enum instead of bool to check if a comment is internal, use good
include and replace some variable name.

gcc/rust/ChangeLog:

        * ast/rust-ast-collector.cc (TokenCollector::begin_internal_comment):
        Change a boolean with an enum.
        (TokenCollector::end_internal_comment): Likewise.
        * ast/rust-ast-collector.h: Likewise + change include.
        * ast/rust-ast-dump.cc (Dump::Dump): Change variable name.
        * ast/rust-ast-dump.h: Likewise + replace vector with a set.
        * rust-session-manager.cc (Session::enable_dump): Change variable
        name.
        (Session::handle_internal_blacklist): Change function name.
        (Session::handle_excluded_node): Likewise.
        (Session::dump_ast_pretty_internal): Change vector with a set.
        * rust-session-manager.h (struct CompileOptions): Likewise + change
        variable name.

Signed-off-by: Benjamin Thos <[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/d5294a4d3596d673f20e977d97cc03f17a407a9b

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4326

 gcc/rust/ast/rust-ast-collector.cc |  4 ++--
 gcc/rust/ast/rust-ast-collector.h  | 12 ++++++++++--
 gcc/rust/ast/rust-ast-dump.cc      |  4 ++--
 gcc/rust/ast/rust-ast-dump.h       | 13 +++++++------
 gcc/rust/rust-session-manager.cc   | 15 ++++++++-------
 gcc/rust/rust-session-manager.h    | 13 +++++--------
 6 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index 7de309dad..1f41e65cd 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -108,7 +108,7 @@ TokenCollector::begin_internal_comment (std::string comment)
 {
   std::string symbol_begin ("(");
 
-  tokens.push_back ({comment + symbol_begin, true});
+  tokens.push_back ({comment + symbol_begin, CollectItem::Comment::Internal});
 }
 
 void
@@ -116,7 +116,7 @@ TokenCollector::end_internal_comment (std::string comment)
 {
   std::string symbol_end (")!");
 
-  tokens.push_back ({symbol_end + comment, true});
+  tokens.push_back ({symbol_end + comment, CollectItem::Comment::Internal});
 }
 
 void
diff --git a/gcc/rust/ast/rust-ast-collector.h 
b/gcc/rust/ast/rust-ast-collector.h
index 504675ae1..97feb192a 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -23,6 +23,7 @@
 #include "rust-ast-visitor.h"
 #include "rust-ast.h"
 #include "rust-ast-full.h"
+#include "rust-system.h"
 
 namespace Rust {
 namespace AST {
@@ -39,9 +40,16 @@ public:
     Token,
   };
 
+  enum class Comment
+  {
+    Regular,
+    Internal,
+  };
+
   CollectItem (TokenPtr token) : token (token), kind (Kind::Token) {}
-  CollectItem (std::string comment, bool internal = false)
-    : comment (comment), kind (internal ? Kind::InternalComment : 
Kind::Comment)
+  CollectItem (std::string comment, Comment type = Comment::Regular)
+    : comment (comment),
+      kind (type == Comment::Internal ? Kind::InternalComment : Kind::Comment)
   {}
   CollectItem (Kind kind) : kind (kind) { rust_assert (kind != Kind::Token); }
   CollectItem (size_t level) : indent_level (level), kind (Kind::Indentation) 
{}
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 3dff71445..6e9c9d437 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -28,10 +28,10 @@ Dump::Dump (std::ostream &stream)
 {}
 
 Dump::Dump (std::ostream &stream, bool print_internal,
-           std::vector<std::string> blacklist)
+           std::set<std::string> excluded_node)
   : stream (stream), indentation (Indent ()), print_internal (print_internal)
 {
-  internal_blacklist = blacklist;
+  excluded_node = excluded_node;
 }
 
 bool
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index a6370f2bc..2d32e6893 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -22,6 +22,7 @@
 #include "rust-ast.h"
 #include "rust-ast-full.h"
 #include "rust-dump.h"
+#include "rust-system.h"
 
 #include "rust-ast-collector.h"
 
@@ -33,7 +34,7 @@ class Dump
 public:
   Dump (std::ostream &stream);
   Dump (std::ostream &stream, bool print_internal,
-       std::vector<std::string> blacklist);
+       std::set<std::string> excluded_node);
 
   /**
    * Run the visitor on an entire crate and its items
@@ -76,17 +77,17 @@ public:
          case AST::CollectItem::Kind::InternalComment:
            if (print_internal)
              {
-               bool is_blacklisted = false;
+               bool is_excluded = false;
                std::string comment = item.get_internal_comment ();
-               for (auto &node : internal_blacklist)
+               for (auto &node : excluded_node)
                  {
                    if (comment.find (node) != std::string::npos)
                      {
-                       is_blacklisted = true;
+                       is_excluded = true;
                        break;
                      }
                  }
-               if (!is_blacklisted)
+               if (!is_excluded)
                  stream << " /* " << comment << " */ ";
              }
            break;
@@ -103,7 +104,7 @@ private:
   std::ostream &stream;
   Indent indentation;
   bool print_internal;
-  std::vector<std::string> internal_blacklist;
+  std::set<std::string> excluded_node;
 
   static bool require_spacing (TokenPtr previous, TokenPtr current);
 };
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index ab81a3f77..901339c9c 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -62,8 +62,7 @@
 #include "selftest.h"
 #include "tm.h"
 #include "rust-target.h"
-#include <sstream>
-#include <vector>
+#include "rust-system.h"
 
 extern bool saw_errors (void);
 
@@ -401,7 +400,7 @@ Session::enable_dump (std::string arg)
                             arg.c_str (), ":");
              return false;
            }
-         handle_internal_blacklist (arg);
+         handle_excluded_node (arg);
          options.enable_dump_option (CompileOptions::INTERNAL_DUMP);
        }
     }
@@ -423,13 +422,15 @@ Session::enable_dump (std::string arg)
  */
 
 void
-Session::handle_internal_blacklist (std::string arg)
+Session::handle_excluded_node (std::string arg)
 {
-  std::istringstream blist_str (arg.substr (arg.find (":") + 1, 50));
+  const int size_node_string = 50;
+  std::istringstream blist_str (
+    arg.substr (arg.find (":") + 1, size_node_string));
   std::string token;
   while (std::getline (blist_str, token, ','))
     {
-      options.add_blacklist (token);
+      options.add_excluded (token);
     }
 }
 
@@ -1078,7 +1079,7 @@ Session::dump_ast_pretty_internal (AST::Crate &crate) 
const
       return;
     }
 
-  std::vector<std::string> str_tmp = options.get_blacklist ();
+  std::set<std::string> str_tmp = options.get_excluded ();
 
   AST::Dump (out, true, str_tmp).go (crate);
 
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 4bb8ff193..75528584b 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -230,7 +230,7 @@ struct CompileOptions
 
   /* List of node that is not print during the dump of the ast with internal
    * comment */
-  std::vector<std::string> internal_blacklist;
+  std::set<std::string> excluded_node;
 
   /* configuration options - actually useful for conditional compilation and
    * whatever data related to target arch, features, os, family, env, endian,
@@ -298,16 +298,13 @@ struct CompileOptions
     enable_dump_option (DumpOption::INTERNAL_DUMP);
   }
 
-  void add_blacklist (std::string node)
+  void add_excluded (std::string node)
   {
     rust_assert (!node.empty ());
-    internal_blacklist.push_back (node);
+    excluded_node.insert (node);
   }
 
-  const std::vector<std::string> get_blacklist () const
-  {
-    return internal_blacklist;
-  }
+  const std::set<std::string> get_excluded () const { return excluded_node; }
 
   void set_crate_name (std::string name)
   {
@@ -432,7 +429,7 @@ private:
   void dump_hir (HIR::Crate &crate) const;
   void dump_hir_pretty (HIR::Crate &crate) const;
 
-  void handle_internal_blacklist (std::string arg);
+  void handle_excluded_node (std::string arg);
 
   // pipeline stages - TODO maybe move?
   /* Register plugins pipeline stage. TODO maybe move to another object?
-- 
2.52.0

Reply via email to