diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-12-03 01:45:44 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-12-03 01:45:44 +0000 |
commit | 5262fda30b876c8aae95f2eb92e349418d6b14bb (patch) | |
tree | 258af401a1fdf30edb4079efece5a40e0ed3551d /tools | |
parent | 7d9bd4257f817494b2fa5b310df05807050a9c18 (diff) |
Fix ASTUnit to allows require a (persistent) Diagnostic object be provided; propogate and simplify.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CIndex/CIndex.cpp | 44 | ||||
-rw-r--r-- | tools/index-test/index-test.cpp | 17 |
2 files changed, 28 insertions, 33 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 87d7856203..a5b7e99622 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -23,6 +23,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/ASTUnit.h" +#include "clang/Frontend/CompilerInstance.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" #include "llvm/Support/Compiler.h" @@ -291,10 +292,24 @@ public: }; class CIndexer : public Indexer { + IgnoreDiagnosticsClient IgnoreDiagClient; + llvm::OwningPtr<Diagnostic> TextDiags; + Diagnostic IgnoreDiags; + bool UseExternalASTGeneration; + bool OnlyLocalDecls; + bool DisplayDiagnostics; + + llvm::sys::Path ClangPath; + public: explicit CIndexer(Program *prog) : Indexer(*prog), + IgnoreDiags(&IgnoreDiagClient), + UseExternalASTGeneration(false), OnlyLocalDecls(false), - DisplayDiagnostics(false) {} + DisplayDiagnostics(false) { + TextDiags.reset( + CompilerInstance::createDiagnostics(DiagnosticOptions(), 0, 0)); + } virtual ~CIndexer() { delete &getProgram(); } @@ -304,18 +319,17 @@ public: bool getOnlyLocalDecls() const { return OnlyLocalDecls; } void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; } + bool getDisplayDiagnostics() const { return DisplayDiagnostics; } void setDisplayDiagnostics(bool Display = true) { DisplayDiagnostics = Display; } - bool getDisplayDiagnostics() const { return DisplayDiagnostics; } + + Diagnostic &getDiags() { + return DisplayDiagnostics ? *TextDiags : IgnoreDiags; + } /// \brief Get the path of the clang binary. const llvm::sys::Path& getClangPath(); -private: - bool OnlyLocalDecls; - bool DisplayDiagnostics; - - llvm::sys::Path ClangPath; }; const llvm::sys::Path& CIndexer::getClangPath() { @@ -457,20 +471,10 @@ CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, const char *ast_filename) { assert(CIdx && "Passed null CXIndex"); CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx); - std::string astName(ast_filename); - std::string ErrMsg; - - CXTranslationUnit TU = - ASTUnit::LoadFromPCHFile(astName, &ErrMsg, - CXXIdx->getDisplayDiagnostics() ? - NULL : new IgnoreDiagnosticsClient(), - CXXIdx->getOnlyLocalDecls(), - /* UseBumpAllocator = */ true); - - if (CXXIdx->getDisplayDiagnostics() && !ErrMsg.empty()) - llvm::errs() << "clang_createTranslationUnit: " << ErrMsg << '\n'; - return TU; + return ASTUnit::LoadFromPCHFile(ast_filename, CXXIdx->getDiags(), + CXXIdx->getOnlyLocalDecls(), + /* UseBumpAllocator = */ true); } CXTranslationUnit diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp index fc8547b784..d13b2d4926 100644 --- a/tools/index-test/index-test.cpp +++ b/tools/index-test/index-test.cpp @@ -238,7 +238,6 @@ int main(int argc, char **argv) { Indexer Idxer(Prog); llvm::SmallVector<TUnit*, 4> TUnits; - TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions(), false); llvm::OwningPtr<Diagnostic> Diags( CompilerInstance::createDiagnostics(DiagnosticOptions(), argc, argv)); @@ -248,21 +247,13 @@ int main(int argc, char **argv) { for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { const std::string &InFile = InputFilenames[i]; - - std::string ErrMsg; llvm::OwningPtr<ASTUnit> AST; - - if (ASTFromSource) { + if (ASTFromSource) AST.reset(CreateFromSource(InFile, *Diags, argv[0])); - if (!AST || Diags->getNumErrors()) - ErrMsg = "unable to create AST"; - } else - AST.reset(ASTUnit::LoadFromPCHFile(InFile, &ErrMsg)); - - if (!AST) { - llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n'; + else + AST.reset(ASTUnit::LoadFromPCHFile(InFile, *Diags)); + if (!AST) return 1; - } TUnit *TU = new TUnit(AST.take(), InFile); TUnits.push_back(TU); |