[cfe-commits] r82430 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp tools/CIndex/CIndex.cpp tools/clang-cc/clang-cc.cpp tools/index-test/index-test.cpp tools/wpa/clang-wpa.cpp
Daniel Dunbar
daniel at zuster.org
Sun Sep 20 20:03:39 PDT 2009
Author: ddunbar
Date: Sun Sep 20 22:03:39 2009
New Revision: 82430
URL: http://llvm.org/viewvc/llvm-project?rev=82430&view=rev
Log:
Change ASTUnit to take the Diagnostic as an argument, the client should have control of this.
Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.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
cfe/trunk/tools/wpa/clang-wpa.cpp
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=82430&r1=82429&r2=82430&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Sun Sep 20 22:03:39 2009
@@ -14,6 +14,7 @@
#ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H
#define LLVM_CLANG_FRONTEND_ASTUNIT_H
+#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/OwningPtr.h"
#include <string>
@@ -21,7 +22,6 @@
class FileManager;
class FileEntry;
class SourceManager;
- class DiagnosticClient;
class Diagnostic;
class HeaderSearch;
class TargetInfo;
@@ -32,23 +32,22 @@
/// \brief Utility class for loading a ASTContext from a PCH file.
///
class ASTUnit {
- llvm::OwningPtr<SourceManager> SourceMgr;
- llvm::OwningPtr<DiagnosticClient> DiagClient;
- llvm::OwningPtr<Diagnostic> Diags;
+ Diagnostic &Diags;
+ SourceManager SourceMgr;
llvm::OwningPtr<HeaderSearch> HeaderInfo;
llvm::OwningPtr<TargetInfo> Target;
llvm::OwningPtr<Preprocessor> PP;
llvm::OwningPtr<ASTContext> Ctx;
- ASTUnit(const ASTUnit&); // do not implement
- ASTUnit &operator=(const ASTUnit &); // do not implement
- ASTUnit();
+ ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
+ ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
+ ASTUnit(Diagnostic &_Diag);
public:
~ASTUnit();
- const SourceManager &getSourceManager() const { return *SourceMgr.get(); }
- SourceManager &getSourceManager() { return *SourceMgr.get(); }
+ const SourceManager &getSourceManager() const { return SourceMgr; }
+ SourceManager &getSourceManager() { return SourceMgr; }
const Preprocessor &getPreprocessor() const { return *PP.get(); }
Preprocessor &getPreprocessor() { return *PP.get(); }
@@ -56,22 +55,26 @@
const ASTContext &getASTContext() const { return *Ctx.get(); }
ASTContext &getASTContext() { return *Ctx.get(); }
- const Diagnostic &getDiagnostic() const { return *Diags.get(); }
- Diagnostic &getDiagnostic() { return *Diags.get(); }
+ const Diagnostic &getDiagnostic() const { return Diags; }
+ Diagnostic &getDiagnostic() { return Diags; }
FileManager &getFileManager();
const std::string &getOriginalSourceFileName();
/// \brief Create a ASTUnit from a PCH file.
///
- /// \param Filename PCH filename
+ /// \param Filename - The PCH file to load.
///
- /// \param FileMgr The FileManager to use
+ /// \param Diags - The Diagnostic implementation to use.
///
- /// \param ErrMsg Error message to report if the PCH file could not be loaded
+ /// \param FileMgr - The FileManager to use.
///
- /// \returns the initialized ASTUnit or NULL if the PCH failed to load
+ /// \param ErrMsg - Error message to report if the PCH file could not be
+ /// loaded.
+ ///
+ /// \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);
};
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=82430&r1=82429&r2=82430&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Sun Sep 20 22:03:39 2009
@@ -13,7 +13,6 @@
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/PCHReader.h"
-#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/StmtVisitor.h"
@@ -25,7 +24,7 @@
using namespace clang;
-ASTUnit::ASTUnit() { }
+ASTUnit::ASTUnit(Diagnostic &_Diags) : Diags(_Diags) { }
ASTUnit::~ASTUnit() { }
namespace {
@@ -86,19 +85,12 @@
}
ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
+ Diagnostic &Diags,
FileManager &FileMgr,
std::string *ErrMsg) {
-
- llvm::OwningPtr<ASTUnit> AST(new ASTUnit());
-
- AST->DiagClient.reset(new TextDiagnosticBuffer());
- AST->Diags.reset(new Diagnostic(AST->DiagClient.get()));
+ llvm::OwningPtr<ASTUnit> AST(new ASTUnit(Diags));
AST->HeaderInfo.reset(new HeaderSearch(FileMgr));
- AST->SourceMgr.reset(new SourceManager());
-
- Diagnostic &Diags = *AST->Diags.get();
- SourceManager &SourceMgr = *AST->SourceMgr.get();
// Gather Info for preprocessor construction later on.
@@ -111,7 +103,7 @@
llvm::OwningPtr<PCHReader> Reader;
llvm::OwningPtr<ExternalASTSource> Source;
- Reader.reset(new PCHReader(SourceMgr, FileMgr, Diags));
+ Reader.reset(new PCHReader(AST->getSourceManager(), FileMgr, AST->Diags));
Reader->setListener(new PCHInfoCollector(LangInfo, HeaderInfo, TargetTriple,
Predefines, Counter));
@@ -130,8 +122,8 @@
// Get information about the target being compiled for.
AST->Target.reset(TargetInfo::CreateTargetInfo(TargetTriple));
- AST->PP.reset(new Preprocessor(Diags, LangInfo, *AST->Target.get(),
- SourceMgr, HeaderInfo));
+ AST->PP.reset(new Preprocessor(AST->Diags, LangInfo, *AST->Target.get(),
+ AST->getSourceManager(), HeaderInfo));
Preprocessor &PP = *AST->PP.get();
PP.setPredefines(Predefines);
@@ -141,7 +133,7 @@
// Create and initialize the ASTContext.
AST->Ctx.reset(new ASTContext(LangInfo,
- SourceMgr,
+ AST->getSourceManager(),
*AST->Target.get(),
PP.getIdentifierTable(),
PP.getSelectorTable(),
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=82430&r1=82429&r2=82430&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Sun Sep 20 22:03:39 2009
@@ -206,7 +206,8 @@
std::string astName(ast_filename);
std::string ErrMsg;
- return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getFileManager(), &ErrMsg);
+ return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getDiagnostics(),
+ CXXIdx->getFileManager(), &ErrMsg);
}
void clang_disposeTranslationUnit(
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=82430&r1=82429&r2=82430&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Sun Sep 20 22:03:39 2009
@@ -2161,7 +2161,7 @@
// FIXME: This is manufactoring its own diags and source manager, we should
// reuse ours.
std::string Error;
- llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, FileMgr,
+ llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, Diags, FileMgr,
&Error));
if (!AST) {
Diags.Report(FullSourceLoc(), diag::err_fe_invalid_ast_file) << Error;
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=82430&r1=82429&r2=82430&view=diff
==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Sun Sep 20 22:03:39 2009
@@ -225,8 +225,8 @@
std::string ErrMsg;
llvm::OwningPtr<ASTUnit> AST;
- AST.reset(ASTUnit::LoadFromPCHFile(InFile, Idxer.getFileManager(),
- &ErrMsg));
+ AST.reset(ASTUnit::LoadFromPCHFile(InFile, Idxer.getDiagnostics(),
+ Idxer.getFileManager(), &ErrMsg));
if (!AST) {
llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n';
return 1;
Modified: cfe/trunk/tools/wpa/clang-wpa.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/wpa/clang-wpa.cpp?rev=82430&r1=82429&r2=82430&view=diff
==============================================================================
--- cfe/trunk/tools/wpa/clang-wpa.cpp (original)
+++ cfe/trunk/tools/wpa/clang-wpa.cpp Sun Sep 20 22:03:39 2009
@@ -15,6 +15,8 @@
#include "clang/Analysis/CallGraph.h"
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
@@ -31,13 +33,16 @@
if (InputFilenames.empty())
return 0;
+ TextDiagnosticBuffer DiagClient;
+ Diagnostic Diags(&DiagClient);
+
for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
const std::string &InFile = InputFilenames[i];
std::string ErrMsg;
llvm::OwningPtr<ASTUnit> AST;
- AST.reset(ASTUnit::LoadFromPCHFile(InFile, FileMgr, &ErrMsg));
+ AST.reset(ASTUnit::LoadFromPCHFile(InFile, Diags, FileMgr, &ErrMsg));
if (!AST) {
llvm::errs() << "[" << InFile << "] error: " << ErrMsg << '\n';
More information about the cfe-commits
mailing list