Daniel Dunbar | bf44c3b | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 1 | //===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===// |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 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" |
Douglas Gregor | fc8ea23 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringRef.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Path.h" |
Douglas Gregor | 4db64a4 | 2010-01-23 00:14:00 +0000 | [diff] [blame] | 21 | #include <vector> |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | bf44c3b | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 23 | namespace llvm { |
| 24 | class CrashRecoveryContext; |
| 25 | } |
| 26 | |
Argyrios Kyrtzidis | bbca564 | 2012-03-28 02:18:02 +0000 | [diff] [blame] | 27 | namespace clang { |
Argyrios Kyrtzidis | e722ed6 | 2012-04-11 02:11:16 +0000 | [diff] [blame] | 28 | class ASTUnit; |
Argyrios Kyrtzidis | bbca564 | 2012-03-28 02:18:02 +0000 | [diff] [blame] | 29 | |
Douglas Gregor | a030b7c | 2010-01-22 20:35:53 +0000 | [diff] [blame] | 30 | class CIndexer { |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 31 | bool OnlyLocalDecls; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 32 | bool DisplayDiagnostics; |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 33 | unsigned Options; // CXGlobalOptFlags. |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | d1e6fdb | 2010-10-11 23:17:59 +0000 | [diff] [blame] | 35 | llvm::sys::Path ResourcesPath; |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 36 | std::string WorkingDir; |
| 37 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 38 | public: |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 39 | CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false), |
| 40 | Options(CXGlobalOpt_None) { } |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 41 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 42 | /// \brief Whether we only want to see "local" declarations (that did not |
| 43 | /// come from a previous precompiled header). If false, we want to see all |
| 44 | /// declarations. |
| 45 | bool getOnlyLocalDecls() const { return OnlyLocalDecls; } |
| 46 | void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; } |
| 47 | |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 48 | bool getDisplayDiagnostics() const { return DisplayDiagnostics; } |
| 49 | void setDisplayDiagnostics(bool Display = true) { |
| 50 | DisplayDiagnostics = Display; |
| 51 | } |
| 52 | |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 53 | unsigned getCXGlobalOptFlags() const { return Options; } |
| 54 | void setCXGlobalOptFlags(unsigned options) { Options = options; } |
| 55 | |
| 56 | bool isOptEnabled(CXGlobalOptFlags opt) const { |
Argyrios Kyrtzidis | f962eb4 | 2012-03-28 20:42:59 +0000 | [diff] [blame] | 57 | return Options & opt; |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 60 | /// \brief Get the path of the clang resource files. |
| 61 | std::string getClangResourcesPath(); |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 62 | |
| 63 | const std::string &getWorkingDirectory() const { return WorkingDir; } |
| 64 | void setWorkingDirectory(const std::string &Dir) { WorkingDir = Dir; } |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Douglas Gregor | 4db64a4 | 2010-01-23 00:14:00 +0000 | [diff] [blame] | 67 | /** |
| 68 | * \brief Given a set of "unsaved" files, create temporary files and |
| 69 | * construct the clang -cc1 argument list needed to perform the remapping. |
| 70 | * |
| 71 | * \returns true if an error occurred. |
| 72 | */ |
| 73 | bool RemapFiles(unsigned num_unsaved_files, |
| 74 | struct CXUnsavedFile *unsaved_files, |
| 75 | std::vector<std::string> &RemapArgs, |
| 76 | std::vector<llvm::sys::Path> &TemporaryFiles); |
Daniel Dunbar | bf44c3b | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 77 | |
| 78 | /// \brief Return the current size to request for "safety". |
| 79 | unsigned GetSafetyThreadStackSize(); |
| 80 | |
| 81 | /// \brief Set the current size to request for "safety" (or 0, if safety |
| 82 | /// threads should not be used). |
| 83 | void SetSafetyThreadStackSize(unsigned Value); |
| 84 | |
| 85 | /// \brief Execution the given code "safely", using crash recovery or safety |
| 86 | /// threads when possible. |
| 87 | /// |
| 88 | /// \return False if a crash was detected. |
| 89 | bool RunSafely(llvm::CrashRecoveryContext &CRC, |
Ted Kremenek | 6c53fdd | 2010-11-14 17:47:35 +0000 | [diff] [blame] | 90 | void (*Fn)(void*), void *UserData, unsigned Size = 0); |
Douglas Gregor | 6df7873 | 2011-05-05 20:27:22 +0000 | [diff] [blame] | 91 | |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 92 | /// \brief Set the thread priority to background. |
| 93 | /// FIXME: Move to llvm/Support. |
Argyrios Kyrtzidis | 81b5ac3 | 2012-03-28 02:49:54 +0000 | [diff] [blame] | 94 | void setThreadBackgroundPriority(); |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 95 | |
Douglas Gregor | 6df7873 | 2011-05-05 20:27:22 +0000 | [diff] [blame] | 96 | /// \brief Print libclang's resource usage to standard error. |
| 97 | void PrintLibclangResourceUsage(CXTranslationUnit TU); |
Argyrios Kyrtzidis | e722ed6 | 2012-04-11 02:11:16 +0000 | [diff] [blame] | 98 | |
| 99 | namespace cxindex { |
| 100 | void printDiagsToStderr(ASTUnit *Unit); |
| 101 | } |
Douglas Gregor | 4db64a4 | 2010-01-23 00:14:00 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 104 | #endif |