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