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