CIndexer.h revision 7aa7eb9d0221bc67e2cd564e703a2427dc212b79
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 23namespace llvm { 24 class CrashRecoveryContext; 25} 26 27namespace clang { 28 class ASTUnit; 29 30class CIndexer { 31 bool OnlyLocalDecls; 32 bool DisplayDiagnostics; 33 unsigned Options; // CXGlobalOptFlags. 34 35 llvm::sys::Path ResourcesPath; 36 37public: 38 CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false), 39 Options(CXGlobalOpt_None) { } 40 41 /// \brief Whether we only want to see "local" declarations (that did not 42 /// come from a previous precompiled header). If false, we want to see all 43 /// declarations. 44 bool getOnlyLocalDecls() const { return OnlyLocalDecls; } 45 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; } 46 47 bool getDisplayDiagnostics() const { return DisplayDiagnostics; } 48 void setDisplayDiagnostics(bool Display = true) { 49 DisplayDiagnostics = Display; 50 } 51 52 unsigned getCXGlobalOptFlags() const { return Options; } 53 void setCXGlobalOptFlags(unsigned options) { Options = options; } 54 55 bool isOptEnabled(CXGlobalOptFlags opt) const { 56 return Options & opt; 57 } 58 59 /// \brief Get the path of the clang resource files. 60 std::string getClangResourcesPath(); 61}; 62 63 /** 64 * \brief Given a set of "unsaved" files, create temporary files and 65 * construct the clang -cc1 argument list needed to perform the remapping. 66 * 67 * \returns true if an error occurred. 68 */ 69 bool RemapFiles(unsigned num_unsaved_files, 70 struct CXUnsavedFile *unsaved_files, 71 std::vector<std::string> &RemapArgs, 72 std::vector<llvm::sys::Path> &TemporaryFiles); 73 74 /// \brief Return the current size to request for "safety". 75 unsigned GetSafetyThreadStackSize(); 76 77 /// \brief Set the current size to request for "safety" (or 0, if safety 78 /// threads should not be used). 79 void SetSafetyThreadStackSize(unsigned Value); 80 81 /// \brief Execution the given code "safely", using crash recovery or safety 82 /// threads when possible. 83 /// 84 /// \return False if a crash was detected. 85 bool RunSafely(llvm::CrashRecoveryContext &CRC, 86 void (*Fn)(void*), void *UserData, unsigned Size = 0); 87 88 /// \brief Set the thread priority to background. 89 /// FIXME: Move to llvm/Support. 90 void setThreadBackgroundPriority(); 91 92 /// \brief Print libclang's resource usage to standard error. 93 void PrintLibclangResourceUsage(CXTranslationUnit TU); 94 95 namespace cxindex { 96 void printDiagsToStderr(ASTUnit *Unit); 97 } 98} 99 100#endif 101