diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 9d78993fa9d..1894d9bf64b 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -106,7 +106,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 @@ -114,7 +114,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 9c2f0c97af9..70fa8a426ca 100644 --- a/gcc/rust/ast/rust-ast-collector.h +++ b/gcc/rust/ast/rust-ast-collector.h @@ -23,7 +23,7 @@ #include "rust-ast-visitor.h" #include "rust-ast.h" #include "rust-ast-full.h" -#include +#include "rust-system.h" namespace Rust { namespace AST { @@ -40,9 +40,16 @@ class CollectItem 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 53b77385d1e..0148c752f40 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 blacklist) + std::set 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 5b0cac3b4f4..3c1a0016166 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 blacklist); + std::set excluded_node); /** * Run the visitor on an entire crate and its items @@ -75,17 +76,17 @@ class Dump 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; @@ -102,7 +103,7 @@ class Dump std::ostream &stream; Indent indentation; bool print_internal; - std::vector internal_blacklist; + std::set 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 d561bfaa923..0ac14a75dd7 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2024 Free Software Foundation, Inc. +// Copyright (C) 2020 - 2024 Free Software Foundation, Inc. // This file is part of GCC. @@ -59,8 +59,7 @@ #include "selftest.h" #include "tm.h" #include "rust-target.h" -#include -#include +#include "rust-system.h" extern bool saw_errors (void); @@ -394,7 +393,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); } } @@ -416,13 +415,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); } } @@ -1058,7 +1059,7 @@ Session::dump_ast_pretty_internal (AST::Crate &crate) const return; } - std::vector str_tmp = options.get_blacklist (); + std::set 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 65e9627123b..a6aa780941f 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 internal_blacklist; + std::set excluded_node; /* configuration options - actually useful for conditional compilation and * whatever data related to target arch, features, os, family, env, endian, @@ -291,16 +291,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 get_blacklist () const - { - return internal_blacklist; - } + const std::set get_excluded () const { return excluded_node; } void set_crate_name (std::string name) { @@ -418,7 +415,7 @@ struct Session 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?