1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 // This file is part of GCC.
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
18 #ifndef RUST_AST_DUMP_H
19 #define RUST_AST_DUMP_H
21 #include "rust-ast-visitor.h"
23 #include "rust-ast-full.h"
24 #include "rust-dump.h"
26 #include "rust-ast-collector.h"
34 Dump (std::ostream
&stream
);
37 * Run the visitor on an entire crate and its items
39 void go (AST::Crate
&crate
);
40 void go (AST::Item
&item
);
42 template <typename T
> void process (T
&v
)
44 TokenCollector collector
;
47 TokenPtr previous
= nullptr;
48 for (auto item
: collector
.collect ())
50 switch (item
.get_kind ())
52 case AST::CollectItem::Kind::Token
: {
53 TokenPtr current
= item
.get_token ();
54 if (require_spacing (previous
, current
))
56 stream
<< current
->as_string ();
60 case AST::CollectItem::Kind::Comment
:
61 stream
<< " /* " << item
.get_comment () << " */ ";
63 case AST::CollectItem::Kind::Indentation
:
64 for (size_t i
= 0; i
< item
.get_indent_level (); i
++)
69 case AST::CollectItem::Kind::Newline
:
79 // Helper method to get a quick debug dump to standard error output
80 static void debug (Visitable
&v
);
86 static bool require_spacing (TokenPtr previous
, TokenPtr current
);
92 // In the global namespace to make it easier to call from debugger
94 debug (Rust::AST::Visitable
&v
);
96 #endif // !RUST_AST_DUMP_H