CIndexer.h revision 34392373fe25e943586de0fdbe37b806c3f7ff70
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 "llvm/Support/PathV1.h" 22#include <vector> 23 24namespace llvm { 25 class CrashRecoveryContext; 26} 27 28namespace clang { 29 class ASTUnit; 30 class MacroInfo; 31 class MacroDefinition; 32 class SourceLocation; 33 class Token; 34 class IdentifierInfo; 35 36class CIndexer { 37 bool OnlyLocalDecls; 38 bool DisplayDiagnostics; 39 unsigned Options; // CXGlobalOptFlags. 40 41 llvm::sys::Path ResourcesPath; 42 43public: 44 CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false), 45 Options(CXGlobalOpt_None) { } 46 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 53 bool getDisplayDiagnostics() const { return DisplayDiagnostics; } 54 void setDisplayDiagnostics(bool Display = true) { 55 DisplayDiagnostics = Display; 56 } 57 58 unsigned getCXGlobalOptFlags() const { return Options; } 59 void setCXGlobalOptFlags(unsigned options) { Options = options; } 60 61 bool isOptEnabled(CXGlobalOptFlags opt) const { 62 return Options & opt; 63 } 64 65 /// \brief Get the path of the clang resource files. 66 std::string getClangResourcesPath(); 67}; 68 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); 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, 92 void (*Fn)(void*), void *UserData, unsigned Size = 0); 93 94 /// \brief Set the thread priority to background. 95 /// FIXME: Move to llvm/Support. 96 void setThreadBackgroundPriority(); 97 98 /// \brief Print libclang's resource usage to standard error. 99 void PrintLibclangResourceUsage(CXTranslationUnit TU); 100 101 namespace cxindex { 102 void printDiagsToStderr(ASTUnit *Unit); 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. 111 const MacroInfo *getMacroInfo(const MacroDefinition *MacroDef, 112 CXTranslationUnit TU); 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); 127 } 128} 129 130#endif 131