aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Frontend/ASTUnit.h34
-rw-r--r--lib/Frontend/ASTUnit.cpp8
-rw-r--r--tools/CIndex/CIndex.cpp6
-rw-r--r--tools/CIndex/CIndexDiagnostic.cpp6
4 files changed, 30 insertions, 24 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index 61db323a12..247df7c1dd 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -52,10 +52,9 @@ public:
typedef std::map<FileID, std::vector<PreprocessedEntity *> >
PreprocessedEntitiesByFileMap;
private:
-
- FileManager FileMgr;
-
- SourceManager SourceMgr;
+ llvm::OwningPtr<Diagnostic> DiagEngine;
+ llvm::OwningPtr<FileManager> FileMgr;
+ llvm::OwningPtr<SourceManager> SourceMgr;
llvm::OwningPtr<HeaderSearch> HeaderInfo;
llvm::OwningPtr<TargetInfo> Target;
llvm::OwningPtr<Preprocessor> PP;
@@ -90,7 +89,7 @@ private:
/// \brief The set of diagnostics produced when creating this
/// translation unit.
- llvm::SmallVector<StoredDiagnostic, 4> Diagnostics;
+ llvm::SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
/// \brief Temporary files that should be removed when the ASTUnit is
/// destroyed.
@@ -142,8 +141,8 @@ public:
bool isMainFileAST() const { return MainFileIsAST; }
- const SourceManager &getSourceManager() const { return SourceMgr; }
- SourceManager &getSourceManager() { return SourceMgr; }
+ const SourceManager &getSourceManager() const { return *SourceMgr; }
+ SourceManager &getSourceManager() { return *SourceMgr; }
const Preprocessor &getPreprocessor() const { return *PP.get(); }
Preprocessor &getPreprocessor() { return *PP.get(); }
@@ -151,8 +150,8 @@ public:
const ASTContext &getASTContext() const { return *Ctx.get(); }
ASTContext &getASTContext() { return *Ctx.get(); }
- const FileManager &getFileManager() const { return FileMgr; }
- FileManager &getFileManager() { return FileMgr; }
+ const FileManager &getFileManager() const { return *FileMgr; }
+ FileManager &getFileManager() { return *FileMgr; }
const std::string &getOriginalSourceFileName();
const std::string &getPCHFileName();
@@ -185,12 +184,17 @@ public:
}
// Retrieve the diagnostics associated with this AST
- typedef const StoredDiagnostic * diag_iterator;
- diag_iterator diag_begin() const { return Diagnostics.begin(); }
- diag_iterator diag_end() const { return Diagnostics.end(); }
- unsigned diag_size() const { return Diagnostics.size(); }
- llvm::SmallVector<StoredDiagnostic, 4> &getDiagnostics() {
- return Diagnostics;
+ typedef const StoredDiagnostic *stored_diag_iterator;
+ stored_diag_iterator stored_diag_begin() const {
+ return StoredDiagnostics.begin();
+ }
+ stored_diag_iterator stored_diag_end() const {
+ return StoredDiagnostics.end();
+ }
+ unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
+
+ llvm::SmallVector<StoredDiagnostic, 4> &getStoredDiagnostics() {
+ return StoredDiagnostics;
}
/// \brief A mapping from a file name to the memory buffer that stores the
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 7243f709cc..38aeedc39a 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -36,8 +36,10 @@
using namespace clang;
ASTUnit::ASTUnit(Diagnostic &Diag, bool _MainFileIsAST)
- : SourceMgr(Diag), MainFileIsAST(_MainFileIsAST),
+ : MainFileIsAST(_MainFileIsAST),
ConcurrencyCheckValue(CheckUnlocked) {
+ FileMgr.reset(new FileManager);
+ SourceMgr.reset(new SourceManager(Diag));
}
ASTUnit::~ASTUnit() {
ConcurrencyCheckValue = CheckLocked;
@@ -153,7 +155,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
// If requested, capture diagnostics in the ASTUnit.
CaptureDroppedDiagnostics Capture(CaptureDiagnostics, Diags,
- AST->Diagnostics);
+ AST->StoredDiagnostics);
for (unsigned I = 0; I != NumRemappedFiles; ++I) {
// Create the file entry for the file that we're mapping from.
@@ -317,7 +319,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
// Capture any diagnostics that would otherwise be dropped.
CaptureDroppedDiagnostics Capture(CaptureDiagnostics,
Clang.getDiagnostics(),
- AST->Diagnostics);
+ AST->StoredDiagnostics);
// Create a file manager object to provide access to and cache the filesystem.
Clang.setFileManager(&AST->getFileManager());
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 2d9b2cb376..9db5ba79ce 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -1064,8 +1064,8 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
if (NumErrors != Diags->getNumErrors()) {
// Make sure to check that 'Unit' is non-NULL.
if (CXXIdx->getDisplayDiagnostics() && Unit.get()) {
- for (ASTUnit::diag_iterator D = Unit->diag_begin(),
- DEnd = Unit->diag_end();
+ for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),
+ DEnd = Unit->stored_diag_end();
D != DEnd; ++D) {
CXStoredDiagnostic Diag(*D, Unit->getASTContext().getLangOptions());
CXString Msg = clang_formatDiagnostic(&Diag,
@@ -1179,7 +1179,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
num_unsaved_files, unsaved_files,
ATU->getFileManager(),
ATU->getSourceManager(),
- ATU->getDiagnostics());
+ ATU->getStoredDiagnostics());
} else if (CXXIdx->getDisplayDiagnostics()) {
// We failed to load the ASTUnit, but we can still deserialize the
// diagnostics and emit them.
diff --git a/tools/CIndex/CIndexDiagnostic.cpp b/tools/CIndex/CIndexDiagnostic.cpp
index 0314a67d07..bcf066daf2 100644
--- a/tools/CIndex/CIndexDiagnostic.cpp
+++ b/tools/CIndex/CIndexDiagnostic.cpp
@@ -32,15 +32,15 @@ extern "C" {
unsigned clang_getNumDiagnostics(CXTranslationUnit Unit) {
ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit);
- return CXXUnit? CXXUnit->diag_size() : 0;
+ return CXXUnit? CXXUnit->stored_diag_size() : 0;
}
CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, unsigned Index) {
ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit);
- if (!CXXUnit || Index >= CXXUnit->diag_size())
+ if (!CXXUnit || Index >= CXXUnit->stored_diag_size())
return 0;
- return new CXStoredDiagnostic(CXXUnit->diag_begin()[Index],
+ return new CXStoredDiagnostic(CXXUnit->stored_diag_begin()[Index],
CXXUnit->getASTContext().getLangOptions());
}