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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/bdf68eb723cca6a3e601d6cf3d1780f5539039fa
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4588
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 000000000..9b1336577
--- /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 8afa04beb..e8ebd850a 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.54.0