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" |
Rafael Espindola | 3439237 | 2013-06-11 19:59:07 +0000 | [diff] [blame] | 21 | #include "llvm/Support/PathV1.h" |
Douglas Gregor | 4db64a4 | 2010-01-23 00:14:00 +0000 | [diff] [blame] | 22 | #include <vector> |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 23 | |
Daniel Dunbar | bf44c3b | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | class CrashRecoveryContext; |
| 26 | } |
| 27 | |
Argyrios Kyrtzidis | bbca564 | 2012-03-28 02:18:02 +0000 | [diff] [blame] | 28 | namespace clang { |
Argyrios Kyrtzidis | e722ed6 | 2012-04-11 02:11:16 +0000 | [diff] [blame] | 29 | class ASTUnit; |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 30 | class MacroInfo; |
| 31 | class MacroDefinition; |
| 32 | class SourceLocation; |
| 33 | class Token; |
| 34 | class IdentifierInfo; |
Argyrios Kyrtzidis | bbca564 | 2012-03-28 02:18:02 +0000 | [diff] [blame] | 35 | |
Douglas Gregor | a030b7c | 2010-01-22 20:35:53 +0000 | [diff] [blame] | 36 | class CIndexer { |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 37 | bool OnlyLocalDecls; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 38 | bool DisplayDiagnostics; |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 39 | unsigned Options; // CXGlobalOptFlags. |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 40 | |
Benjamin Kramer | 082ad2b | 2013-06-13 13:56:37 +0000 | [diff] [blame^] | 41 | std::string ResourcesPath; |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 42 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 43 | public: |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 44 | CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false), |
| 45 | Options(CXGlobalOpt_None) { } |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 46 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 47 | /// \brief Whether we only want to see "local" declarations (that did not |
| 48 | /// come from a previous precompiled header). If false, we want to see all |
| 49 | /// declarations. |
| 50 | bool getOnlyLocalDecls() const { return OnlyLocalDecls; } |
| 51 | void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; } |
| 52 | |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 53 | bool getDisplayDiagnostics() const { return DisplayDiagnostics; } |
| 54 | void setDisplayDiagnostics(bool Display = true) { |
| 55 | DisplayDiagnostics = Display; |
| 56 | } |
| 57 | |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 58 | unsigned getCXGlobalOptFlags() const { return Options; } |
| 59 | void setCXGlobalOptFlags(unsigned options) { Options = options; } |
| 60 | |
| 61 | bool isOptEnabled(CXGlobalOptFlags opt) const { |
Argyrios Kyrtzidis | f962eb4 | 2012-03-28 20:42:59 +0000 | [diff] [blame] | 62 | return Options & opt; |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 65 | /// \brief Get the path of the clang resource files. |
Benjamin Kramer | 082ad2b | 2013-06-13 13:56:37 +0000 | [diff] [blame^] | 66 | const std::string &getClangResourcesPath(); |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
Douglas Gregor | 4db64a4 | 2010-01-23 00:14:00 +0000 | [diff] [blame] | 69 | /** |
| 70 | * \brief Given a set of "unsaved" files, create temporary files and |
| 71 | * construct the clang -cc1 argument list needed to perform the remapping. |
| 72 | * |
| 73 | * \returns true if an error occurred. |
| 74 | */ |
| 75 | bool RemapFiles(unsigned num_unsaved_files, |
| 76 | struct CXUnsavedFile *unsaved_files, |
| 77 | std::vector<std::string> &RemapArgs, |
| 78 | std::vector<llvm::sys::Path> &TemporaryFiles); |
Daniel Dunbar | bf44c3b | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 79 | |
| 80 | /// \brief Return the current size to request for "safety". |
| 81 | unsigned GetSafetyThreadStackSize(); |
| 82 | |
| 83 | /// \brief Set the current size to request for "safety" (or 0, if safety |
| 84 | /// threads should not be used). |
| 85 | void SetSafetyThreadStackSize(unsigned Value); |
| 86 | |
| 87 | /// \brief Execution the given code "safely", using crash recovery or safety |
| 88 | /// threads when possible. |
| 89 | /// |
| 90 | /// \return False if a crash was detected. |
| 91 | bool RunSafely(llvm::CrashRecoveryContext &CRC, |
Ted Kremenek | 6c53fdd | 2010-11-14 17:47:35 +0000 | [diff] [blame] | 92 | void (*Fn)(void*), void *UserData, unsigned Size = 0); |
Douglas Gregor | 6df7873 | 2011-05-05 20:27:22 +0000 | [diff] [blame] | 93 | |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 94 | /// \brief Set the thread priority to background. |
| 95 | /// FIXME: Move to llvm/Support. |
Argyrios Kyrtzidis | 81b5ac3 | 2012-03-28 02:49:54 +0000 | [diff] [blame] | 96 | void setThreadBackgroundPriority(); |
Argyrios Kyrtzidis | fdc1795 | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 97 | |
Douglas Gregor | 6df7873 | 2011-05-05 20:27:22 +0000 | [diff] [blame] | 98 | /// \brief Print libclang's resource usage to standard error. |
| 99 | void PrintLibclangResourceUsage(CXTranslationUnit TU); |
Argyrios Kyrtzidis | e722ed6 | 2012-04-11 02:11:16 +0000 | [diff] [blame] | 100 | |
| 101 | namespace cxindex { |
| 102 | void printDiagsToStderr(ASTUnit *Unit); |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 103 | |
| 104 | /// \brief If \c MacroDefLoc points at a macro definition with \c II as |
| 105 | /// its name, this retrieves its MacroInfo. |
| 106 | MacroInfo *getMacroInfo(const IdentifierInfo &II, |
| 107 | SourceLocation MacroDefLoc, |
| 108 | CXTranslationUnit TU); |
| 109 | |
| 110 | /// \brief Retrieves the corresponding MacroInfo of a MacroDefinition. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 111 | const MacroInfo *getMacroInfo(const MacroDefinition *MacroDef, |
| 112 | CXTranslationUnit TU); |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 113 | |
| 114 | /// \brief If \c Loc resides inside the definition of \c MI and it points at |
| 115 | /// an identifier that has ever been a macro name, this returns the latest |
| 116 | /// MacroDefinition for that name, otherwise it returns NULL. |
| 117 | MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI, |
| 118 | SourceLocation Loc, |
| 119 | CXTranslationUnit TU); |
| 120 | |
| 121 | /// \brief If \c Tok resides inside the definition of \c MI and it points at |
| 122 | /// an identifier that has ever been a macro name, this returns the latest |
| 123 | /// MacroDefinition for that name, otherwise it returns NULL. |
| 124 | MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI, |
| 125 | const Token &Tok, |
| 126 | CXTranslationUnit TU); |
Argyrios Kyrtzidis | e722ed6 | 2012-04-11 02:11:16 +0000 | [diff] [blame] | 127 | } |
Douglas Gregor | 4db64a4 | 2010-01-23 00:14:00 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Ted Kremenek | ab18893 | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 130 | #endif |