[cfe-dev] SourceLoc comparison
Rafael·Stahl via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 13 06:02:23 PST 2018
When grabbing SourceLocs from different Preprocessors, they cannot be
compared with each other by using their comparison operator.
I assume this is because they have some kind of pointer identity and
equality just compares raw representations.
I attached a function that helped me solve this issue. Can you please
give feedback if I missed something existing or if there is an issue
with my approach? Or maybe the SourceManager/Preprocessor should not
even create new "duplicate" SrcLocs in this case?
bool clutil::DeepSrcLocEqual(clang::SourceLocation lhs,
clang::SourceLocation rhs, const clang::SourceManager &SM)
if (lhs == rhs)
if (SM.getExpansionLoc(lhs) != SM.getExpansionLoc(rhs))
if (SM.getSpellingLoc(lhs) != SM.getSpellingLoc(rhs))
clang::SourceLocation lhsMacro, rhsMacro;
if (SM.isMacroArgExpansion(lhs, &lhsMacro))
if (!SM.isMacroArgExpansion(rhs, &rhsMacro))
if (!DeepSrcLocEqual(lhsMacro, rhsMacro, SM))
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 5449 bytes
Desc: S/MIME Cryptographic Signature
More information about the cfe-dev