tokens.emplace_back (CollectItem::make_comment (comment));
}
-void
-TokenCollector::begin_describe_node (const std::string &node_name)
-{
- const std::string symbol_begin ("(");
-
- tokens.emplace_back (
- CollectItem::make_node_description (node_name + symbol_begin));
-}
-
-void
-TokenCollector::end_describe_node (const std::string &node_name)
-{
- const std::string symbol_end (")!");
-
- tokens.push_back (
- CollectItem::make_node_description (symbol_end + node_name));
-}
-
void
TokenCollector::describe_node (const std::string &node_name,
std::function<void ()> visitor)
{
- begin_describe_node (node_name);
+ tokens.emplace_back (CollectItem::make_begin_node_description (node_name));
visitor ();
- end_describe_node (node_name);
+ tokens.push_back (CollectItem::make_end_node_description (node_name));
}
void
{
Comment,
InternalComment,
- NodeDescription,
+ BeginNodeDescription,
+ EndNodeDescription,
Newline,
Indentation,
Token,
{
return CollectItem (comment, Kind::Comment);
}
- static CollectItem make_node_description (const std::string &node_description)
+
+ static CollectItem
+ make_begin_node_description (const std::string &node_description)
+ {
+ return CollectItem (node_description, Kind::BeginNodeDescription);
+ }
+
+ static CollectItem
+ make_end_node_description (const std::string &node_description)
{
- return CollectItem (node_description, Kind::NodeDescription);
+ return CollectItem (node_description, Kind::EndNodeDescription);
}
Kind get_kind () { return kind; }
std::string get_node_description ()
{
- rust_assert (kind == Kind::NodeDescription);
+ rust_assert (kind == Kind::BeginNodeDescription
+ || kind == Kind::EndNodeDescription);
return comment;
}
void increment_indentation ();
void decrement_indentation ();
void comment (std::string comment);
- void begin_describe_node (const std::string &node_name);
- void end_describe_node (const std::string &node_name);
/**
* Visit common items of functions: Parameters, return type, block
*/
#include "rust-ast-dump.h"
#include "rust-expr.h"
-#include <vector>
namespace Rust {
namespace AST {
Dump::Dump (std::ostream &stream)
- : stream (stream), indentation (Indent ()), print_internal (false)
+ : stream (stream), indentation (Indent ()),
+ configuration (Configuration{
+ Configuration::InternalComment::Hide,
+ Configuration::NodeDescription::Hide,
+ Configuration::Comment::Dump,
+ })
{}
-Dump::Dump (std::ostream &stream, bool print_internal,
+Dump::Dump (std::ostream &stream, Configuration configuration,
std::set<std::string> excluded_node)
- : stream (stream), indentation (Indent ()), print_internal (print_internal)
-{
- excluded_node = excluded_node;
-}
+ : stream (stream), indentation (Indent ()), configuration (configuration),
+ excluded_node (excluded_node)
+{}
bool
Dump::require_spacing (TokenPtr previous, TokenPtr current)
class Dump
{
public:
+ struct Configuration
+ {
+ enum class InternalComment
+ {
+ Dump,
+ Hide,
+ } dump_internal_comments;
+ enum class NodeDescription
+ {
+ Dump,
+ Hide,
+ } dump_node_description;
+ enum class Comment
+ {
+ Dump,
+ Hide,
+ } dump_comments;
+ };
+
Dump (std::ostream &stream);
- Dump (std::ostream &stream, bool print_internal,
+ Dump (std::ostream &stream, Configuration configuration,
std::set<std::string> excluded_node);
/**
}
break;
case AST::CollectItem::Kind::Comment:
- stream << " /* " << item.get_comment () << " */ ";
+ if (configuration.dump_comments == Configuration::Comment::Dump)
+ stream << " /* " << item.get_comment () << " */ ";
break;
case AST::CollectItem::Kind::Indentation:
for (size_t i = 0; i < item.get_indent_level (); i++)
stream << "\n";
previous = nullptr;
break;
+ case AST::CollectItem::Kind::BeginNodeDescription:
+ if (configuration.dump_node_description
+ == Configuration::NodeDescription::Dump)
+ {
+ std::string comment = item.get_node_description ();
+ if (excluded_node.find (comment) == excluded_node.end ())
+ stream << " /* " << comment << " */ ";
+ }
+ break;
+ case AST::CollectItem::Kind::EndNodeDescription:
+ if (configuration.dump_node_description
+ == Configuration::NodeDescription::Dump)
+ {
+ std::string comment = item.get_node_description ();
+ if (excluded_node.find (comment) == excluded_node.end ())
+ stream << " /* !" << comment << " */ ";
+ }
+ break;
case AST::CollectItem::Kind::InternalComment:
- if (print_internal)
+ if (configuration.dump_internal_comments
+ == Configuration::InternalComment::Dump)
{
- bool is_excluded = false;
std::string comment = item.get_internal_comment ();
- for (auto &node : excluded_node)
- {
- if (comment.find (node) != std::string::npos)
- {
- is_excluded = true;
- break;
- }
- }
- if (!is_excluded)
- stream << " /* " << comment << " */ ";
+ stream << " /* " << comment << " */ ";
}
break;
default:
private:
std::ostream &stream;
Indent indentation;
- bool print_internal;
+ Configuration configuration;
std::set<std::string> excluded_node;
static bool require_spacing (TokenPtr previous, TokenPtr current);
std::set<std::string> str_tmp = options.get_excluded ();
- AST::Dump (out, true, str_tmp).go (crate);
+ AST::Dump (out,
+ AST::Dump::Configuration{
+ AST::Dump::Configuration::InternalComment::Dump,
+ AST::Dump::Configuration::NodeDescription::Dump,
+ AST::Dump::Configuration::Comment::Dump,
+ },
+ str_tmp)
+ .go (crate);
out.close ();
}