[clang] [Clang] [C++26] Iterating expansion statements using string injection (PR #208877)

Ambrose Leeb via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 4 10:17:04 PDT 2026


================
@@ -236,26 +236,29 @@ void Lexer::resetExtendedTokenMode() {
     SetCommentRetentionState(PP->getCommentRetentionState());
 }
 
-/// Create_PragmaLexer: Lexer constructor - Create a new lexer object for
-/// _Pragma expansion.  This has a variety of magic semantics that this method
-/// sets up.
+/// CreateScratchLexer: Lexer constructor - Create a new lexer object that
+/// places 'Code' in the scratch buffer and lexes from it.
 ///
-/// On entrance to this routine, TokStartLoc is a macro location which has a
-/// spelling loc that indicates the bytes to be lexed for the token and an
-/// expansion location that indicates where all lexed tokens should be
-/// "expanded from".
+/// This is used to implement _Pragma as well as string injection.
 ///
 /// TODO: It would really be nice to make _Pragma just be a wrapper around a
 /// normal lexer that remaps tokens as they fly by.  This would require making
 /// Preprocessor::Lex virtual.  Given that, we could just dump in a magic lexer
 /// interface that could handle this stuff.  This would pull GetMappedTokenLoc
 /// out of the critical path of the lexer!
 ///
-std::unique_ptr<Lexer> Lexer::Create_PragmaLexer(
-    SourceLocation SpellingLoc, SourceLocation ExpansionLocStart,
-    SourceLocation ExpansionLocEnd, unsigned TokLen, Preprocessor &PP) {
+std::unique_ptr<Lexer>
+Lexer::CreateScratchLexer(StringRef Code, SourceLocation ExpansionLocStart,
+                          SourceLocation ExpansionLocEnd, Preprocessor &PP) {
   SourceManager &SM = PP.getSourceManager();
 
+  // Plop the string into a buffer where we can lex it.
----------------
Sirraide wrote:

I will say that this comment is from like a decade ago; I just moved it here :eyes: 

https://github.com/llvm/llvm-project/pull/208877


More information about the cfe-commits mailing list