Move HeaderSearchOptions into the Lex library, make it intrusively

reference-counted, and hold a reference to it in HeaderSearch.

llvm-svn: 166583
This commit is contained in:
Douglas Gregor 2012-10-24 16:19:39 +00:00
parent 5a2783d522
commit b85b9ccb76
9 changed files with 50 additions and 29 deletions

View File

@ -19,6 +19,7 @@
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Lex/ModuleLoader.h"
#include "clang/Lex/PreprocessingRecord.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/AST/ASTContext.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h"
@ -63,15 +64,16 @@ class ASTDeserializationListener;
///
class ASTUnit : public ModuleLoader {
private:
IntrusiveRefCntPtr<LangOptions> LangOpts;
IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
IntrusiveRefCntPtr<FileManager> FileMgr;
IntrusiveRefCntPtr<SourceManager> SourceMgr;
OwningPtr<HeaderSearch> HeaderInfo;
IntrusiveRefCntPtr<TargetInfo> Target;
IntrusiveRefCntPtr<Preprocessor> PP;
IntrusiveRefCntPtr<ASTContext> Ctx;
IntrusiveRefCntPtr<TargetOptions> TargetOpts;
IntrusiveRefCntPtr<LangOptions> LangOpts;
IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
IntrusiveRefCntPtr<FileManager> FileMgr;
IntrusiveRefCntPtr<SourceManager> SourceMgr;
OwningPtr<HeaderSearch> HeaderInfo;
IntrusiveRefCntPtr<TargetInfo> Target;
IntrusiveRefCntPtr<Preprocessor> PP;
IntrusiveRefCntPtr<ASTContext> Ctx;
IntrusiveRefCntPtr<TargetOptions> TargetOpts;
IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts;
ASTReader *Reader;
struct ASTWriterData;

View File

@ -14,12 +14,12 @@
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "clang/Frontend/MigratorOptions.h"
#include "clang/Frontend/CodeGenOptions.h"
#include "clang/Frontend/DependencyOutputOptions.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/Frontend/HeaderSearchOptions.h"
#include "clang/Frontend/LangStandard.h"
#include "clang/Frontend/PreprocessorOptions.h"
#include "clang/Frontend/PreprocessorOutputOptions.h"
@ -59,6 +59,9 @@ protected:
/// Options controlling the diagnostic engine.
IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts;
/// Options controlling the \#include directive.
IntrusiveRefCntPtr<HeaderSearchOptions> HeaderSearchOpts;
public:
CompilerInvocationBase();
@ -73,6 +76,11 @@ public:
}
DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
const HeaderSearchOptions &getHeaderSearchOpts() const {
return *HeaderSearchOpts;
}
};
/// \brief Helper class for holding the data necessary to invoke the compiler.
@ -98,9 +106,6 @@ class CompilerInvocation : public CompilerInvocationBase {
/// Options controlling the frontend itself.
FrontendOptions FrontendOpts;
/// Options controlling the \#include directive.
HeaderSearchOptions HeaderSearchOpts;
/// Options controlling the preprocessor (aside from \#include handling).
PreprocessorOptions PreprocessorOpts;
@ -182,11 +187,6 @@ public:
return FileSystemOpts;
}
HeaderSearchOptions &getHeaderSearchOpts() { return HeaderSearchOpts; }
const HeaderSearchOptions &getHeaderSearchOpts() const {
return HeaderSearchOpts;
}
FrontendOptions &getFrontendOpts() { return FrontendOpts; }
const FrontendOptions &getFrontendOpts() const {
return FrontendOpts;

View File

@ -17,6 +17,7 @@
#include "clang/Lex/DirectoryLookup.h"
#include "clang/Lex/ModuleMap.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Allocator.h"
@ -29,6 +30,7 @@ class DiagnosticsEngine;
class ExternalIdentifierLookup;
class FileEntry;
class FileManager;
class HeaderSearchOptions;
class IdentifierInfo;
/// \brief The preprocessor keeps track of this information for each
@ -131,6 +133,9 @@ class HeaderSearch {
bool IsUserSpecifiedSystemFramework;
};
/// \brief Header-search options used to initialize this header search.
llvm::IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts;
FileManager &FileMgr;
/// \#include search path information. Requests for \#include "x" search the
/// directory of the \#including file first, then each directory in SearchDirs
@ -212,10 +217,15 @@ class HeaderSearch {
friend class DirectoryLookup;
public:
HeaderSearch(FileManager &FM, DiagnosticsEngine &Diags,
HeaderSearch(llvm::IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts,
FileManager &FM, DiagnosticsEngine &Diags,
const LangOptions &LangOpts, const TargetInfo *Target);
~HeaderSearch();
/// \brief Retrieve the header-search options with which this header search
/// was initialized.
HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; }
FileManager &getFileMgr() const { return FileMgr; }
/// \brief Interface for setting the file search paths.

View File

@ -7,9 +7,10 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_FRONTEND_HEADERSEARCHOPTIONS_H
#define LLVM_CLANG_FRONTEND_HEADERSEARCHOPTIONS_H
#ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
#define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringRef.h"
#include <vector>
@ -36,7 +37,7 @@ namespace frontend {
/// HeaderSearchOptions - Helper class for storing options related to the
/// initialization of the HeaderSearch object.
class HeaderSearchOptions {
class HeaderSearchOptions : public llvm::RefCountedBase<HeaderSearchOptions> {
public:
struct Entry {
std::string Path;

View File

@ -709,7 +709,10 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
AST->getFileManager(),
UserFilesAreVolatile);
AST->HeaderInfo.reset(new HeaderSearch(AST->getFileManager(),
AST->HSOpts = new HeaderSearchOptions();
AST->HeaderInfo.reset(new HeaderSearch(AST->HSOpts,
AST->getFileManager(),
AST->getDiagnostics(),
AST->ASTFileLangOpts,
/*Target=*/0));

View File

@ -242,7 +242,8 @@ void CompilerInstance::createPreprocessor() {
PTHMgr = PTHManager::Create(PPOpts.TokenCache, getDiagnostics());
// Create the Preprocessor.
HeaderSearch *HeaderInfo = new HeaderSearch(getFileManager(),
HeaderSearch *HeaderInfo = new HeaderSearch(&getHeaderSearchOpts(),
getFileManager(),
getDiagnostics(),
getLangOpts(),
&getTarget());

View File

@ -36,13 +36,15 @@ using namespace clang;
CompilerInvocationBase::CompilerInvocationBase()
: LangOpts(new LangOptions()), TargetOpts(new TargetOptions()),
DiagnosticOpts(new DiagnosticOptions()) {}
DiagnosticOpts(new DiagnosticOptions()),
HeaderSearchOpts(new HeaderSearchOptions()) {}
CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X)
: RefCountedBase<CompilerInvocation>(),
LangOpts(new LangOptions(*X.getLangOpts())),
TargetOpts(new TargetOptions(X.getTargetOpts())),
DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())) {}
DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())),
HeaderSearchOpts(new HeaderSearchOptions(X.getHeaderSearchOpts())) {}
//===----------------------------------------------------------------------===//
// Utility functions.

View File

@ -14,7 +14,7 @@
#include "clang/Frontend/Utils.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Frontend/HeaderSearchOptions.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/HeaderSearch.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallPtrSet.h"

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/HeaderMap.h"
#include "clang/Lex/Lexer.h"
#include "clang/Basic/Diagnostic.h"
@ -38,10 +39,11 @@ HeaderFileInfo::getControllingMacro(ExternalIdentifierLookup *External) {
ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() {}
HeaderSearch::HeaderSearch(FileManager &FM, DiagnosticsEngine &Diags,
HeaderSearch::HeaderSearch(llvm::IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts,
FileManager &FM, DiagnosticsEngine &Diags,
const LangOptions &LangOpts,
const TargetInfo *Target)
: FileMgr(FM), FrameworkMap(64),
: HSOpts(HSOpts), FileMgr(FM), FrameworkMap(64),
ModMap(FileMgr, *Diags.getClient(), LangOpts, Target)
{
AngledDirIdx = 0;