blob: b227f943f7b3bc5a975fc15a5d2c0f7c4fd18495 [file] [log] [blame]
Daniel Dunbarb7383e62010-11-05 07:19:31 +00001//===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===//
Ted Kremenek0ec2cca2010-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
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000015#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H
16#define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000017
18#include "clang-c/Index.h"
Adrian Prantlbb165fb2015-06-20 18:53:08 +000019#include "clang/Frontend/PCHContainerOperations.h"
Mehdi Amini9670f842016-07-18 19:02:11 +000020#include "llvm/ADT/STLExtras.h"
Benjamin Kramercfeacf52016-05-27 14:27:13 +000021#include <utility>
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000022
Daniel Dunbarb7383e62010-11-05 07:19:31 +000023namespace llvm {
24 class CrashRecoveryContext;
25}
26
Argyrios Kyrtzidisc557bad2012-03-28 02:18:02 +000027namespace clang {
Richard Smith66a81862015-05-04 02:25:31 +000028class ASTUnit;
29class MacroInfo;
30class MacroDefinitionRecord;
31class SourceLocation;
32class Token;
33class IdentifierInfo;
Argyrios Kyrtzidisc557bad2012-03-28 02:18:02 +000034
Douglas Gregor87752492010-01-22 20:35:53 +000035class CIndexer {
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000036 bool OnlyLocalDecls;
Douglas Gregor1e21cc72010-02-18 23:07:20 +000037 bool DisplayDiagnostics;
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000038 unsigned Options; // CXGlobalOptFlags.
Douglas Gregor1e21cc72010-02-18 23:07:20 +000039
Benjamin Kramere3868e42013-06-13 13:56:37 +000040 std::string ResourcesPath;
Adrian Prantlbb165fb2015-06-20 18:53:08 +000041 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
Argyrios Kyrtzidis71731d62010-11-03 22:45:23 +000042
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000043public:
Adrian Prantlbb165fb2015-06-20 18:53:08 +000044 CIndexer(std::shared_ptr<PCHContainerOperations> PCHContainerOps =
Adrian Prantlfb2398d2015-07-17 01:19:54 +000045 std::make_shared<PCHContainerOperations>())
Adrian Prantlbb165fb2015-06-20 18:53:08 +000046 : OnlyLocalDecls(false), DisplayDiagnostics(false),
Benjamin Kramercfeacf52016-05-27 14:27:13 +000047 Options(CXGlobalOpt_None), PCHContainerOps(std::move(PCHContainerOps)) {
48 }
Adrian Prantlbb165fb2015-06-20 18:53:08 +000049
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000050 /// \brief Whether we only want to see "local" declarations (that did not
51 /// come from a previous precompiled header). If false, we want to see all
52 /// declarations.
53 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
54 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
55
Douglas Gregor1e21cc72010-02-18 23:07:20 +000056 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
57 void setDisplayDiagnostics(bool Display = true) {
58 DisplayDiagnostics = Display;
59 }
60
Adrian Prantlbb165fb2015-06-20 18:53:08 +000061 std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
62 return PCHContainerOps;
63 }
64
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000065 unsigned getCXGlobalOptFlags() const { return Options; }
66 void setCXGlobalOptFlags(unsigned options) { Options = options; }
67
68 bool isOptEnabled(CXGlobalOptFlags opt) const {
Argyrios Kyrtzidise26ba142012-03-28 20:42:59 +000069 return Options & opt;
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000070 }
71
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000072 /// \brief Get the path of the clang resource files.
Benjamin Kramere3868e42013-06-13 13:56:37 +000073 const std::string &getClangResourcesPath();
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000074};
75
Daniel Dunbarb7383e62010-11-05 07:19:31 +000076 /// \brief Return the current size to request for "safety".
77 unsigned GetSafetyThreadStackSize();
78
79 /// \brief Set the current size to request for "safety" (or 0, if safety
80 /// threads should not be used).
81 void SetSafetyThreadStackSize(unsigned Value);
82
83 /// \brief Execution the given code "safely", using crash recovery or safety
84 /// threads when possible.
85 ///
86 /// \return False if a crash was detected.
Benjamin Kramer11a9cd92015-07-25 20:55:44 +000087 bool RunSafely(llvm::CrashRecoveryContext &CRC, llvm::function_ref<void()> Fn,
88 unsigned Size = 0);
Douglas Gregoraf44c782011-05-05 20:27:22 +000089
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000090 /// \brief Set the thread priority to background.
91 /// FIXME: Move to llvm/Support.
Argyrios Kyrtzidis58d5f3f2012-03-28 02:49:54 +000092 void setThreadBackgroundPriority();
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000093
Douglas Gregoraf44c782011-05-05 20:27:22 +000094 /// \brief Print libclang's resource usage to standard error.
95 void PrintLibclangResourceUsage(CXTranslationUnit TU);
Argyrios Kyrtzidisac1cc932012-04-11 02:11:16 +000096
97 namespace cxindex {
98 void printDiagsToStderr(ASTUnit *Unit);
Argyrios Kyrtzidis579825a2013-01-07 19:16:25 +000099
100 /// \brief If \c MacroDefLoc points at a macro definition with \c II as
101 /// its name, this retrieves its MacroInfo.
102 MacroInfo *getMacroInfo(const IdentifierInfo &II,
Richard Smith66a81862015-05-04 02:25:31 +0000103 SourceLocation MacroDefLoc, CXTranslationUnit TU);
Argyrios Kyrtzidis579825a2013-01-07 19:16:25 +0000104
Richard Smith66a81862015-05-04 02:25:31 +0000105 /// \brief Retrieves the corresponding MacroInfo of a MacroDefinitionRecord.
106 const MacroInfo *getMacroInfo(const MacroDefinitionRecord *MacroDef,
Dmitri Gribenkoba2f7462013-01-11 21:01:49 +0000107 CXTranslationUnit TU);
Argyrios Kyrtzidis579825a2013-01-07 19:16:25 +0000108
109 /// \brief If \c Loc resides inside the definition of \c MI and it points at
110 /// an identifier that has ever been a macro name, this returns the latest
Richard Smith66a81862015-05-04 02:25:31 +0000111 /// MacroDefinitionRecord for that name, otherwise it returns NULL.
112 MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
113 SourceLocation Loc,
114 CXTranslationUnit TU);
Argyrios Kyrtzidis579825a2013-01-07 19:16:25 +0000115
116 /// \brief If \c Tok resides inside the definition of \c MI and it points at
117 /// an identifier that has ever been a macro name, this returns the latest
Richard Smith66a81862015-05-04 02:25:31 +0000118 /// MacroDefinitionRecord for that name, otherwise it returns NULL.
119 MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
120 const Token &Tok,
121 CXTranslationUnit TU);
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000122 }
123 }
Douglas Gregoraa98ed92010-01-23 00:14:00 +0000124
Ted Kremenek0ec2cca2010-01-05 19:32:54 +0000125#endif