95 assert(!includes.empty() &&
"No '-chain-include' in options!");
97 std::vector<std::unique_ptr<CompilerInstance>> CIs;
103 for (
unsigned i = 0, e = includes.size(); i != e; ++i) {
104 bool firstInclude = (i == 0);
105 std::unique_ptr<CompilerInvocation> CInvok;
108 CInvok->getPreprocessorOpts().ChainedIncludes.clear();
109 CInvok->getPreprocessorOpts().ImplicitPCHInclude.clear();
110 CInvok->getPreprocessorOpts().DisablePCHOrModuleValidation =
112 CInvok->getPreprocessorOpts().Includes.clear();
113 CInvok->getPreprocessorOpts().MacroIncludes.clear();
114 CInvok->getPreprocessorOpts().Macros.clear();
116 CInvok->getFrontendOpts().Inputs.clear();
118 CInvok->getFrontendOpts().Inputs.push_back(InputFile);
122 auto Diags = llvm::makeIntrusiveRefCnt<DiagnosticsEngine>(
125 auto Clang = std::make_unique<CompilerInstance>(
130 Clang->setDiagnostics(Diags);
132 Clang->getDiagnostics(), Clang->getInvocation().getTargetOpts()));
133 Clang->createFileManager();
134 Clang->createSourceManager();
136 Clang->getDiagnosticClient().BeginSourceFile(Clang->getLangOpts(),
137 &Clang->getPreprocessor());
138 Clang->createASTContext();
140 auto Buffer = std::make_shared<PCHBuffer>();
142 auto consumer = std::make_unique<PCHGenerator>(
143 Clang->getPreprocessor(), Clang->getModuleCache(),
"-",
"",
144 Buffer, Clang->getCodeGenOpts(), Extensions,
146 Clang->getASTContext().setASTMutationListener(
147 consumer->GetASTMutationListener());
148 Clang->setASTConsumer(std::move(consumer));
156 assert(!SerialBufs.empty());
160 for (
auto &SB : SerialBufs)
161 Bufs.push_back(llvm::MemoryBuffer::getMemBuffer(SB->getBuffer()));
162 std::string pchName = includes[i-1];
163 llvm::raw_string_ostream os(pchName);
165 serialBufNames.push_back(pchName);
169 *Clang, pchName, Bufs, serialBufNames,
170 Clang->getASTConsumer().GetASTDeserializationListener());
173 Clang->setASTReader(Reader);
174 Clang->getASTContext().setExternalSource(Reader);
177 if (!Clang->InitializeSourceManager(InputFile))
181 Clang->getDiagnosticClient().EndSourceFile();
182 assert(Buffer->IsComplete &&
"serialization did not complete");
183 auto &serialAST = Buffer->Data;
184 SerialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(
185 StringRef(serialAST.data(), serialAST.size())));
187 CIs.push_back(std::move(Clang));
190 assert(!SerialBufs.empty());
191 std::string pchName = includes.back() +
".pch-final";
192 serialBufNames.push_back(pchName);
198 llvm::makeIntrusiveRefCnt<ChainedIncludesSource>(std::move(CIs));
199 return llvm::makeIntrusiveRefCnt<MultiplexExternalSemaSource>(
200 std::move(ChainedSrc), OutReader);
void initializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
void ParseAST(Preprocessor &pp, ASTConsumer *C, ASTContext &Ctx, bool PrintStats=false, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr, bool SkipFunctionBodies=false)
Parse the entire file specified, notifying the ASTConsumer as the file is parsed.