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