[cfe-commits] r100441 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp tools/CIndex/CIndex.cpp tools/CIndex/CIndexDiagnostic.cpp
Douglas Gregor
dgregor at apple.com
Mon Apr 5 11:10:21 PDT 2010
Author: dgregor
Date: Mon Apr 5 13:10:21 2010
New Revision: 100441
URL: http://llvm.org/viewvc/llvm-project?rev=100441&view=rev
Log:
Minor ASTUnit cleanups:
- Rename "Diagnostics" and related to "StoredDiagnostics", to better
capture what we're actually storing.
- Move SourceManager and FileManager to the heap.
Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/tools/CIndex/CIndex.cpp
cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=100441&r1=100440&r2=100441&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Mon Apr 5 13:10:21 2010
@@ -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
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=100441&r1=100440&r2=100441&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Apr 5 13:10:21 2010
@@ -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());
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=100441&r1=100440&r2=100441&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Mon Apr 5 13:10:21 2010
@@ -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.
Modified: cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp?rev=100441&r1=100440&r2=100441&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp Mon Apr 5 13:10:21 2010
@@ -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());
}
More information about the cfe-commits
mailing list