Minor ASTUnit cleanups:
- Rename "Diagnostics" and related to "StoredDiagnostics", to better
capture what we're actually storing.
- Move SourceManager and FileManager to the heap.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100441 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index 61db323..247df7c 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -52,10 +52,9 @@
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 @@
/// \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 @@
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 @@
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 @@
}
// 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 7243f70..38aeedc 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 @@
// 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 @@
// 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 2d9b2cb..9db5ba7 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -1064,8 +1064,8 @@
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 @@
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 0314a67..bcf066d 100644
--- a/tools/CIndex/CIndexDiagnostic.cpp
+++ b/tools/CIndex/CIndexDiagnostic.cpp
@@ -32,15 +32,15 @@
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());
}