зеркало из https://github.com/microsoft/clang-1.git
Move Diagnostic/DiagClient/FileManager from Indexer => ASTUnit.
Removing this shared data should enable clang_createTranslationUnit/clang_createTranslationUnitFromSourceFile to be run from multiple threads (related to <rdar://problem/7303432>). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84499 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
bade7de59d
Коммит
36c4464ba6
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include <string>
|
||||
|
||||
namespace clang {
|
||||
|
@ -23,6 +25,7 @@ namespace clang {
|
|||
class FileEntry;
|
||||
class SourceManager;
|
||||
class Diagnostic;
|
||||
class TextDiagnosticBuffer;
|
||||
class HeaderSearch;
|
||||
class TargetInfo;
|
||||
class Preprocessor;
|
||||
|
@ -32,7 +35,10 @@ namespace clang {
|
|||
/// \brief Utility class for loading a ASTContext from a PCH file.
|
||||
///
|
||||
class ASTUnit {
|
||||
Diagnostic &Diags;
|
||||
TextDiagnosticBuffer DiagClient;
|
||||
Diagnostic Diags;
|
||||
FileManager FileMgr;
|
||||
|
||||
SourceManager SourceMgr;
|
||||
llvm::OwningPtr<HeaderSearch> HeaderInfo;
|
||||
llvm::OwningPtr<TargetInfo> Target;
|
||||
|
@ -47,7 +53,7 @@ class ASTUnit {
|
|||
|
||||
ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
|
||||
ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
|
||||
ASTUnit(Diagnostic &_Diag);
|
||||
ASTUnit();
|
||||
|
||||
public:
|
||||
~ASTUnit();
|
||||
|
@ -64,7 +70,9 @@ public:
|
|||
const Diagnostic &getDiagnostic() const { return Diags; }
|
||||
Diagnostic &getDiagnostic() { return Diags; }
|
||||
|
||||
FileManager &getFileManager();
|
||||
const FileManager &getFileManager() const { return FileMgr; }
|
||||
FileManager &getFileManager() { return FileMgr; }
|
||||
|
||||
const std::string &getOriginalSourceFileName();
|
||||
const std::string &getPCHFileName();
|
||||
|
||||
|
@ -85,8 +93,6 @@ public:
|
|||
///
|
||||
/// \returns - The initialized ASTUnit or null if the PCH failed to load.
|
||||
static ASTUnit *LoadFromPCHFile(const std::string &Filename,
|
||||
Diagnostic &Diags,
|
||||
FileManager &FileMgr,
|
||||
std::string *ErrMsg = 0,
|
||||
bool OnlyLocalDecls = false,
|
||||
bool UseBumpAllocator = false);
|
||||
|
|
|
@ -14,13 +14,11 @@
|
|||
#ifndef LLVM_CLANG_INDEX_INDEXER_H
|
||||
#define LLVM_CLANG_INDEX_INDEXER_H
|
||||
|
||||
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
||||
#include "clang/Index/IndexProvider.h"
|
||||
#include "clang/Index/Entity.h"
|
||||
#include "clang/Index/GlobalSelector.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include <map>
|
||||
|
||||
namespace clang {
|
||||
|
@ -39,16 +37,10 @@ public:
|
|||
typedef std::map<GlobalSelector, TUSetTy> SelMapTy;
|
||||
|
||||
explicit Indexer(Program &prog) :
|
||||
Prog(prog), Diags(&DiagClient) { }
|
||||
Prog(prog) { }
|
||||
|
||||
Program &getProgram() const { return Prog; }
|
||||
|
||||
Diagnostic &getDiagnostics() { return Diags; }
|
||||
const Diagnostic &getDiagnostics() const { return Diags; }
|
||||
|
||||
FileManager &getFileManager() { return FileMgr; }
|
||||
const FileManager &getFileManager() const { return FileMgr; }
|
||||
|
||||
/// \brief Find all Entities and map them to the given translation unit.
|
||||
void IndexAST(TranslationUnit *TU);
|
||||
|
||||
|
@ -59,9 +51,6 @@ public:
|
|||
|
||||
private:
|
||||
Program &Prog;
|
||||
TextDiagnosticBuffer DiagClient;
|
||||
Diagnostic Diags;
|
||||
FileManager FileMgr;
|
||||
|
||||
MapTy Map;
|
||||
CtxTUMapTy CtxTUMap;
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
|
||||
using namespace clang;
|
||||
|
||||
ASTUnit::ASTUnit(Diagnostic &_Diags) : Diags(_Diags), tempFile(false) { }
|
||||
ASTUnit::ASTUnit() : tempFile(false) {
|
||||
Diags.setClient(&DiagClient);
|
||||
}
|
||||
ASTUnit::~ASTUnit() {
|
||||
if (tempFile)
|
||||
llvm::sys::Path(getPCHFileName()).eraseFromDisk();
|
||||
|
@ -88,19 +90,13 @@ const std::string &ASTUnit::getPCHFileName() {
|
|||
return dyn_cast<PCHReader>(Ctx->getExternalSource())->getFileName();
|
||||
}
|
||||
|
||||
FileManager &ASTUnit::getFileManager() {
|
||||
return HeaderInfo->getFileMgr();
|
||||
}
|
||||
|
||||
ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
|
||||
Diagnostic &Diags,
|
||||
FileManager &FileMgr,
|
||||
std::string *ErrMsg,
|
||||
bool OnlyLocalDecls,
|
||||
bool UseBumpAllocator) {
|
||||
llvm::OwningPtr<ASTUnit> AST(new ASTUnit(Diags));
|
||||
llvm::OwningPtr<ASTUnit> AST(new ASTUnit());
|
||||
AST->OnlyLocalDecls = OnlyLocalDecls;
|
||||
AST->HeaderInfo.reset(new HeaderSearch(FileMgr));
|
||||
AST->HeaderInfo.reset(new HeaderSearch(AST->getFileManager()));
|
||||
|
||||
// Gather Info for preprocessor construction later on.
|
||||
|
||||
|
@ -113,7 +109,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
|
|||
llvm::OwningPtr<PCHReader> Reader;
|
||||
llvm::OwningPtr<ExternalASTSource> Source;
|
||||
|
||||
Reader.reset(new PCHReader(AST->getSourceManager(), FileMgr, AST->Diags));
|
||||
Reader.reset(new PCHReader(AST->getSourceManager(), AST->getFileManager(), AST->Diags));
|
||||
Reader->setListener(new PCHInfoCollector(LangInfo, HeaderInfo, TargetTriple,
|
||||
Predefines, Counter));
|
||||
|
||||
|
|
|
@ -347,8 +347,7 @@ CXTranslationUnit clang_createTranslationUnit(
|
|||
std::string astName(ast_filename);
|
||||
std::string ErrMsg;
|
||||
|
||||
return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getDiagnostics(),
|
||||
CXXIdx->getFileManager(), &ErrMsg,
|
||||
return ASTUnit::LoadFromPCHFile(astName, &ErrMsg,
|
||||
CXXIdx->getOnlyLocalDecls(),
|
||||
/* UseBumpAllocator = */ true);
|
||||
}
|
||||
|
|
|
@ -2188,8 +2188,7 @@ static void ProcessASTInputFile(const std::string &InFile, ProgActions PA,
|
|||
Diagnostic &Diags, FileManager &FileMgr,
|
||||
llvm::LLVMContext& Context) {
|
||||
std::string Error;
|
||||
llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, Diags, FileMgr,
|
||||
&Error));
|
||||
llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, &Error));
|
||||
if (!AST) {
|
||||
Diags.Report(FullSourceLoc(), diag::err_fe_invalid_ast_file) << Error;
|
||||
return;
|
||||
|
|
|
@ -225,8 +225,7 @@ int main(int argc, char **argv) {
|
|||
std::string ErrMsg;
|
||||
llvm::OwningPtr<ASTUnit> AST;
|
||||
|
||||
AST.reset(ASTUnit::LoadFromPCHFile(InFile, Idxer.getDiagnostics(),
|
||||
Idxer.getFileManager(), &ErrMsg));
|
||||
AST.reset(ASTUnit::LoadFromPCHFile(InFile, &ErrMsg));
|
||||
if (!AST) {
|
||||
llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n';
|
||||
return 1;
|
||||
|
@ -244,7 +243,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (!PointAtLocation.empty()) {
|
||||
const std::string &Filename = PointAtLocation[0].FileName;
|
||||
const FileEntry *File = Idxer.getFileManager().getFile(Filename);
|
||||
const FileEntry *File = FirstAST->getFileManager().getFile(Filename);
|
||||
if (File == 0) {
|
||||
llvm::errs() << "File '" << Filename << "' does not exist\n";
|
||||
return 1;
|
||||
|
@ -253,7 +252,7 @@ int main(int argc, char **argv) {
|
|||
// Safety check. Using an out-of-date AST file will only lead to crashes
|
||||
// or incorrect results.
|
||||
// FIXME: Check all the source files that make up the AST file.
|
||||
const FileEntry *ASTFile = Idxer.getFileManager().getFile(FirstFile);
|
||||
const FileEntry *ASTFile = FirstAST->getFileManager().getFile(FirstFile);
|
||||
if (File->getModificationTime() > ASTFile->getModificationTime()) {
|
||||
llvm::errs() << "[" << FirstFile << "] Error: " <<
|
||||
"Pointing at a source file which was modified after creating "
|
||||
|
|
Загрузка…
Ссылка в новой задаче