https://gcc.gnu.org/g:a51e7e1a1b1de81afbb0f3b6043d02836e6797f3
commit r17-3071-ga51e7e1a1b1de81afbb0f3b6043d02836e6797f3 Author: Pierre-Emmanuel Patry <[email protected]> Date: Wed Jul 1 17:08:03 2026 +0200 gccrs: Move Identifier class to its own file This class is used in several locations and should be easy to include anywhere without including the whole AST definitions. gcc/rust/ChangeLog: * ast/rust-ast.h (class Identifier): Move from here to rust-ast-identifiers.h. (operator<<): Likewise. * ast/rust-ast-identifier.h: New file. Signed-off-by: Pierre-Emmanuel Patry <[email protected]> Diff: --- gcc/rust/ast/rust-ast-identifier.h | 65 ++++++++++++++++++++++++++++++++++++++ gcc/rust/ast/rust-ast.h | 39 +---------------------- 2 files changed, 66 insertions(+), 38 deletions(-) diff --git a/gcc/rust/ast/rust-ast-identifier.h b/gcc/rust/ast/rust-ast-identifier.h new file mode 100644 index 000000000000..9b1336577315 --- /dev/null +++ b/gcc/rust/ast/rust-ast-identifier.h @@ -0,0 +1,65 @@ +// Copyright (C) 2026 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#ifndef RUST_AST_IDENTIFIER_H +#define RUST_AST_IDENTIFIER_H + +#include "rust-token.h" + +namespace Rust { +class Identifier +{ +public: + // Create dummy identifier + Identifier () : ident (""), loc (UNDEF_LOCATION) {} + // Create identifier with dummy location + Identifier (std::string ident, location_t loc = UNDEF_LOCATION) + : ident (ident), loc (loc) + {} + // Create identifier from token + Identifier (const_TokenPtr token) + : ident (token->get_str ()), loc (token->get_locus ()) + {} + + Identifier (const Identifier &) = default; + Identifier (Identifier &&) = default; + Identifier &operator= (const Identifier &) = default; + Identifier &operator= (Identifier &&) = default; + + location_t get_locus () const { return loc; } + const std::string &as_string () const { return ident; } + + bool empty () const { return ident.empty (); } + + bool operator== (const Identifier &other) const + { + return ident == other.ident; + } + + operator const std::string & () const { return ident; } + +private: + std::string ident; + location_t loc; +}; + +std::ostream &operator<< (std::ostream &os, Identifier const &i); + +} // namespace Rust + +#endif diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 8afa04bebf41..e8ebd850af0a 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -27,6 +27,7 @@ #include "rust-diagnostics.h" #include "rust-keyword-values.h" #include "rust-cloneable.h" +#include "rust-ast-identifier.h" namespace Rust { // TODO: remove typedefs and make actual types for these @@ -34,44 +35,6 @@ typedef int TupleIndex; struct Session; struct MacroExpander; -class Identifier -{ -public: - // Create dummy identifier - Identifier () : ident (""), loc (UNDEF_LOCATION) {} - // Create identifier with dummy location - Identifier (std::string ident, location_t loc = UNDEF_LOCATION) - : ident (ident), loc (loc) - {} - // Create identifier from token - Identifier (const_TokenPtr token) - : ident (token->get_str ()), loc (token->get_locus ()) - {} - - Identifier (const Identifier &) = default; - Identifier (Identifier &&) = default; - Identifier &operator= (const Identifier &) = default; - Identifier &operator= (Identifier &&) = default; - - location_t get_locus () const { return loc; } - const std::string &as_string () const { return ident; } - - bool empty () const { return ident.empty (); } - - bool operator== (const Identifier &other) const - { - return ident == other.ident; - } - - operator const std::string & () const { return ident; } - -private: - std::string ident; - location_t loc; -}; - -std::ostream &operator<< (std::ostream &os, Identifier const &i); - namespace AST { // foward decl: ast visitor class ASTVisitor;
