[PR testsuite/116860] Testsuite adjustment for recently added tests
[official-gcc.git] / gcc / rust / ast / rust-ast-formatting.cc
blob37aca83b34922aff0a7f7dfd5973eaac95fb3758
1 /* General AST-related method implementations for Rust frontend.
2 Copyright (C) 2009-2025 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "rust-ast-full.h"
22 namespace Rust {
23 namespace AST {
25 std::string
26 indent_spaces (enum indent_mode mode)
28 static int indent = 0;
29 std::string str = "";
30 if (out == mode)
31 indent--;
32 for (int i = 0; i < indent; i++)
33 str += " ";
34 if (enter == mode)
35 indent++;
37 return str;
40 std::string
41 get_string_in_delims (std::string str_input, DelimType delim_type)
43 switch (delim_type)
45 case PARENS:
46 return "(" + str_input + ")";
47 case SQUARE:
48 return "[" + str_input + "]";
49 case CURLY:
50 return "{" + str_input + "}";
51 default:
52 return "ERROR-MARK-STRING (delims)";
54 rust_unreachable ();
57 std::string
58 get_mode_dump_desc (AttrMode mode)
60 switch (mode)
62 case OUTER:
63 return "outer attributes";
64 case INNER:
65 return "inner attributes";
66 default:
67 rust_unreachable ();
68 return "";
72 std::string
73 append_attributes (std::vector<Attribute> attrs, AttrMode mode)
75 indent_spaces (enter);
77 std::string str
78 = "\n" + indent_spaces (stay) + get_mode_dump_desc (mode) + ": ";
79 // str += "\n" + indent_spaces (stay) + "inner attributes: ";
80 if (attrs.empty ())
82 str += "none";
84 else
86 /* note that this does not print them with outer or "inner attribute"
87 * syntax - just prints the body */
88 for (const auto &attr : attrs)
89 str += "\n" + indent_spaces (stay) + attr.as_string ();
92 indent_spaces (out);
94 return str;
97 std::string
98 unquote_string (std::string input)
100 rust_assert (input.front () == '"');
101 rust_assert (input.back () == '"');
102 return input.substr (1, input.length () - 2);
105 } // namespace AST
106 } // namespace Rust