diff clang/lib/Lex/Preprocessor.cpp @ 240:ca573705d418

merge
author matac
date Fri, 28 Jul 2023 20:50:09 +0900
parents 173fe712db74
children b2ae1833b9d9
line wrap: on
line diff
--- a/clang/lib/Lex/Preprocessor.cpp	Wed Nov 09 18:03:41 2022 +0900
+++ b/clang/lib/Lex/Preprocessor.cpp	Fri Jul 28 20:50:09 2023 +0900
@@ -154,6 +154,11 @@
       !this->PPOpts->ImplicitPCHInclude.empty())
     SkippingUntilPCHThroughHeader = true;
 
+#ifndef noCbC
+  SavedDepth = 0;
+  SavedTokenFlag = false;
+#endif
+
   if (this->PPOpts->GeneratePreamble)
     PreambleConditionalStack.startRecording();
 
@@ -1476,3 +1481,31 @@
   Record = new PreprocessingRecord(getSourceManager());
   addPPCallbacks(std::unique_ptr<PPCallbacks>(Record));
 }
+
+#ifndef noCbC
+
+Token Preprocessor::ReadFromString(const char *src , SourceLocation Loc) {
+    // Push the ( "string" ) tokens into the token stream.
+    MacroInfo *MI = AllocateMacroInfo(Loc);
+    Token Tok;
+    std::unique_ptr<Lexer> lx(new Lexer(CurLexer->getFileID(),getSourceManager().getBufferOrFake(CurLexer->getFileID(), Loc),*this));
+    lx->InitLexer(src,src,src + strlen(src));
+    lx->Lex(Tok);
+    CurLexer.swap(lx);
+    int i = 0;
+    while (Tok.getKind() != tok::TokenKind::eof) {
+      Tok.setLocation(Loc);
+      MI->AddTokenToBody(Tok);
+      Lex(Tok); i++;
+    }
+    Tok.setLocation(Loc);
+    MI->AddTokenToBody(Tok); i++;
+    MI->DefinitionLength = i;
+    CurLexer = std::move(lx);
+    CurPPLexer = CurLexer.get();
+    EnterMacro(Tok, Loc, MI , 0 );
+    CurTokenLexer->MacroDefLength = i;
+    return Tok;
+}
+
+#endif