diff options
Diffstat (limited to 'lib/Serialization/ChainedIncludesSource.cpp')
-rw-r--r-- | lib/Serialization/ChainedIncludesSource.cpp | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/lib/Serialization/ChainedIncludesSource.cpp b/lib/Serialization/ChainedIncludesSource.cpp index 3b7cd23b92ae..5fcf11a36e3c 100644 --- a/lib/Serialization/ChainedIncludesSource.cpp +++ b/lib/Serialization/ChainedIncludesSource.cpp @@ -26,17 +26,20 @@ using namespace clang; static ASTReader *createASTReader(CompilerInstance &CI, - llvm::StringRef pchFile, - llvm::MemoryBuffer **memBufs, - unsigned numBufs, + StringRef pchFile, + SmallVector<llvm::MemoryBuffer *, 4> &memBufs, + SmallVector<std::string, 4> &bufNames, ASTDeserializationListener *deserialListener = 0) { Preprocessor &PP = CI.getPreprocessor(); llvm::OwningPtr<ASTReader> Reader; - Reader.reset(new ASTReader(PP, &CI.getASTContext(), /*isysroot=*/0, + Reader.reset(new ASTReader(PP, CI.getASTContext(), /*isysroot=*/"", /*DisableValidation=*/true)); - Reader->setASTMemoryBuffers(memBufs, numBufs); + for (unsigned ti = 0; ti < bufNames.size(); ++ti) { + StringRef sr(bufNames[ti]); + Reader->addInMemoryBuffer(sr, memBufs[ti]); + } Reader->setDeserializationListener(deserialListener); - switch (Reader->ReadAST(pchFile, ASTReader::PCH)) { + switch (Reader->ReadAST(pchFile, serialization::MK_PCH)) { case ASTReader::Success: // Set the predefines buffer as suggested by the PCH reader. PP.setPredefines(Reader->getSuggestedPredefines()); @@ -62,7 +65,8 @@ ChainedIncludesSource *ChainedIncludesSource::create(CompilerInstance &CI) { llvm::OwningPtr<ChainedIncludesSource> source(new ChainedIncludesSource()); InputKind IK = CI.getFrontendOpts().Inputs[0].first; - llvm::SmallVector<llvm::MemoryBuffer *, 4> serialBufs; + SmallVector<llvm::MemoryBuffer *, 4> serialBufs; + SmallVector<std::string, 4> serialBufNames; for (unsigned i = 0, e = includes.size(); i != e; ++i) { bool firstInclude = (i == 0); @@ -83,8 +87,8 @@ ChainedIncludesSource *ChainedIncludesSource::create(CompilerInstance &CI) { TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions()); llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); - llvm::IntrusiveRefCntPtr<Diagnostic> Diags(new Diagnostic(DiagID, - DiagClient)); + llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags( + new DiagnosticsEngine(DiagID, DiagClient)); llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance()); Clang->setInvocation(CInvok.take()); @@ -98,16 +102,15 @@ ChainedIncludesSource *ChainedIncludesSource::create(CompilerInstance &CI) { &Clang->getPreprocessor()); Clang->createASTContext(); - llvm::SmallVector<char, 256> serialAST; + SmallVector<char, 256> serialAST; llvm::raw_svector_ostream OS(serialAST); llvm::OwningPtr<ASTConsumer> consumer; consumer.reset(new PCHGenerator(Clang->getPreprocessor(), "-", - /*Chaining=*/!firstInclude, - /*isysroot=*/0, &OS)); + /*IsModule=*/false, /*isysroot=*/"", &OS)); Clang->getASTContext().setASTMutationListener( consumer->GetASTMutationListener()); Clang->setASTConsumer(consumer.take()); - Clang->createSema(/*CompleteTranslationUnit=*/false, 0); + Clang->createSema(TU_Prefix, 0); if (firstInclude) { Preprocessor &PP = Clang->getPreprocessor(); @@ -115,19 +118,23 @@ ChainedIncludesSource *ChainedIncludesSource::create(CompilerInstance &CI) { PP.getLangOptions()); } else { assert(!serialBufs.empty()); - llvm::SmallVector<llvm::MemoryBuffer *, 4> bufs; + SmallVector<llvm::MemoryBuffer *, 4> bufs; for (unsigned si = 0, se = serialBufs.size(); si != se; ++si) { bufs.push_back(llvm::MemoryBuffer::getMemBufferCopy( - llvm::StringRef(serialBufs[si]->getBufferStart(), + StringRef(serialBufs[si]->getBufferStart(), serialBufs[si]->getBufferSize()))); } std::string pchName = includes[i-1]; llvm::raw_string_ostream os(pchName); os << ".pch" << i-1; os.flush(); + + serialBufNames.push_back(pchName); + llvm::OwningPtr<ExternalASTSource> Reader; - Reader.reset(createASTReader(*Clang, pchName, bufs.data(), bufs.size(), - Clang->getASTConsumer().GetASTDeserializationListener())); + + Reader.reset(createASTReader(*Clang, pchName, bufs, serialBufNames, + Clang->getASTConsumer().GetASTDeserializationListener())); if (!Reader) return 0; Clang->getASTContext().setExternalSource(Reader); @@ -140,16 +147,16 @@ ChainedIncludesSource *ChainedIncludesSource::create(CompilerInstance &CI) { OS.flush(); Clang->getDiagnosticClient().EndSourceFile(); serialBufs.push_back( - llvm::MemoryBuffer::getMemBufferCopy(llvm::StringRef(serialAST.data(), + llvm::MemoryBuffer::getMemBufferCopy(StringRef(serialAST.data(), serialAST.size()))); source->CIs.push_back(Clang.take()); } assert(!serialBufs.empty()); std::string pchName = includes.back() + ".pch-final"; + serialBufNames.push_back(pchName); llvm::OwningPtr<ASTReader> Reader; - Reader.reset(createASTReader(CI, pchName, - serialBufs.data(), serialBufs.size())); + Reader.reset(createASTReader(CI, pchName, serialBufs, serialBufNames)); if (!Reader) return 0; @@ -182,13 +189,10 @@ ChainedIncludesSource::FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) { return getFinalReader().FindExternalVisibleDeclsByName(DC, Name); } -void ChainedIncludesSource::MaterializeVisibleDecls(const DeclContext *DC) { - return getFinalReader().MaterializeVisibleDecls(DC); -} ExternalLoadResult ChainedIncludesSource::FindExternalLexicalDecls(const DeclContext *DC, bool (*isKindWeWant)(Decl::Kind), - llvm::SmallVectorImpl<Decl*> &Result) { + SmallVectorImpl<Decl*> &Result) { return getFinalReader().FindExternalLexicalDecls(DC, isKindWeWant, Result); } void ChainedIncludesSource::CompleteType(TagDecl *Tag) { |