1 //===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines CIndexer, a subclass of Indexer that provides extra
11 // functionality needed by the CIndex library.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H
16 #define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H
18 #include "clang-c/Index.h"
19 #include "clang/Frontend/PCHContainerOperations.h"
20 #include "clang/Lex/ModuleLoader.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/Path.h"
26 class CrashRecoveryContext;
32 class MacroDefinitionRecord;
39 bool DisplayDiagnostics;
40 unsigned Options; // CXGlobalOptFlags.
42 std::string ResourcesPath;
43 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
46 CIndexer(std::shared_ptr<PCHContainerOperations> PCHContainerOps =
47 std::make_shared<RawPCHContainerOperations>())
48 : OnlyLocalDecls(false), DisplayDiagnostics(false),
49 Options(CXGlobalOpt_None), PCHContainerOps(PCHContainerOps) {}
51 /// \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
54 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
55 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
57 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
58 void setDisplayDiagnostics(bool Display = true) {
59 DisplayDiagnostics = Display;
62 std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
63 return PCHContainerOps;
66 unsigned getCXGlobalOptFlags() const { return Options; }
67 void setCXGlobalOptFlags(unsigned options) { Options = options; }
69 bool isOptEnabled(CXGlobalOptFlags opt) const {
73 /// \brief Get the path of the clang resource files.
74 const std::string &getClangResourcesPath();
77 /// \brief Return the current size to request for "safety".
78 unsigned GetSafetyThreadStackSize();
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);
84 /// \brief Execution the given code "safely", using crash recovery or safety
85 /// threads when possible.
87 /// \return False if a crash was detected.
88 bool RunSafely(llvm::CrashRecoveryContext &CRC,
89 void (*Fn)(void*), void *UserData, unsigned Size = 0);
91 /// \brief Set the thread priority to background.
92 /// FIXME: Move to llvm/Support.
93 void setThreadBackgroundPriority();
95 /// \brief Print libclang's resource usage to standard error.
96 void PrintLibclangResourceUsage(CXTranslationUnit TU);
99 void printDiagsToStderr(ASTUnit *Unit);
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,
104 SourceLocation MacroDefLoc, CXTranslationUnit TU);
106 /// \brief Retrieves the corresponding MacroInfo of a MacroDefinitionRecord.
107 const MacroInfo *getMacroInfo(const MacroDefinitionRecord *MacroDef,
108 CXTranslationUnit TU);
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
112 /// MacroDefinitionRecord for that name, otherwise it returns NULL.
113 MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
115 CXTranslationUnit TU);
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
119 /// MacroDefinitionRecord for that name, otherwise it returns NULL.
120 MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
122 CXTranslationUnit TU);