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>(
127 Clang->createVirtualFileSystem();
128 Clang->setDiagnostics(Diags);
130 Clang->getDiagnostics(), Clang->getInvocation().getTargetOpts()));
131 Clang->createFileManager();
132 Clang->createSourceManager(Clang->getFileManager());
134 Clang->getDiagnosticClient().BeginSourceFile(Clang->getLangOpts(),
135 &Clang->getPreprocessor());
136 Clang->createASTContext();
138 auto Buffer = std::make_shared<PCHBuffer>();
140 auto consumer = std::make_unique<PCHGenerator>(
141 Clang->getPreprocessor(), Clang->getModuleCache(),
"-",
"",
142 Buffer, Clang->getCodeGenOpts(), Extensions,
144 Clang->getASTContext().setASTMutationListener(
145 consumer->GetASTMutationListener());
146 Clang->setASTConsumer(std::move(consumer));
154 assert(!SerialBufs.empty());
158 for (
auto &SB : SerialBufs)
159 Bufs.push_back(llvm::MemoryBuffer::getMemBuffer(SB->getBuffer()));
160 std::string pchName = includes[i-1];
161 llvm::raw_string_ostream os(pchName);
163 serialBufNames.push_back(pchName);
167 *Clang, pchName, Bufs, serialBufNames,
168 Clang->getASTConsumer().GetASTDeserializationListener());
171 Clang->setASTReader(Reader);
172 Clang->getASTContext().setExternalSource(Reader);
175 if (!Clang->InitializeSourceManager(InputFile))
179 Clang->getDiagnosticClient().EndSourceFile();
180 assert(Buffer->IsComplete &&
"serialization did not complete");
181 auto &serialAST = Buffer->Data;
182 SerialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(
183 StringRef(serialAST.data(), serialAST.size())));
185 CIs.push_back(std::move(Clang));
188 assert(!SerialBufs.empty());
189 std::string pchName = includes.back() +
".pch-final";
190 serialBufNames.push_back(pchName);
196 llvm::makeIntrusiveRefCnt<ChainedIncludesSource>(std::move(CIs));
197 return llvm::makeIntrusiveRefCnt<MultiplexExternalSemaSource>(
198 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.