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