CIndexer.h revision fdc1795acc9d5d73a767cc7d43ad1546e93adbba
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
29class CIndexer {
30  bool OnlyLocalDecls;
31  bool DisplayDiagnostics;
32  unsigned Options; // CXGlobalOptFlags.
33
34  llvm::sys::Path ResourcesPath;
35  std::string WorkingDir;
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 & ~unsigned(opt);
57  }
58
59  /// \brief Get the path of the clang resource files.
60  std::string getClangResourcesPath();
61
62  const std::string &getWorkingDirectory() const { return WorkingDir; }
63  void setWorkingDirectory(const std::string &Dir) { WorkingDir = Dir; }
64};
65
66  /**
67   * \brief Given a set of "unsaved" files, create temporary files and
68   * construct the clang -cc1 argument list needed to perform the remapping.
69   *
70   * \returns true if an error occurred.
71   */
72  bool RemapFiles(unsigned num_unsaved_files,
73                  struct CXUnsavedFile *unsaved_files,
74                  std::vector<std::string> &RemapArgs,
75                  std::vector<llvm::sys::Path> &TemporaryFiles);
76
77  /// \brief Return the current size to request for "safety".
78  unsigned GetSafetyThreadStackSize();
79
80  /// \brief Set the current size to request for "safety" (or 0, if safety
81  /// threads should not be used).
82  void SetSafetyThreadStackSize(unsigned Value);
83
84  /// \brief Execution the given code "safely", using crash recovery or safety
85  /// threads when possible.
86  ///
87  /// \return False if a crash was detected.
88  bool RunSafely(llvm::CrashRecoveryContext &CRC,
89                 void (*Fn)(void*), void *UserData, unsigned Size = 0);
90
91  /// \brief Set the thread priority to background.
92  /// FIXME: Move to llvm/Support.
93  void setBackGroundPriority();
94
95  /// \brief Print libclang's resource usage to standard error.
96  void PrintLibclangResourceUsage(CXTranslationUnit TU);
97}
98
99#endif
100