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_CINDEXER_H
16 #define LLVM_CLANG_CINDEXER_H
18 #include "clang-c/Index.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/Path.h"
24 class CrashRecoveryContext;
30 class MacroDefinition;
37 bool DisplayDiagnostics;
38 unsigned Options; // CXGlobalOptFlags.
40 std::string ResourcesPath;
43 CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false),
44 Options(CXGlobalOpt_None) { }
46 /// \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
49 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
50 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
52 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
53 void setDisplayDiagnostics(bool Display = true) {
54 DisplayDiagnostics = Display;
57 unsigned getCXGlobalOptFlags() const { return Options; }
58 void setCXGlobalOptFlags(unsigned options) { Options = options; }
60 bool isOptEnabled(CXGlobalOptFlags opt) const {
64 /// \brief Get the path of the clang resource files.
65 const std::string &getClangResourcesPath();
68 /// \brief Return the current size to request for "safety".
69 unsigned GetSafetyThreadStackSize();
71 /// \brief Set the current size to request for "safety" (or 0, if safety
72 /// threads should not be used).
73 void SetSafetyThreadStackSize(unsigned Value);
75 /// \brief Execution the given code "safely", using crash recovery or safety
76 /// threads when possible.
78 /// \return False if a crash was detected.
79 bool RunSafely(llvm::CrashRecoveryContext &CRC,
80 void (*Fn)(void*), void *UserData, unsigned Size = 0);
82 /// \brief Set the thread priority to background.
83 /// FIXME: Move to llvm/Support.
84 void setThreadBackgroundPriority();
86 /// \brief Print libclang's resource usage to standard error.
87 void PrintLibclangResourceUsage(CXTranslationUnit TU);
90 void printDiagsToStderr(ASTUnit *Unit);
92 /// \brief If \c MacroDefLoc points at a macro definition with \c II as
93 /// its name, this retrieves its MacroInfo.
94 MacroInfo *getMacroInfo(const IdentifierInfo &II,
95 SourceLocation MacroDefLoc,
96 CXTranslationUnit TU);
98 /// \brief Retrieves the corresponding MacroInfo of a MacroDefinition.
99 const MacroInfo *getMacroInfo(const MacroDefinition *MacroDef,
100 CXTranslationUnit TU);
102 /// \brief If \c Loc resides inside the definition of \c MI and it points at
103 /// an identifier that has ever been a macro name, this returns the latest
104 /// MacroDefinition for that name, otherwise it returns NULL.
105 MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI,
107 CXTranslationUnit TU);
109 /// \brief If \c Tok 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
111 /// MacroDefinition for that name, otherwise it returns NULL.
112 MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI,
114 CXTranslationUnit TU);