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