blob: d34547dffd43178b94b2ef5fd605c86cd3635a97 [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 {
Argyrios Kyrtzidise722ed62012-04-11 02:11:16 +000028 class ASTUnit;
Argyrios Kyrtzidis664b06f2013-01-07 19:16:25 +000029 class MacroInfo;
30 class MacroDefinition;
31 class SourceLocation;
32 class Token;
33 class IdentifierInfo;
Argyrios Kyrtzidisbbca5642012-03-28 02:18:02 +000034
Douglas Gregora030b7c2010-01-22 20:35:53 +000035class CIndexer {
Ted Kremenekab188932010-01-05 19:32:54 +000036 bool OnlyLocalDecls;
Douglas Gregor0a812cf2010-02-18 23:07:20 +000037 bool DisplayDiagnostics;
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000038 unsigned Options; // CXGlobalOptFlags.
Douglas Gregor0a812cf2010-02-18 23:07:20 +000039
Douglas Gregord1e6fdb2010-10-11 23:17:59 +000040 llvm::sys::Path ResourcesPath;
Argyrios Kyrtzidis389db162010-11-03 22:45:23 +000041
Ted Kremenekab188932010-01-05 19:32:54 +000042public:
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000043 CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false),
44 Options(CXGlobalOpt_None) { }
Ted Kremenekab188932010-01-05 19:32:54 +000045
Ted Kremenekab188932010-01-05 19:32:54 +000046 /// \brief Whether we only want to see "local" declarations (that did not
47 /// come from a previous precompiled header). If false, we want to see all
48 /// declarations.
49 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
50 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
51
Douglas Gregor0a812cf2010-02-18 23:07:20 +000052 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
53 void setDisplayDiagnostics(bool Display = true) {
54 DisplayDiagnostics = Display;
55 }
56
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000057 unsigned getCXGlobalOptFlags() const { return Options; }
58 void setCXGlobalOptFlags(unsigned options) { Options = options; }
59
60 bool isOptEnabled(CXGlobalOptFlags opt) const {
Argyrios Kyrtzidisf962eb42012-03-28 20:42:59 +000061 return Options & opt;
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000062 }
63
Ted Kremenekab188932010-01-05 19:32:54 +000064 /// \brief Get the path of the clang resource files.
65 std::string getClangResourcesPath();
Ted Kremenekab188932010-01-05 19:32:54 +000066};
67
Douglas Gregor4db64a42010-01-23 00:14:00 +000068 /**
69 * \brief Given a set of "unsaved" files, create temporary files and
70 * construct the clang -cc1 argument list needed to perform the remapping.
71 *
72 * \returns true if an error occurred.
73 */
74 bool RemapFiles(unsigned num_unsaved_files,
75 struct CXUnsavedFile *unsaved_files,
76 std::vector<std::string> &RemapArgs,
77 std::vector<llvm::sys::Path> &TemporaryFiles);
Daniel Dunbarbf44c3b2010-11-05 07:19:31 +000078
79 /// \brief Return the current size to request for "safety".
80 unsigned GetSafetyThreadStackSize();
81
82 /// \brief Set the current size to request for "safety" (or 0, if safety
83 /// threads should not be used).
84 void SetSafetyThreadStackSize(unsigned Value);
85
86 /// \brief Execution the given code "safely", using crash recovery or safety
87 /// threads when possible.
88 ///
89 /// \return False if a crash was detected.
90 bool RunSafely(llvm::CrashRecoveryContext &CRC,
Ted Kremenek6c53fdd2010-11-14 17:47:35 +000091 void (*Fn)(void*), void *UserData, unsigned Size = 0);
Douglas Gregor6df78732011-05-05 20:27:22 +000092
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000093 /// \brief Set the thread priority to background.
94 /// FIXME: Move to llvm/Support.
Argyrios Kyrtzidis81b5ac32012-03-28 02:49:54 +000095 void setThreadBackgroundPriority();
Argyrios Kyrtzidisfdc17952012-03-28 02:18:05 +000096
Douglas Gregor6df78732011-05-05 20:27:22 +000097 /// \brief Print libclang's resource usage to standard error.
98 void PrintLibclangResourceUsage(CXTranslationUnit TU);
Argyrios Kyrtzidise722ed62012-04-11 02:11:16 +000099
100 namespace cxindex {
101 void printDiagsToStderr(ASTUnit *Unit);
Argyrios Kyrtzidis664b06f2013-01-07 19:16:25 +0000102
103 /// \brief If \c MacroDefLoc points at a macro definition with \c II as
104 /// its name, this retrieves its MacroInfo.
105 MacroInfo *getMacroInfo(const IdentifierInfo &II,
106 SourceLocation MacroDefLoc,
107 CXTranslationUnit TU);
108
109 /// \brief Retrieves the corresponding MacroInfo of a MacroDefinition.
110 MacroInfo *getMacroInfo(MacroDefinition *MacroDef, CXTranslationUnit TU);
111
112 /// \brief If \c Loc resides inside the definition of \c MI and it points at
113 /// an identifier that has ever been a macro name, this returns the latest
114 /// MacroDefinition for that name, otherwise it returns NULL.
115 MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI,
116 SourceLocation Loc,
117 CXTranslationUnit TU);
118
119 /// \brief If \c Tok resides inside the definition of \c MI and it points at
120 /// an identifier that has ever been a macro name, this returns the latest
121 /// MacroDefinition for that name, otherwise it returns NULL.
122 MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI,
123 const Token &Tok,
124 CXTranslationUnit TU);
Argyrios Kyrtzidise722ed62012-04-11 02:11:16 +0000125 }
Douglas Gregor4db64a42010-01-23 00:14:00 +0000126}
127
Ted Kremenekab188932010-01-05 19:32:54 +0000128#endif