Line data Source code
1 : // Copyright (C) 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-system.h"
20 :
21 : #ifndef RUST_RAW_PATH_H
22 : #define RUST_RAW_PATH_H
23 :
24 : namespace Rust {
25 :
26 56585424 : template <typename Segment> class RawPath
27 : {
28 : protected:
29 : std::vector<Segment> segments;
30 : bool opening_scope_resolution;
31 :
32 : public:
33 17433167 : RawPath (std::vector<Segment> segments, bool opening_scope_resolution)
34 15346305 : : segments (std::move (segments)),
35 17433167 : opening_scope_resolution (opening_scope_resolution)
36 : {}
37 :
38 : /* Returns whether the RawPath has an opening scope resolution operator
39 : * (i.e. is global path or crate-relative path, not module-relative) */
40 8871550 : bool has_opening_scope_resolution () const
41 : {
42 8871550 : return opening_scope_resolution;
43 : }
44 :
45 4747581 : const std::vector<Segment> &get_segments () const { return segments; }
46 308935996 : std::vector<Segment> &get_segments () { return segments; }
47 :
48 1856545 : bool is_empty () const { return segments.empty (); }
49 :
50 885868 : Segment &get_final_segment ()
51 : {
52 885868 : rust_assert (!is_empty ());
53 885868 : return get_segments ().back ();
54 : }
55 149545 : const Segment &get_final_segment () const
56 : {
57 149545 : rust_assert (!is_empty ());
58 149545 : return get_segments ().back ();
59 : }
60 : };
61 :
62 : } // namespace Rust
63 :
64 : #endif
|