[clang] [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (PR #135808)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 15 09:48:10 PDT 2025
================
@@ -466,6 +467,29 @@ class FullSourceLoc : public SourceLocation {
}
};
+/// A simple pair of identifier info and location.
+class IdentifierLoc {
+ SourceLocation Loc;
+ IdentifierInfo *II = nullptr;
+
+public:
+ IdentifierLoc() = default;
+ IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}
+
+ void setLoc(SourceLocation L) { Loc = L; }
+ void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
+ SourceLocation getLoc() const { return Loc; }
+ IdentifierInfo *getIdentifierInfo() const { return II; }
+
+ bool operator==(const IdentifierLoc &X) const {
+ return Loc == X.Loc && II == X.II;
+ }
+
+ bool operator!=(const IdentifierLoc &X) const {
+ return Loc != X.Loc || II != X.II;
+ }
+};
+
----------------
mizvekov wrote:
I think this would be more appropriate to stay in `IdentifierTable.h`
Not only it already had IdentifierLocPair, but there is more precedent in that sort of direction.
Ie we have precedent to define the `Loc` versions of AST nodes in the same headers which define the basic AST node. See for example NestedNameSpecifierLoc.
On the other hand, this would be the first Loc-like entity which we are defining in the SourceLocation Header, which would be breaking a clear line we have in place today.
https://github.com/llvm/llvm-project/pull/135808
More information about the cfe-commits
mailing list