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 : #ifndef RUST_AST_IDENTIFIER_H
20 : #define RUST_AST_IDENTIFIER_H
21 :
22 : #include "rust-token.h"
23 :
24 : namespace Rust {
25 26161714 : class Identifier
26 : {
27 : public:
28 : // Create dummy identifier
29 6594 : Identifier () : ident (""), loc (UNDEF_LOCATION) {}
30 : // Create identifier with dummy location
31 975340 : Identifier (std::string ident, location_t loc = UNDEF_LOCATION)
32 1948413 : : ident (ident), loc (loc)
33 : {}
34 : // Create identifier from token
35 69393 : Identifier (const_TokenPtr token)
36 69393 : : ident (token->get_str ()), loc (token->get_locus ())
37 69393 : {}
38 :
39 32051620 : Identifier (const Identifier &) = default;
40 7167456 : Identifier (Identifier &&) = default;
41 0 : Identifier &operator= (const Identifier &) = default;
42 15201 : Identifier &operator= (Identifier &&) = default;
43 :
44 177245 : location_t get_locus () const { return loc; }
45 13547143 : const std::string &as_string () const { return ident; }
46 :
47 9809462 : bool empty () const { return ident.empty (); }
48 :
49 : bool operator== (const Identifier &other) const
50 : {
51 : return ident == other.ident;
52 : }
53 :
54 548 : operator const std::string & () const { return ident; }
55 :
56 : private:
57 : std::string ident;
58 : location_t loc;
59 : };
60 :
61 : std::ostream &operator<< (std::ostream &os, Identifier const &i);
62 :
63 : } // namespace Rust
64 :
65 : #endif
|