Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
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
8 : // version.
9 :
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
13 : // for more details.
14 :
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 :
19 : #include "rust-ast-dump.h"
20 : #include "rust-expr.h"
21 :
22 : namespace Rust {
23 : namespace AST {
24 :
25 3 : Dump::Dump (std::ostream &stream)
26 3 : : stream (stream), indentation (Indent ()),
27 3 : configuration (Configuration{
28 : Configuration::InternalComment::Hide,
29 : Configuration::NodeDescription::Hide,
30 : Configuration::Comment::Dump,
31 : Configuration::Newline::Dump,
32 : Configuration::Indentation::Space4,
33 3 : })
34 3 : {}
35 :
36 4305 : Dump::Dump (std::ostream &stream, Configuration configuration,
37 : std::set<std::string> excluded_node)
38 4305 : : stream (stream), indentation (Indent ()), configuration (configuration),
39 4305 : excluded_node (excluded_node)
40 4305 : {}
41 :
42 : bool
43 896908 : Dump::require_spacing (TokenPtr previous, TokenPtr current)
44 : {
45 896908 : if (previous == nullptr)
46 : {
47 : return false;
48 : }
49 :
50 748906 : switch (current->get_id ())
51 : {
52 : case EXCLAM:
53 : case DOT_DOT:
54 : case DOT_DOT_EQ:
55 : case SCOPE_RESOLUTION:
56 : case LEFT_PAREN:
57 : case LEFT_ANGLE:
58 : case LEFT_SQUARE:
59 : case RIGHT_SQUARE:
60 : case RIGHT_PAREN:
61 : case SEMICOLON:
62 : case COMMA:
63 : case DOT:
64 : return false;
65 481461 : default:
66 481461 : break;
67 : }
68 :
69 481461 : switch (previous->get_id ())
70 : {
71 : case SCOPE_RESOLUTION:
72 : case DOLLAR_SIGN:
73 : case LEFT_SQUARE:
74 : case LEFT_PAREN:
75 : case AMP:
76 : case DOT:
77 : return false;
78 : default:
79 : return true;
80 : }
81 : }
82 :
83 : void
84 0 : Dump::debug (Visitable &v)
85 : {
86 0 : Dump dump (std::cerr);
87 0 : dump.process (v);
88 0 : }
89 :
90 : void
91 0 : Dump::go (AST::Crate &crate)
92 : {
93 0 : process (crate);
94 0 : }
95 :
96 : void
97 3 : Dump::go (AST::Item &item)
98 : {
99 3 : process (item);
100 3 : }
101 :
102 : } // namespace AST
103 : } // namespace Rust
104 :
105 : void
106 0 : debug (Rust::AST::Visitable &v)
107 : {
108 0 : Rust::AST::Dump::debug (v);
109 0 : }
110 :
111 : void
112 0 : debug (Rust::AST::Crate &crate)
113 : {
114 0 : for (auto &inner_attr : crate.get_inner_attrs ())
115 : {
116 0 : debug (inner_attr);
117 : }
118 0 : for (auto &item : crate.items)
119 : {
120 0 : debug (*item);
121 : }
122 0 : }
|