[cfe-commits] r84499 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h include/clang/Index/Indexer.h lib/Frontend/ASTUnit.cpp tools/CIndex/CIndex.cpp tools/clang-cc/clang-cc.cpp tools/index-test/index-test.cpp
Steve Naroff
snaroff at apple.com
Mon Oct 19 07:34:23 PDT 2009
Author: snaroff
Date: Mon Oct 19 09:34:22 2009
New Revision: 84499
URL: http://llvm.org/viewvc/llvm-project?rev=84499&view=rev
Log:
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>).
Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/include/clang/Index/Indexer.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/tools/CIndex/CIndex.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
cfe/trunk/tools/index-test/index-test.cpp
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=84499&r1=84498&r2=84499&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Mon Oct 19 09:34:22 2009
@@ -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 @@
class FileEntry;
class SourceManager;
class Diagnostic;
+ class TextDiagnosticBuffer;
class HeaderSearch;
class TargetInfo;
class Preprocessor;
@@ -32,7 +35,10 @@
/// \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 @@
ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
- ASTUnit(Diagnostic &_Diag);
+ ASTUnit();
public:
~ASTUnit();
@@ -64,7 +70,9 @@
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 @@
///
/// \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);
Modified: cfe/trunk/include/clang/Index/Indexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/Indexer.h?rev=84499&r1=84498&r2=84499&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/Indexer.h (original)
+++ cfe/trunk/include/clang/Index/Indexer.h Mon Oct 19 09:34:22 2009
@@ -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 @@
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 @@
private:
Program &Prog;
- TextDiagnosticBuffer DiagClient;
- Diagnostic Diags;
- FileManager FileMgr;
MapTy Map;
CtxTUMapTy CtxTUMap;
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=84499&r1=84498&r2=84499&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Oct 19 09:34:22 2009
@@ -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 @@
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 @@
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));
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=84499&r1=84498&r2=84499&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Mon Oct 19 09:34:22 2009
@@ -347,8 +347,7 @@
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);
}
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=84499&r1=84498&r2=84499&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Mon Oct 19 09:34:22 2009
@@ -2188,8 +2188,7 @@
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;
Modified: cfe/trunk/tools/index-test/index-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/index-test/index-test.cpp?rev=84499&r1=84498&r2=84499&view=diff
==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Mon Oct 19 09:34:22 2009
@@ -225,8 +225,7 @@
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 @@
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 @@
// 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 "
More information about the cfe-commits
mailing list