Daniel Dunbar | b7383e6 | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 1 | //===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===// |
Ted Kremenek | 0ec2cca | 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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 15 | #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H |
| 16 | #define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 17 | |
| 18 | #include "clang-c/Index.h" |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame^] | 19 | #include "clang/Frontend/PCHContainerOperations.h" |
| 20 | #include "clang/Lex/ModuleLoader.h" |
Douglas Gregor | 27b4fa9 | 2010-01-26 17:06:03 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringRef.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Path.h" |
Douglas Gregor | aa98ed9 | 2010-01-23 00:14:00 +0000 | [diff] [blame] | 23 | #include <vector> |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | b7383e6 | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 25 | namespace llvm { |
| 26 | class CrashRecoveryContext; |
| 27 | } |
| 28 | |
Argyrios Kyrtzidis | c557bad | 2012-03-28 02:18:02 +0000 | [diff] [blame] | 29 | namespace clang { |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 30 | class ASTUnit; |
| 31 | class MacroInfo; |
| 32 | class MacroDefinitionRecord; |
| 33 | class SourceLocation; |
| 34 | class Token; |
| 35 | class IdentifierInfo; |
Argyrios Kyrtzidis | c557bad | 2012-03-28 02:18:02 +0000 | [diff] [blame] | 36 | |
Douglas Gregor | 8775249 | 2010-01-22 20:35:53 +0000 | [diff] [blame] | 37 | class CIndexer { |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 38 | bool OnlyLocalDecls; |
Douglas Gregor | 1e21cc7 | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 39 | bool DisplayDiagnostics; |
Argyrios Kyrtzidis | 7317a5c | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 40 | unsigned Options; // CXGlobalOptFlags. |
Douglas Gregor | 1e21cc7 | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 41 | |
Benjamin Kramer | e3868e4 | 2013-06-13 13:56:37 +0000 | [diff] [blame] | 42 | std::string ResourcesPath; |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame^] | 43 | std::shared_ptr<PCHContainerOperations> PCHContainerOps; |
Argyrios Kyrtzidis | 71731d6 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 44 | |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 45 | public: |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame^] | 46 | CIndexer(std::shared_ptr<PCHContainerOperations> PCHContainerOps = |
| 47 | std::make_shared<RawPCHContainerOperations>()) |
| 48 | : OnlyLocalDecls(false), DisplayDiagnostics(false), |
| 49 | Options(CXGlobalOpt_None), PCHContainerOps(PCHContainerOps) {} |
| 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 | |
Douglas Gregor | 1e21cc7 | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 57 | bool getDisplayDiagnostics() const { return DisplayDiagnostics; } |
| 58 | void setDisplayDiagnostics(bool Display = true) { |
| 59 | DisplayDiagnostics = Display; |
| 60 | } |
| 61 | |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame^] | 62 | std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const { |
| 63 | return PCHContainerOps; |
| 64 | } |
| 65 | |
Argyrios Kyrtzidis | 7317a5c | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 66 | unsigned getCXGlobalOptFlags() const { return Options; } |
| 67 | void setCXGlobalOptFlags(unsigned options) { Options = options; } |
| 68 | |
| 69 | bool isOptEnabled(CXGlobalOptFlags opt) const { |
Argyrios Kyrtzidis | e26ba14 | 2012-03-28 20:42:59 +0000 | [diff] [blame] | 70 | return Options & opt; |
Argyrios Kyrtzidis | 7317a5c | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 73 | /// \brief Get the path of the clang resource files. |
Benjamin Kramer | e3868e4 | 2013-06-13 13:56:37 +0000 | [diff] [blame] | 74 | const std::string &getClangResourcesPath(); |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Daniel Dunbar | b7383e6 | 2010-11-05 07:19:31 +0000 | [diff] [blame] | 77 | /// \brief Return the current size to request for "safety". |
| 78 | unsigned GetSafetyThreadStackSize(); |
| 79 | |
| 80 | /// \brief Set the current size to request for "safety" (or 0, if safety |
| 81 | /// threads should not be used). |
| 82 | void SetSafetyThreadStackSize(unsigned Value); |
| 83 | |
| 84 | /// \brief Execution the given code "safely", using crash recovery or safety |
| 85 | /// threads when possible. |
| 86 | /// |
| 87 | /// \return False if a crash was detected. |
| 88 | bool RunSafely(llvm::CrashRecoveryContext &CRC, |
Ted Kremenek | ca817a3c | 2010-11-14 17:47:35 +0000 | [diff] [blame] | 89 | void (*Fn)(void*), void *UserData, unsigned Size = 0); |
Douglas Gregor | af44c78 | 2011-05-05 20:27:22 +0000 | [diff] [blame] | 90 | |
Argyrios Kyrtzidis | 7317a5c | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 91 | /// \brief Set the thread priority to background. |
| 92 | /// FIXME: Move to llvm/Support. |
Argyrios Kyrtzidis | 58d5f3f | 2012-03-28 02:49:54 +0000 | [diff] [blame] | 93 | void setThreadBackgroundPriority(); |
Argyrios Kyrtzidis | 7317a5c | 2012-03-28 02:18:05 +0000 | [diff] [blame] | 94 | |
Douglas Gregor | af44c78 | 2011-05-05 20:27:22 +0000 | [diff] [blame] | 95 | /// \brief Print libclang's resource usage to standard error. |
| 96 | void PrintLibclangResourceUsage(CXTranslationUnit TU); |
Argyrios Kyrtzidis | ac1cc93 | 2012-04-11 02:11:16 +0000 | [diff] [blame] | 97 | |
| 98 | namespace cxindex { |
| 99 | void printDiagsToStderr(ASTUnit *Unit); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 100 | |
| 101 | /// \brief If \c MacroDefLoc points at a macro definition with \c II as |
| 102 | /// its name, this retrieves its MacroInfo. |
| 103 | MacroInfo *getMacroInfo(const IdentifierInfo &II, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 104 | SourceLocation MacroDefLoc, CXTranslationUnit TU); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 105 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 106 | /// \brief Retrieves the corresponding MacroInfo of a MacroDefinitionRecord. |
| 107 | const MacroInfo *getMacroInfo(const MacroDefinitionRecord *MacroDef, |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 108 | CXTranslationUnit TU); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 109 | |
| 110 | /// \brief If \c Loc resides inside the definition of \c MI and it points at |
| 111 | /// an identifier that has ever been a macro name, this returns the latest |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 112 | /// MacroDefinitionRecord for that name, otherwise it returns NULL. |
| 113 | MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI, |
| 114 | SourceLocation Loc, |
| 115 | CXTranslationUnit TU); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 116 | |
| 117 | /// \brief If \c Tok resides inside the definition of \c MI and it points at |
| 118 | /// an identifier that has ever been a macro name, this returns the latest |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 119 | /// MacroDefinitionRecord for that name, otherwise it returns NULL. |
| 120 | MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI, |
| 121 | const Token &Tok, |
| 122 | CXTranslationUnit TU); |
| 123 | } |
| 124 | } |
Douglas Gregor | aa98ed9 | 2010-01-23 00:14:00 +0000 | [diff] [blame] | 125 | |
Ted Kremenek | 0ec2cca | 2010-01-05 19:32:54 +0000 | [diff] [blame] | 126 | #endif |