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