blob: 8a306cde67ca576ef2dbcd9eb9e3d1e70baced7b [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"
20#include "clang/Lex/ModuleLoader.h"
Douglas Gregor27b4fa92010-01-26 17:06:03 +000021#include "llvm/ADT/StringRef.h"
Michael J. Spencer8aaf4992010-11-29 18:12:39 +000022#include "llvm/Support/Path.h"
Douglas Gregoraa98ed92010-01-23 00:14:00 +000023#include <vector>
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000024
Daniel Dunbarb7383e62010-11-05 07:19:31 +000025namespace llvm {
26 class CrashRecoveryContext;
27}
28
Argyrios Kyrtzidisc557bad2012-03-28 02:18:02 +000029namespace clang {
Richard Smith66a81862015-05-04 02:25:31 +000030class ASTUnit;
31class MacroInfo;
32class MacroDefinitionRecord;
33class SourceLocation;
34class Token;
35class IdentifierInfo;
Argyrios Kyrtzidisc557bad2012-03-28 02:18:02 +000036
Douglas Gregor87752492010-01-22 20:35:53 +000037class CIndexer {
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000038 bool OnlyLocalDecls;
Douglas Gregor1e21cc72010-02-18 23:07:20 +000039 bool DisplayDiagnostics;
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000040 unsigned Options; // CXGlobalOptFlags.
Douglas Gregor1e21cc72010-02-18 23:07:20 +000041
Benjamin Kramere3868e42013-06-13 13:56:37 +000042 std::string ResourcesPath;
Adrian Prantlbb165fb2015-06-20 18:53:08 +000043 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
Argyrios Kyrtzidis71731d62010-11-03 22:45:23 +000044
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000045public:
Adrian Prantlbb165fb2015-06-20 18:53:08 +000046 CIndexer(std::shared_ptr<PCHContainerOperations> PCHContainerOps =
47 std::make_shared<RawPCHContainerOperations>())
48 : OnlyLocalDecls(false), DisplayDiagnostics(false),
49 Options(CXGlobalOpt_None), PCHContainerOps(PCHContainerOps) {}
50
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000051 /// \brief Whether we only want to see "local" declarations (that did not
52 /// come from a previous precompiled header). If false, we want to see all
53 /// declarations.
54 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
55 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
56
Douglas Gregor1e21cc72010-02-18 23:07:20 +000057 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
58 void setDisplayDiagnostics(bool Display = true) {
59 DisplayDiagnostics = Display;
60 }
61
Adrian Prantlbb165fb2015-06-20 18:53:08 +000062 std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
63 return PCHContainerOps;
64 }
65
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000066 unsigned getCXGlobalOptFlags() const { return Options; }
67 void setCXGlobalOptFlags(unsigned options) { Options = options; }
68
69 bool isOptEnabled(CXGlobalOptFlags opt) const {
Argyrios Kyrtzidise26ba142012-03-28 20:42:59 +000070 return Options & opt;
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000071 }
72
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000073 /// \brief Get the path of the clang resource files.
Benjamin Kramere3868e42013-06-13 13:56:37 +000074 const std::string &getClangResourcesPath();
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000075};
76
Daniel Dunbarb7383e62010-11-05 07:19:31 +000077 /// \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 Kremenekca817a3c2010-11-14 17:47:35 +000089 void (*Fn)(void*), void *UserData, unsigned Size = 0);
Douglas Gregoraf44c782011-05-05 20:27:22 +000090
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000091 /// \brief Set the thread priority to background.
92 /// FIXME: Move to llvm/Support.
Argyrios Kyrtzidis58d5f3f2012-03-28 02:49:54 +000093 void setThreadBackgroundPriority();
Argyrios Kyrtzidis7317a5c2012-03-28 02:18:05 +000094
Douglas Gregoraf44c782011-05-05 20:27:22 +000095 /// \brief Print libclang's resource usage to standard error.
96 void PrintLibclangResourceUsage(CXTranslationUnit TU);
Argyrios Kyrtzidisac1cc932012-04-11 02:11:16 +000097
98 namespace cxindex {
99 void printDiagsToStderr(ASTUnit *Unit);
Argyrios Kyrtzidis579825a2013-01-07 19:16:25 +0000100
101 /// \brief If \c MacroDefLoc points at a macro definition with \c II as
102 /// its name, this retrieves its MacroInfo.
103 MacroInfo *getMacroInfo(const IdentifierInfo &II,
Richard Smith66a81862015-05-04 02:25:31 +0000104 SourceLocation MacroDefLoc, CXTranslationUnit TU);
Argyrios Kyrtzidis579825a2013-01-07 19:16:25 +0000105
Richard Smith66a81862015-05-04 02:25:31 +0000106 /// \brief Retrieves the corresponding MacroInfo of a MacroDefinitionRecord.
107 const MacroInfo *getMacroInfo(const MacroDefinitionRecord *MacroDef,
Dmitri Gribenkoba2f7462013-01-11 21:01:49 +0000108 CXTranslationUnit TU);
Argyrios Kyrtzidis579825a2013-01-07 19:16:25 +0000109
110 /// \brief If \c Loc resides inside the definition of \c MI and it points at
111 /// an identifier that has ever been a macro name, this returns the latest
Richard Smith66a81862015-05-04 02:25:31 +0000112 /// MacroDefinitionRecord for that name, otherwise it returns NULL.
113 MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
114 SourceLocation Loc,
115 CXTranslationUnit TU);
Argyrios Kyrtzidis579825a2013-01-07 19:16:25 +0000116
117 /// \brief If \c Tok resides inside the definition of \c MI and it points at
118 /// an identifier that has ever been a macro name, this returns the latest
Richard Smith66a81862015-05-04 02:25:31 +0000119 /// MacroDefinitionRecord for that name, otherwise it returns NULL.
120 MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
121 const Token &Tok,
122 CXTranslationUnit TU);
123 }
124 }
Douglas Gregoraa98ed92010-01-23 00:14:00 +0000125
Ted Kremenek0ec2cca2010-01-05 19:32:54 +0000126#endif