Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame^] | 1 | //===- CIndexer.h - Clang-C Source Indexing Library -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines CIndexer, a subclass of Indexer that provides extra |
| 11 | // functionality needed by the CIndex library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_CLANG_CINDEXER_H |
| 16 | #define LLVM_CLANG_CINDEXER_H |
| 17 | |
| 18 | #include "clang-c/Index.h" |
| 19 | #include "clang/Index/ASTLocation.h" |
| 20 | #include "clang/Index/Indexer.h" |
| 21 | #include "clang/Index/Program.h" |
| 22 | #include "clang/Index/Utils.h" |
| 23 | #include "clang/Frontend/CompilerInstance.h" |
| 24 | #include "clang/Frontend/ASTUnit.h" |
| 25 | #include "llvm/System/Path.h" |
| 26 | |
| 27 | using namespace clang; |
| 28 | |
| 29 | /// IgnoreDiagnosticsClient - A DiagnosticsClient that just ignores emitted |
| 30 | /// warnings and errors. |
| 31 | class IgnoreDiagnosticsClient : public DiagnosticClient { |
| 32 | public: |
| 33 | virtual ~IgnoreDiagnosticsClient() {} |
| 34 | virtual void HandleDiagnostic(Diagnostic::Level, const DiagnosticInfo &) {} |
| 35 | }; |
| 36 | |
| 37 | class CIndexer : public Indexer { |
| 38 | DiagnosticOptions DiagOpts; |
| 39 | IgnoreDiagnosticsClient IgnoreDiagClient; |
| 40 | llvm::OwningPtr<Diagnostic> TextDiags; |
| 41 | Diagnostic IgnoreDiags; |
| 42 | bool UseExternalASTGeneration; |
| 43 | bool OnlyLocalDecls; |
| 44 | bool DisplayDiagnostics; |
| 45 | |
| 46 | llvm::sys::Path ClangPath; |
| 47 | |
| 48 | public: |
| 49 | explicit CIndexer(Program *prog) : Indexer(*prog), |
| 50 | IgnoreDiags(&IgnoreDiagClient), |
| 51 | UseExternalASTGeneration(false), |
| 52 | OnlyLocalDecls(false), |
| 53 | DisplayDiagnostics(false) { |
| 54 | TextDiags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0)); |
| 55 | } |
| 56 | |
| 57 | virtual ~CIndexer() { delete &getProgram(); } |
| 58 | |
| 59 | /// \brief Whether we only want to see "local" declarations (that did not |
| 60 | /// come from a previous precompiled header). If false, we want to see all |
| 61 | /// declarations. |
| 62 | bool getOnlyLocalDecls() const { return OnlyLocalDecls; } |
| 63 | void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; } |
| 64 | |
| 65 | bool getDisplayDiagnostics() const { return DisplayDiagnostics; } |
| 66 | void setDisplayDiagnostics(bool Display = true) { |
| 67 | DisplayDiagnostics = Display; |
| 68 | } |
| 69 | |
| 70 | bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; } |
| 71 | void setUseExternalASTGeneration(bool Value) { |
| 72 | UseExternalASTGeneration = Value; |
| 73 | } |
| 74 | |
| 75 | Diagnostic &getDiags() { |
| 76 | return DisplayDiagnostics ? *TextDiags : IgnoreDiags; |
| 77 | } |
| 78 | |
| 79 | /// \brief Get the path of the clang binary. |
| 80 | const llvm::sys::Path& getClangPath(); |
| 81 | |
| 82 | /// \brief Get the path of the clang resource files. |
| 83 | std::string getClangResourcesPath(); |
| 84 | }; |
| 85 | |
| 86 | #endif |