23 #include "llvm/Support/MemoryBuffer.h"
25 using namespace clang;
30 ~ChainedIncludesSource()
override;
34 std::vector<CompilerInstance *> CIs;
42 Decl *GetExternalDecl(uint32_t
ID)
override;
43 Selector GetExternalSelector(uint32_t
ID)
override;
44 uint32_t GetNumExternalSelectors()
override;
45 Stmt *GetExternalDeclStmt(uint64_t
Offset)
override;
48 bool FindExternalVisibleDeclsByName(
const DeclContext *DC,
54 void CompleteType(
TagDecl *Tag)
override;
56 void StartedDeserializing()
override;
57 void FinishedDeserializing()
override;
58 void StartTranslationUnit(
ASTConsumer *Consumer)
override;
59 void PrintStats()
override;
63 void getMemoryBufferSizes(MemoryBufferSizes &sizes)
const override;
69 void InitializeSema(
Sema &
S)
override;
70 void ForgetSema()
override;
71 void ReadMethodPool(
Selector Sel)
override;
82 std::unique_ptr<ASTReader> Reader;
86 for (
unsigned ti = 0; ti < bufNames.size(); ++ti) {
87 StringRef sr(bufNames[ti]);
88 Reader->addInMemoryBuffer(sr, std::move(MemBufs[ti]));
90 Reader->setDeserializationListener(deserialListener);
96 return Reader.release();
109 ChainedIncludesSource::~ChainedIncludesSource() {
110 for (
unsigned i = 0, e = CIs.size(); i != e; ++i)
118 assert(!includes.empty() &&
"No '-chain-include' in options!");
126 for (
unsigned i = 0, e = includes.size(); i != e; ++i) {
127 bool firstInclude = (i == 0);
128 std::unique_ptr<CompilerInvocation> CInvok;
131 CInvok->getPreprocessorOpts().ChainedIncludes.clear();
132 CInvok->getPreprocessorOpts().ImplicitPCHInclude.clear();
133 CInvok->getPreprocessorOpts().ImplicitPTHInclude.clear();
134 CInvok->getPreprocessorOpts().DisablePCHValidation =
true;
135 CInvok->getPreprocessorOpts().Includes.clear();
136 CInvok->getPreprocessorOpts().MacroIncludes.clear();
137 CInvok->getPreprocessorOpts().Macros.clear();
139 CInvok->getFrontendOpts().Inputs.clear();
141 CInvok->getFrontendOpts().Inputs.push_back(InputFile);
149 std::unique_ptr<CompilerInstance> Clang(
151 Clang->setInvocation(CInvok.release());
152 Clang->setDiagnostics(Diags.get());
154 Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
155 Clang->createFileManager();
156 Clang->createSourceManager(Clang->getFileManager());
158 Clang->getDiagnosticClient().BeginSourceFile(Clang->getLangOpts(),
159 &Clang->getPreprocessor());
160 Clang->createASTContext();
162 auto Buffer = std::make_shared<PCHBuffer>();
163 auto consumer = llvm::make_unique<PCHGenerator>(
164 Clang->getPreprocessor(),
"-",
nullptr,
"", Buffer);
165 Clang->getASTContext().setASTMutationListener(
166 consumer->GetASTMutationListener());
167 Clang->setASTConsumer(std::move(consumer));
175 assert(!SerialBufs.empty());
179 for (
auto &SB : SerialBufs)
180 Bufs.push_back(llvm::MemoryBuffer::getMemBuffer(SB->getBuffer()));
181 std::string pchName = includes[i-1];
182 llvm::raw_string_ostream os(pchName);
184 serialBufNames.push_back(os.str());
188 *Clang, pchName, Bufs, serialBufNames,
189 Clang->getASTConsumer().GetASTDeserializationListener());
192 Clang->setModuleManager(Reader);
193 Clang->getASTContext().setExternalSource(Reader);
196 if (!Clang->InitializeSourceManager(InputFile))
200 Clang->getDiagnosticClient().EndSourceFile();
201 assert(Buffer->IsComplete &&
"serialization did not complete");
202 auto &serialAST = Buffer->Data;
203 SerialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(
204 StringRef(serialAST.data(), serialAST.size())));
206 source->CIs.push_back(Clang.release());
209 assert(!SerialBufs.empty());
210 std::string pchName = includes.back() +
".pch-final";
211 serialBufNames.push_back(pchName);
216 source->FinalReader = Reader;
224 Decl *ChainedIncludesSource::GetExternalDecl(uint32_t
ID) {
225 return getFinalReader().GetExternalDecl(ID);
227 Selector ChainedIncludesSource::GetExternalSelector(uint32_t ID) {
228 return getFinalReader().GetExternalSelector(ID);
230 uint32_t ChainedIncludesSource::GetNumExternalSelectors() {
231 return getFinalReader().GetNumExternalSelectors();
233 Stmt *ChainedIncludesSource::GetExternalDeclStmt(uint64_t
Offset) {
234 return getFinalReader().GetExternalDeclStmt(Offset);
237 ChainedIncludesSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
238 return getFinalReader().GetExternalCXXBaseSpecifiers(Offset);
241 ChainedIncludesSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
242 return getFinalReader().GetExternalCXXCtorInitializers(Offset);
245 ChainedIncludesSource::FindExternalVisibleDeclsByName(
const DeclContext *DC,
247 return getFinalReader().FindExternalVisibleDeclsByName(DC, Name);
250 ChainedIncludesSource::FindExternalLexicalDecls(
const DeclContext *DC,
253 return getFinalReader().FindExternalLexicalDecls(DC, isKindWeWant, Result);
255 void ChainedIncludesSource::CompleteType(
TagDecl *Tag) {
256 return getFinalReader().CompleteType(Tag);
259 return getFinalReader().CompleteType(Class);
261 void ChainedIncludesSource::StartedDeserializing() {
262 return getFinalReader().StartedDeserializing();
264 void ChainedIncludesSource::FinishedDeserializing() {
265 return getFinalReader().FinishedDeserializing();
267 void ChainedIncludesSource::StartTranslationUnit(
ASTConsumer *Consumer) {
268 return getFinalReader().StartTranslationUnit(Consumer);
270 void ChainedIncludesSource::PrintStats() {
271 return getFinalReader().PrintStats();
273 void ChainedIncludesSource::getMemoryBufferSizes(MemoryBufferSizes &sizes)
const{
274 for (
unsigned i = 0, e = CIs.size(); i != e; ++i) {
276 CIs[i]->getASTContext().getExternalSource()) {
277 eSrc->getMemoryBufferSizes(sizes);
281 getFinalReader().getMemoryBufferSizes(sizes);
284 void ChainedIncludesSource::InitializeSema(
Sema &
S) {
285 return getFinalReader().InitializeSema(S);
287 void ChainedIncludesSource::ForgetSema() {
288 return getFinalReader().ForgetSema();
290 void ChainedIncludesSource::ReadMethodPool(
Selector Sel) {
291 getFinalReader().ReadMethodPool(Sel);
294 return getFinalReader().LookupUnqualified(R, S);
ASTContext & getASTContext() const
CompilerInvocation & getInvocation()
PreprocessorOptions & getPreprocessorOpts()
Smart pointer class that efficiently represents Objective-C method names.
IntrusiveRefCntPtr< ExternalSemaSource > createChainedIncludesSource(CompilerInstance &CI, IntrusiveRefCntPtr< ExternalSemaSource > &Reader)
DiagnosticOptions & getDiagnosticOpts()
The translation unit is a prefix to a translation unit, and is not complete.
static ASTReader * createASTReader(CompilerInstance &CI, StringRef pchFile, SmallVectorImpl< std::unique_ptr< llvm::MemoryBuffer >> &MemBufs, SmallVectorImpl< std::string > &bufNames, ASTDeserializationListener *deserialListener=nullptr)
Builtin::Context & getBuiltinInfo()
void setPredefines(const char *P)
Set the predefines for this Preprocessor.
const LangOptions & getLangOpts() const
Represents the results of name lookup.
FrontendOptions & getFrontendOpts()
Concrete class used by the front-end to report problems and issues.
Represents an ObjC class declaration.
The AST file itself appears corrupted.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Sema - This implements semantic analysis and AST building for C.
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
ID
Defines the set of possible language-specific address spaces.
ExternalLoadResult
Enumeration describing the result of loading information from an external source. ...
Defines the clang::Preprocessor interface.
static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)
Construct a target for the given options.
The result type of a method or function.
The client can't handle any AST loading failures.
The AST file was missing.
An abstract interface that should be implemented by external AST sources that also provide informatio...
Abstract interface for external sources of AST nodes.
The control block was read successfully. Aside from failures, the AST file is safe to read into the c...
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
const PCHContainerReader & getPCHContainerReader() const
File is a PCH file treated as such.
Options for controlling the compiler diagnostics engine.
std::vector< FrontendInputFile > Inputs
The input files and their types.
TagDecl - Represents the declaration of a struct/union/class/enum.
IdentifierTable & getIdentifierTable()
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. ...
std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const
The AST file was writtten with a different language/target configuration.
Reads an AST files chain containing the contents of a translation unit.
Used for handling and querying diagnostic IDs.
Helper class for holding the data necessary to invoke the compiler.
Represents a C++ base or member initializer.
Represents a base class of a C++ class.
void InitializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
Defines the clang::TargetInfo interface.
The AST file is out-of-date relative to its input files, and needs to be regenerated.
Kind
Lists the kind of concrete classes of Decl.
The AST file was written by a different version of Clang.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.