Ted Kremenek | 0ec2cca | 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" |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/CompilerInstance.h" |
| 20 | #include "clang/Frontend/ASTUnit.h" |
| 21 | #include "llvm/System/Path.h" |
| 22 | |
| 23 | using namespace clang; |
| 24 | |
| 25 | /// IgnoreDiagnosticsClient - A DiagnosticsClient that just ignores emitted |
| 26 | /// warnings and errors. |
| 27 | class IgnoreDiagnosticsClient : public DiagnosticClient { |
| 28 | public: |
| 29 | virtual ~IgnoreDiagnosticsClient() {} |
| 30 | virtual void HandleDiagnostic(Diagnostic::Level, const DiagnosticInfo &) {} |
| 31 | }; |
| 32 | |
Douglas Gregor | 8775249 | 2010-01-22 20:35:53 +0000 | [diff] [blame^] | 33 | class CIndexer { |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 34 | DiagnosticOptions DiagOpts; |
| 35 | IgnoreDiagnosticsClient IgnoreDiagClient; |
| 36 | llvm::OwningPtr<Diagnostic> TextDiags; |
| 37 | Diagnostic IgnoreDiags; |
| 38 | bool UseExternalASTGeneration; |
| 39 | bool OnlyLocalDecls; |
| 40 | bool DisplayDiagnostics; |
| 41 | |
| 42 | llvm::sys::Path ClangPath; |
| 43 | |
| 44 | public: |
Douglas Gregor | 8775249 | 2010-01-22 20:35:53 +0000 | [diff] [blame^] | 45 | CIndexer() : IgnoreDiags(&IgnoreDiagClient), UseExternalASTGeneration(false), |
| 46 | OnlyLocalDecls(false), DisplayDiagnostics(false) |
| 47 | { |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 48 | TextDiags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0)); |
| 49 | } |
| 50 | |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 51 | /// \brief Whether we only want to see "local" declarations (that did not |
| 52 | /// come from a previous precompiled header). If false, we want to see all |
| 53 | /// declarations. |
| 54 | bool getOnlyLocalDecls() const { return OnlyLocalDecls; } |
| 55 | void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; } |
| 56 | |
| 57 | bool getDisplayDiagnostics() const { return DisplayDiagnostics; } |
| 58 | void setDisplayDiagnostics(bool Display = true) { |
| 59 | DisplayDiagnostics = Display; |
| 60 | } |
| 61 | |
| 62 | bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; } |
| 63 | void setUseExternalASTGeneration(bool Value) { |
| 64 | UseExternalASTGeneration = Value; |
| 65 | } |
| 66 | |
| 67 | Diagnostic &getDiags() { |
| 68 | return DisplayDiagnostics ? *TextDiags : IgnoreDiags; |
| 69 | } |
| 70 | |
| 71 | /// \brief Get the path of the clang binary. |
| 72 | const llvm::sys::Path& getClangPath(); |
| 73 | |
| 74 | /// \brief Get the path of the clang resource files. |
| 75 | std::string getClangResourcesPath(); |
Ted Kremenek | 4615797 | 2010-01-12 00:36:38 +0000 | [diff] [blame] | 76 | |
| 77 | static CXString createCXString(const char *String, bool DupString = false); |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | #endif |