1*67e74705SXin Li //===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===// 2*67e74705SXin Li // 3*67e74705SXin Li // The LLVM Compiler Infrastructure 4*67e74705SXin Li // 5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source 6*67e74705SXin Li // License. See LICENSE.TXT for details. 7*67e74705SXin Li // 8*67e74705SXin Li //===----------------------------------------------------------------------===// 9*67e74705SXin Li // 10*67e74705SXin Li // This file defines CIndexer, a subclass of Indexer that provides extra 11*67e74705SXin Li // functionality needed by the CIndex library. 12*67e74705SXin Li // 13*67e74705SXin Li //===----------------------------------------------------------------------===// 14*67e74705SXin Li 15*67e74705SXin Li #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H 16*67e74705SXin Li #define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H 17*67e74705SXin Li 18*67e74705SXin Li #include "clang-c/Index.h" 19*67e74705SXin Li #include "clang/Frontend/PCHContainerOperations.h" 20*67e74705SXin Li #include "clang/Lex/ModuleLoader.h" 21*67e74705SXin Li #include "llvm/ADT/StringRef.h" 22*67e74705SXin Li #include "llvm/Support/Path.h" 23*67e74705SXin Li #include <utility> 24*67e74705SXin Li #include <vector> 25*67e74705SXin Li 26*67e74705SXin Li namespace llvm { 27*67e74705SXin Li class CrashRecoveryContext; 28*67e74705SXin Li } 29*67e74705SXin Li 30*67e74705SXin Li namespace clang { 31*67e74705SXin Li class ASTUnit; 32*67e74705SXin Li class MacroInfo; 33*67e74705SXin Li class MacroDefinitionRecord; 34*67e74705SXin Li class SourceLocation; 35*67e74705SXin Li class Token; 36*67e74705SXin Li class IdentifierInfo; 37*67e74705SXin Li 38*67e74705SXin Li class CIndexer { 39*67e74705SXin Li bool OnlyLocalDecls; 40*67e74705SXin Li bool DisplayDiagnostics; 41*67e74705SXin Li unsigned Options; // CXGlobalOptFlags. 42*67e74705SXin Li 43*67e74705SXin Li std::string ResourcesPath; 44*67e74705SXin Li std::shared_ptr<PCHContainerOperations> PCHContainerOps; 45*67e74705SXin Li 46*67e74705SXin Li public: 47*67e74705SXin Li CIndexer(std::shared_ptr<PCHContainerOperations> PCHContainerOps = 48*67e74705SXin Li std::make_shared<PCHContainerOperations>()) OnlyLocalDecls(false)49*67e74705SXin Li : OnlyLocalDecls(false), DisplayDiagnostics(false), 50*67e74705SXin Li Options(CXGlobalOpt_None), PCHContainerOps(std::move(PCHContainerOps)) { 51*67e74705SXin Li } 52*67e74705SXin Li 53*67e74705SXin Li /// \brief Whether we only want to see "local" declarations (that did not 54*67e74705SXin Li /// come from a previous precompiled header). If false, we want to see all 55*67e74705SXin Li /// declarations. getOnlyLocalDecls()56*67e74705SXin Li bool getOnlyLocalDecls() const { return OnlyLocalDecls; } 57*67e74705SXin Li void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; } 58*67e74705SXin Li getDisplayDiagnostics()59*67e74705SXin Li bool getDisplayDiagnostics() const { return DisplayDiagnostics; } 60*67e74705SXin Li void setDisplayDiagnostics(bool Display = true) { 61*67e74705SXin Li DisplayDiagnostics = Display; 62*67e74705SXin Li } 63*67e74705SXin Li getPCHContainerOperations()64*67e74705SXin Li std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const { 65*67e74705SXin Li return PCHContainerOps; 66*67e74705SXin Li } 67*67e74705SXin Li getCXGlobalOptFlags()68*67e74705SXin Li unsigned getCXGlobalOptFlags() const { return Options; } setCXGlobalOptFlags(unsigned options)69*67e74705SXin Li void setCXGlobalOptFlags(unsigned options) { Options = options; } 70*67e74705SXin Li isOptEnabled(CXGlobalOptFlags opt)71*67e74705SXin Li bool isOptEnabled(CXGlobalOptFlags opt) const { 72*67e74705SXin Li return Options & opt; 73*67e74705SXin Li } 74*67e74705SXin Li 75*67e74705SXin Li /// \brief Get the path of the clang resource files. 76*67e74705SXin Li const std::string &getClangResourcesPath(); 77*67e74705SXin Li }; 78*67e74705SXin Li 79*67e74705SXin Li /// \brief Return the current size to request for "safety". 80*67e74705SXin Li unsigned GetSafetyThreadStackSize(); 81*67e74705SXin Li 82*67e74705SXin Li /// \brief Set the current size to request for "safety" (or 0, if safety 83*67e74705SXin Li /// threads should not be used). 84*67e74705SXin Li void SetSafetyThreadStackSize(unsigned Value); 85*67e74705SXin Li 86*67e74705SXin Li /// \brief Execution the given code "safely", using crash recovery or safety 87*67e74705SXin Li /// threads when possible. 88*67e74705SXin Li /// 89*67e74705SXin Li /// \return False if a crash was detected. 90*67e74705SXin Li bool RunSafely(llvm::CrashRecoveryContext &CRC, llvm::function_ref<void()> Fn, 91*67e74705SXin Li unsigned Size = 0); 92*67e74705SXin Li 93*67e74705SXin Li /// \brief Set the thread priority to background. 94*67e74705SXin Li /// FIXME: Move to llvm/Support. 95*67e74705SXin Li void setThreadBackgroundPriority(); 96*67e74705SXin Li 97*67e74705SXin Li /// \brief Print libclang's resource usage to standard error. 98*67e74705SXin Li void PrintLibclangResourceUsage(CXTranslationUnit TU); 99*67e74705SXin Li 100*67e74705SXin Li namespace cxindex { 101*67e74705SXin Li void printDiagsToStderr(ASTUnit *Unit); 102*67e74705SXin Li 103*67e74705SXin Li /// \brief If \c MacroDefLoc points at a macro definition with \c II as 104*67e74705SXin Li /// its name, this retrieves its MacroInfo. 105*67e74705SXin Li MacroInfo *getMacroInfo(const IdentifierInfo &II, 106*67e74705SXin Li SourceLocation MacroDefLoc, CXTranslationUnit TU); 107*67e74705SXin Li 108*67e74705SXin Li /// \brief Retrieves the corresponding MacroInfo of a MacroDefinitionRecord. 109*67e74705SXin Li const MacroInfo *getMacroInfo(const MacroDefinitionRecord *MacroDef, 110*67e74705SXin Li CXTranslationUnit TU); 111*67e74705SXin Li 112*67e74705SXin Li /// \brief If \c Loc resides inside the definition of \c MI and it points at 113*67e74705SXin Li /// an identifier that has ever been a macro name, this returns the latest 114*67e74705SXin Li /// MacroDefinitionRecord for that name, otherwise it returns NULL. 115*67e74705SXin Li MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI, 116*67e74705SXin Li SourceLocation Loc, 117*67e74705SXin Li CXTranslationUnit TU); 118*67e74705SXin Li 119*67e74705SXin Li /// \brief If \c Tok resides inside the definition of \c MI and it points at 120*67e74705SXin Li /// an identifier that has ever been a macro name, this returns the latest 121*67e74705SXin Li /// MacroDefinitionRecord for that name, otherwise it returns NULL. 122*67e74705SXin Li MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI, 123*67e74705SXin Li const Token &Tok, 124*67e74705SXin Li CXTranslationUnit TU); 125*67e74705SXin Li } 126*67e74705SXin Li } 127*67e74705SXin Li 128*67e74705SXin Li #endif 129