blob: 32cfa971f34a5d3f8d0a2ae0a89661b50dbc3c8c [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"
Ted Kremenekab188932010-01-05 19:32:54 +000020#include "llvm/System/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
Ted Kremenekee4db4f2010-02-17 00:41:08 +000027namespace clang {
28namespace cxstring {
29 CXString createCXString(const char *String, bool DupString = false);
30 CXString createCXString(llvm::StringRef String, bool DupString = true);
31}
32}
33
Douglas Gregora030b7c2010-01-22 20:35:53 +000034class CIndexer {
Ted Kremenekab188932010-01-05 19:32:54 +000035 bool OnlyLocalDecls;
Douglas Gregor0a812cf2010-02-18 23:07:20 +000036 bool DisplayDiagnostics;
37
Douglas Gregord1e6fdb2010-10-11 23:17:59 +000038 llvm::sys::Path ResourcesPath;
Argyrios Kyrtzidis389db162010-11-03 22:45:23 +000039 std::string WorkingDir;
40
Ted Kremenekab188932010-01-05 19:32:54 +000041public:
Douglas Gregorb10daed2010-10-11 16:52:23 +000042 CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false) { }
Ted Kremenekab188932010-01-05 19:32:54 +000043
Ted Kremenekab188932010-01-05 19:32:54 +000044 /// \brief Whether we only want to see "local" declarations (that did not
45 /// come from a previous precompiled header). If false, we want to see all
46 /// declarations.
47 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
48 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
49
Douglas Gregor0a812cf2010-02-18 23:07:20 +000050 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
51 void setDisplayDiagnostics(bool Display = true) {
52 DisplayDiagnostics = Display;
53 }
54
Ted Kremenekab188932010-01-05 19:32:54 +000055 /// \brief Get the path of the clang resource files.
56 std::string getClangResourcesPath();
Argyrios Kyrtzidis389db162010-11-03 22:45:23 +000057
58 const std::string &getWorkingDirectory() const { return WorkingDir; }
59 void setWorkingDirectory(const std::string &Dir) { WorkingDir = Dir; }
Ted Kremenekab188932010-01-05 19:32:54 +000060};
61
Douglas Gregor4db64a42010-01-23 00:14:00 +000062namespace clang {
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);
Daniel Dunbarbf44c3b2010-11-05 07:19:31 +000073
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,
Ted Kremenek6c53fdd2010-11-14 17:47:35 +000086 void (*Fn)(void*), void *UserData, unsigned Size = 0);
Douglas Gregor4db64a42010-01-23 00:14:00 +000087}
88
Ted Kremenekab188932010-01-05 19:32:54 +000089#endif