96 assert(!includes.empty() &&
"No '-chain-include' in options!");
98 std::vector<std::unique_ptr<CompilerInstance>> CIs;
104 for (
unsigned i = 0, e = includes.size(); i != e; ++i) {
105 bool firstInclude = (i == 0);
106 std::unique_ptr<CompilerInvocation> CInvok;
109 CInvok->getPreprocessorOpts().ChainedIncludes.clear();
110 CInvok->getPreprocessorOpts().ImplicitPCHInclude.clear();
111 CInvok->getPreprocessorOpts().DisablePCHOrModuleValidation =
113 CInvok->getPreprocessorOpts().Includes.clear();
114 CInvok->getPreprocessorOpts().MacroIncludes.clear();
115 CInvok->getPreprocessorOpts().Macros.clear();
117 CInvok->getFrontendOpts().Inputs.clear();
119 CInvok->getFrontendOpts().Inputs.push_back(InputFile);
123 auto Diags = llvm::makeIntrusiveRefCnt<DiagnosticsEngine>(
126 auto Clang = std::make_unique<CompilerInstance>(
131 Clang->setDiagnostics(Diags);
133 Clang->getDiagnostics(), Clang->getInvocation().getTargetOpts()));
134 Clang->createFileManager();
135 Clang->createSourceManager();
137 Clang->getDiagnosticClient().BeginSourceFile(Clang->getLangOpts(),
138 &Clang->getPreprocessor());
139 Clang->createASTContext();
141 auto Buffer = std::make_shared<PCHBuffer>();
143 auto consumer = std::make_unique<PCHGenerator>(
144 Clang->getPreprocessor(), Clang->getModuleCache(),
"-",
"",
145 Buffer, Clang->getCodeGenOpts(), Extensions,
147 Clang->getASTContext().setASTMutationListener(
148 consumer->GetASTMutationListener());
149 Clang->setASTConsumer(std::move(consumer));
157 assert(!SerialBufs.empty());
161 for (
auto &SB : SerialBufs)
162 Bufs.push_back(llvm::MemoryBuffer::getMemBuffer(SB->getBuffer()));
163 std::string pchName = includes[i-1];
164 llvm::raw_string_ostream os(pchName);
166 serialBufNames.push_back(pchName);
170 *Clang, pchName, Bufs, serialBufNames,
171 Clang->getASTConsumer().GetASTDeserializationListener());
174 Clang->setASTReader(Reader);
175 Clang->getASTContext().setExternalSource(Reader);
178 if (!Clang->InitializeSourceManager(InputFile))
182 Clang->getDiagnosticClient().EndSourceFile();
183 assert(Buffer->IsComplete &&
"serialization did not complete");
184 auto &serialAST = Buffer->Data;
185 SerialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(
186 StringRef(serialAST.data(), serialAST.size())));
188 CIs.push_back(std::move(Clang));
191 assert(!SerialBufs.empty());
192 std::string pchName = includes.back() +
".pch-final";
193 serialBufNames.push_back(pchName);
199 llvm::makeIntrusiveRefCnt<ChainedIncludesSource>(std::move(CIs));
200 return llvm::makeIntrusiveRefCnt<MultiplexExternalSemaSource>(
201 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.