================
@@ -69,6 +72,44 @@ class RedundantPreprocessorCallbacks : public PPCallbacks {
}
private:
+ /// Extract the condition text following the 'if' keyword from source.
+ /// Loc points to the 'if' keyword token, so we find its end and read
+ /// forward through the source buffer to the end of the directive,
+ /// handling backslash line continuations.
+ StringRef getConditionText(SourceLocation Loc) {
+ const SourceManager &SM = PP.getSourceManager();
+ const SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
+
+ const SourceLocation AfterIf =
+ Lexer::getLocForEndOfToken(SpellingLoc, 0, SM, PP.getLangOpts());
+ if (AfterIf.isInvalid())
+ return {};
+
+ bool Invalid = false;
+ auto [FID, Offset] = SM.getDecomposedLoc(AfterIf);
+ const StringRef Buffer = SM.getBufferData(FID, &Invalid);
+ if (Invalid || Offset >= Buffer.size())
+ return {};
+
+ // Read to end-of-line, handling backslash line continuations.
----------------
zeyi2 wrote:
Could you try using `Token::isAtStartOfLine()` on a single Lexer instance to
detect the directive boundary? AFAIK the lexer handles backslash continuations
transparently, so IMO this is equivalent.
https://github.com/llvm/llvm-project/pull/181734
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits