Skip to content

Commit

Permalink
Move ChainedIncludesSource into the implementation
Browse files Browse the repository at this point in the history
This doesn't need to be in the headers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212451 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
atoker committed Jul 7, 2014
1 parent 1e2908f commit 67d62bc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 84 deletions.
75 changes: 0 additions & 75 deletions include/clang/Frontend/ChainedIncludesSource.h

This file was deleted.

7 changes: 7 additions & 0 deletions include/clang/Frontend/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Decl;
class DependencyOutputOptions;
class DiagnosticsEngine;
class DiagnosticOptions;
class ExternalSemaSource;
class FileManager;
class HeaderSearch;
class HeaderSearchOptions;
Expand Down Expand Up @@ -162,6 +163,12 @@ void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false,
/// a seekable stream.
void CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS);

/// The ChainedIncludesSource class converts headers to chained PCHs in
/// memory, mainly for testing.
IntrusiveRefCntPtr<ExternalSemaSource>
createChainedIncludesSource(CompilerInstance &CI,
IntrusiveRefCntPtr<ExternalSemaSource> &Reader);

/// createInvocationFromCommandLine - Construct a compiler invocation object for
/// a command line argument vector.
///
Expand Down
54 changes: 50 additions & 4 deletions lib/Frontend/ChainedIncludesSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

#include "clang/Frontend/ChainedIncludesSource.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/CompilerInstance.h"
Expand All @@ -25,6 +24,54 @@

using namespace clang;

namespace {
class ChainedIncludesSource : public ExternalSemaSource {
public:
virtual ~ChainedIncludesSource();

ExternalSemaSource &getFinalReader() const { return *FinalReader; }

std::vector<CompilerInstance *> CIs;
IntrusiveRefCntPtr<ExternalSemaSource> FinalReader;

protected:
//===----------------------------------------------------------------------===//
// ExternalASTSource interface.
//===----------------------------------------------------------------------===//

Decl *GetExternalDecl(uint32_t ID) override;
Selector GetExternalSelector(uint32_t ID) override;
uint32_t GetNumExternalSelectors() override;
Stmt *GetExternalDeclStmt(uint64_t Offset) override;
CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
bool FindExternalVisibleDeclsByName(const DeclContext *DC,
DeclarationName Name) override;
ExternalLoadResult
FindExternalLexicalDecls(const DeclContext *DC,
bool (*isKindWeWant)(Decl::Kind),
SmallVectorImpl<Decl *> &Result) override;
void CompleteType(TagDecl *Tag) override;
void CompleteType(ObjCInterfaceDecl *Class) override;
void StartedDeserializing() override;
void FinishedDeserializing() override;
void StartTranslationUnit(ASTConsumer *Consumer) override;
void PrintStats() override;

/// Return the amount of memory used by memory buffers, breaking down
/// by heap-backed versus mmap'ed memory.
void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;

//===----------------------------------------------------------------------===//
// ExternalSemaSource interface.
//===----------------------------------------------------------------------===//

void InitializeSema(Sema &S) override;
void ForgetSema() override;
void ReadMethodPool(Selector Sel) override;
bool LookupUnqualified(LookupResult &R, Scope *S) override;
};
}

static ASTReader *
createASTReader(CompilerInstance &CI, StringRef pchFile,
SmallVectorImpl<llvm::MemoryBuffer *> &memBufs,
Expand Down Expand Up @@ -62,8 +109,8 @@ ChainedIncludesSource::~ChainedIncludesSource() {
delete CIs[i];
}

IntrusiveRefCntPtr<ChainedIncludesSource>
ChainedIncludesSource::create(CompilerInstance &CI) {
IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
CompilerInstance &CI, IntrusiveRefCntPtr<ExternalSemaSource> &Reader) {

std::vector<std::string> &includes = CI.getPreprocessorOpts().ChainedIncludes;
assert(!includes.empty() && "No '-chain-include' in options!");
Expand Down Expand Up @@ -156,7 +203,6 @@ ChainedIncludesSource::create(CompilerInstance &CI) {
assert(!serialBufs.empty());
std::string pchName = includes.back() + ".pch-final";
serialBufNames.push_back(pchName);
IntrusiveRefCntPtr<ASTReader> Reader;
Reader = createASTReader(CI, pchName, serialBufs, serialBufNames);
if (!Reader)
return nullptr;
Expand Down
8 changes: 3 additions & 5 deletions lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclGroup.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/ChainedIncludesSource.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
Expand Down Expand Up @@ -315,13 +314,12 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,

if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) {
// Convert headers to PCH and chain them.
IntrusiveRefCntPtr<ChainedIncludesSource> source;
source = ChainedIncludesSource::create(CI);
IntrusiveRefCntPtr<ExternalSemaSource> source, FinalReader;
source = createChainedIncludesSource(CI, FinalReader);
if (!source)
goto failure;
CI.setModuleManager(static_cast<ASTReader*>(&source->getFinalReader()));
CI.setModuleManager(static_cast<ASTReader *>(FinalReader.get()));
CI.getASTContext().setExternalSource(source);

} else if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
// Use PCH.
assert(hasPCHSupport() && "This action does not have PCH support!");
Expand Down

0 comments on commit 67d62bc

Please sign in to comment.