]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/rust/ast/rust-ast-formatting.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / rust / ast / rust-ast-formatting.cc
CommitLineData
721bc1b9 1/* General AST-related method implementations for Rust frontend.
767698ff 2 Copyright (C) 2009-2024 Free Software Foundation, Inc.
721bc1b9
PEP
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#include "rust-ast-full.h"
21
22namespace Rust {
23namespace AST {
24
25std::string
26indent_spaces (enum indent_mode mode)
27{
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++;
36
37 return str;
38}
39
40std::string
41get_string_in_delims (std::string str_input, DelimType delim_type)
42{
43 switch (delim_type)
44 {
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)";
53 }
93866b6a 54 rust_unreachable ();
721bc1b9
PEP
55}
56
57std::string
58get_mode_dump_desc (AttrMode mode)
59{
60 switch (mode)
61 {
62 case OUTER:
63 return "outer attributes";
64 case INNER:
65 return "inner attributes";
66 default:
93866b6a 67 rust_unreachable ();
721bc1b9
PEP
68 return "";
69 }
70}
71
72std::string
73append_attributes (std::vector<Attribute> attrs, AttrMode mode)
74{
75 indent_spaces (enter);
76
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 ())
81 {
82 str += "none";
83 }
84 else
85 {
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 ();
90 }
91
92 indent_spaces (out);
93
94 return str;
95}
96
97std::string
98unquote_string (std::string input)
99{
100 rust_assert (input.front () == '"');
101 rust_assert (input.back () == '"');
102 return input.substr (1, input.length () - 2);
103}
104
105} // namespace AST
106} // namespace Rust