blob: c8c48e9787ee89e6ebd22d87e0bc52c922d4b2db [file] [log] [blame]
Daniel Dunbarbf44c3b2010-11-05 07:19:31 +00001//===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===//
Ted Kremenekab188932010-01-05 19:32:54 +00002//
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"
Douglas Gregorfc8ea232010-01-26 17:06:03 +000019#include "llvm/ADT/StringRef.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000020#include "llvm/Support/Path.h"
Douglas Gregor4db64a42010-01-23 00:14:00 +000021#include <vector>
Ted Kremenekab188932010-01-05 19:32:54 +000022
Daniel Dunbarbf44c3b2010-11-05 07:19:31 +000023namespace llvm {
24 class CrashRecoveryContext;
25}
26
Argyrios Kyrtzidisbbca5642012-03-28 02:18:02 +000027namespace clang {
28
Douglas Gregora030b7c2010-01-22 20:35:53 +000029class CIndexer {
Ted Kremenekab188932010-01-05 19:32:54 +000030 bool OnlyLocalDecls;
Douglas Gregor0a812cf2010-02-18 23:07:20 +000031 bool DisplayDiagnostics;
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000032 unsigned Options; // CXGlobalOptFlags.
Douglas Gregor0a812cf2010-02-18 23:07:20 +000033
Douglas Gregord1e6fdb2010-10-11 23:17:59 +000034 llvm::sys::Path ResourcesPath;
Argyrios Kyrtzidis389db162010-11-03 22:45:23 +000035 std::string WorkingDir;
36
Ted Kremenekab188932010-01-05 19:32:54 +000037public:
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000038 CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false),
39 Options(CXGlobalOpt_None) { }
Ted Kremenekab188932010-01-05 19:32:54 +000040
Ted Kremenekab188932010-01-05 19:32:54 +000041 /// \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
Douglas Gregor0a812cf2010-02-18 23:07:20 +000047 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
48 void setDisplayDiagnostics(bool Display = true) {
49 DisplayDiagnostics = Display;
50 }
51
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000052 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
Ted Kremenekab188932010-01-05 19:32:54 +000059 /// \brief Get the path of the clang resource files.
60 std::string getClangResourcesPath();
Argyrios Kyrtzidis389db162010-11-03 22:45:23 +000061
62 const std::string &getWorkingDirectory() const { return WorkingDir; }
63 void setWorkingDirectory(const std::string &Dir) { WorkingDir = Dir; }
Ted Kremenekab188932010-01-05 19:32:54 +000064};
65
Douglas Gregor4db64a42010-01-23 00:14:00 +000066 /**
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);
Daniel Dunbarbf44c3b2010-11-05 07:19:31 +000076
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,
Ted Kremenek6c53fdd2010-11-14 17:47:35 +000089 void (*Fn)(void*), void *UserData, unsigned Size = 0);
Douglas Gregor6df78732011-05-05 20:27:22 +000090
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000091 /// \brief Set the thread priority to background.
92 /// FIXME: Move to llvm/Support.
Argyrios Kyrtzidis81b5ac32012-03-28 02:49:54 +000093 void setThreadBackgroundPriority();
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000094
Douglas Gregor6df78732011-05-05 20:27:22 +000095 /// \brief Print libclang's resource usage to standard error.
96 void PrintLibclangResourceUsage(CXTranslationUnit TU);
Douglas Gregor4db64a42010-01-23 00:14:00 +000097}
98
Ted Kremenekab188932010-01-05 19:32:54 +000099#endif