| 1 |
// Copyright (C) 2020-2025 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 |
Dump::Dump (std::ostream &stream) : stream (stream), indentation (Indent ()) {} |
| 26 |
|
| 27 |
bool |
| 28 |
Dump::require_spacing (TokenPtr previous, TokenPtr current) |
| 29 |
{ |
| 30 |
if (previous == nullptr) |
| 31 |
{ |
| 32 |
return false; |
| 33 |
} |
| 34 |
|
| 35 |
switch (current->get_id ()) |
| 36 |
{ |
| 37 |
case EXCLAM: |
| 38 |
case DOT_DOT: |
| 39 |
case DOT_DOT_EQ: |
| 40 |
case SCOPE_RESOLUTION: |
| 41 |
case LEFT_PAREN: |
| 42 |
case LEFT_ANGLE: |
| 43 |
case LEFT_SQUARE: |
| 44 |
case RIGHT_SQUARE: |
| 45 |
case RIGHT_PAREN: |
| 46 |
case SEMICOLON: |
| 47 |
case COMMA: |
| 48 |
case DOT: |
| 49 |
return false; |
| 50 |
default: |
| 51 |
break; |
| 52 |
} |
| 53 |
|
| 54 |
switch (previous->get_id ()) |
| 55 |
{ |
| 56 |
case SCOPE_RESOLUTION: |
| 57 |
case DOLLAR_SIGN: |
| 58 |
case LEFT_SQUARE: |
| 59 |
case LEFT_PAREN: |
| 60 |
case AMP: |
| 61 |
case DOT: |
| 62 |
return false; |
| 63 |
default: |
| 64 |
return true; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
void |
| 69 |
Dump::debug (Visitable &v) |
| 70 |
{ |
| 71 |
Dump dump (std::cerr); |
| 72 |
dump.process (v); |
| 73 |
} |
| 74 |
|
| 75 |
void |
| 76 |
Dump::go (AST::Crate &crate) |
| 77 |
{ |
| 78 |
process (crate); |
| 79 |
} |
| 80 |
|
| 81 |
void |
| 82 |
Dump::go (AST::Item &item) |
| 83 |
{ |
| 84 |
process (item); |
| 85 |
} |
| 86 |
|
| 87 |
} // namespace AST |
| 88 |
} // namespace Rust |
| 89 |
|
| 90 |
void |
| 91 |
debug (Rust::AST::Visitable &v) |
| 92 |
{ |
| 93 |
Rust::AST::Dump::debug (v); |
| 94 |
} |