[COMMITTED 13/77] gccrs: Move Identifier class to its own file

[email protected]
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.rust
Message-ID <[email protected]>
From: Pierre-Emmanuel Patry <[email protected]>

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]>
---
 gcc/rust/ast/rust-ast-identifier.h | 65 ++++++++++++++++++++++++++++++
 gcc/rust/ast/rust-ast.h            | 39 +-----------------
 2 files changed, 66 insertions(+), 38 deletions(-)
 create mode 100644 gcc/rust/ast/rust-ast-identifier.h

diff --git a/gcc/rust/ast/rust-ast-identifier.h b/gcc/rust/ast/rust-ast-identifier.h
new file mode 100644
index 00000000000..9b133657731
--- /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 8afa04bebf4..e8ebd850af0 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;
-- 
2.50.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.