xref: /minix3/external/bsd/llvm/dist/clang/tools/libclang/CIndexer.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file defines CIndexer, a subclass of Indexer that provides extra
11f4a2713aSLionel Sambuc // functionality needed by the CIndex library.
12f4a2713aSLionel Sambuc //
13f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
14f4a2713aSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H
16*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc #include "clang-c/Index.h"
19f4a2713aSLionel Sambuc #include "llvm/ADT/StringRef.h"
20f4a2713aSLionel Sambuc #include "llvm/Support/Path.h"
21f4a2713aSLionel Sambuc #include <vector>
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc namespace llvm {
24f4a2713aSLionel Sambuc   class CrashRecoveryContext;
25f4a2713aSLionel Sambuc }
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc namespace clang {
28f4a2713aSLionel Sambuc   class ASTUnit;
29f4a2713aSLionel Sambuc   class MacroInfo;
30f4a2713aSLionel Sambuc   class MacroDefinition;
31f4a2713aSLionel Sambuc   class SourceLocation;
32f4a2713aSLionel Sambuc   class Token;
33f4a2713aSLionel Sambuc   class IdentifierInfo;
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc class CIndexer {
36f4a2713aSLionel Sambuc   bool OnlyLocalDecls;
37f4a2713aSLionel Sambuc   bool DisplayDiagnostics;
38f4a2713aSLionel Sambuc   unsigned Options; // CXGlobalOptFlags.
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc   std::string ResourcesPath;
41f4a2713aSLionel Sambuc 
42f4a2713aSLionel Sambuc public:
CIndexer()43f4a2713aSLionel Sambuc  CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false),
44f4a2713aSLionel Sambuc               Options(CXGlobalOpt_None) { }
45f4a2713aSLionel Sambuc 
46f4a2713aSLionel Sambuc   /// \brief Whether we only want to see "local" declarations (that did not
47f4a2713aSLionel Sambuc   /// come from a previous precompiled header). If false, we want to see all
48f4a2713aSLionel Sambuc   /// declarations.
getOnlyLocalDecls()49f4a2713aSLionel Sambuc   bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
50f4a2713aSLionel Sambuc   void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
51f4a2713aSLionel Sambuc 
getDisplayDiagnostics()52f4a2713aSLionel Sambuc   bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
53f4a2713aSLionel Sambuc   void setDisplayDiagnostics(bool Display = true) {
54f4a2713aSLionel Sambuc     DisplayDiagnostics = Display;
55f4a2713aSLionel Sambuc   }
56f4a2713aSLionel Sambuc 
getCXGlobalOptFlags()57f4a2713aSLionel Sambuc   unsigned getCXGlobalOptFlags() const { return Options; }
setCXGlobalOptFlags(unsigned options)58f4a2713aSLionel Sambuc   void setCXGlobalOptFlags(unsigned options) { Options = options; }
59f4a2713aSLionel Sambuc 
isOptEnabled(CXGlobalOptFlags opt)60f4a2713aSLionel Sambuc   bool isOptEnabled(CXGlobalOptFlags opt) const {
61f4a2713aSLionel Sambuc     return Options & opt;
62f4a2713aSLionel Sambuc   }
63f4a2713aSLionel Sambuc 
64f4a2713aSLionel Sambuc   /// \brief Get the path of the clang resource files.
65f4a2713aSLionel Sambuc   const std::string &getClangResourcesPath();
66f4a2713aSLionel Sambuc };
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc   /// \brief Return the current size to request for "safety".
69f4a2713aSLionel Sambuc   unsigned GetSafetyThreadStackSize();
70f4a2713aSLionel Sambuc 
71f4a2713aSLionel Sambuc   /// \brief Set the current size to request for "safety" (or 0, if safety
72f4a2713aSLionel Sambuc   /// threads should not be used).
73f4a2713aSLionel Sambuc   void SetSafetyThreadStackSize(unsigned Value);
74f4a2713aSLionel Sambuc 
75f4a2713aSLionel Sambuc   /// \brief Execution the given code "safely", using crash recovery or safety
76f4a2713aSLionel Sambuc   /// threads when possible.
77f4a2713aSLionel Sambuc   ///
78f4a2713aSLionel Sambuc   /// \return False if a crash was detected.
79f4a2713aSLionel Sambuc   bool RunSafely(llvm::CrashRecoveryContext &CRC,
80f4a2713aSLionel Sambuc                  void (*Fn)(void*), void *UserData, unsigned Size = 0);
81f4a2713aSLionel Sambuc 
82f4a2713aSLionel Sambuc   /// \brief Set the thread priority to background.
83f4a2713aSLionel Sambuc   /// FIXME: Move to llvm/Support.
84f4a2713aSLionel Sambuc   void setThreadBackgroundPriority();
85f4a2713aSLionel Sambuc 
86f4a2713aSLionel Sambuc   /// \brief Print libclang's resource usage to standard error.
87f4a2713aSLionel Sambuc   void PrintLibclangResourceUsage(CXTranslationUnit TU);
88f4a2713aSLionel Sambuc 
89f4a2713aSLionel Sambuc   namespace cxindex {
90f4a2713aSLionel Sambuc     void printDiagsToStderr(ASTUnit *Unit);
91f4a2713aSLionel Sambuc 
92f4a2713aSLionel Sambuc     /// \brief If \c MacroDefLoc points at a macro definition with \c II as
93f4a2713aSLionel Sambuc     /// its name, this retrieves its MacroInfo.
94f4a2713aSLionel Sambuc     MacroInfo *getMacroInfo(const IdentifierInfo &II,
95f4a2713aSLionel Sambuc                             SourceLocation MacroDefLoc,
96f4a2713aSLionel Sambuc                             CXTranslationUnit TU);
97f4a2713aSLionel Sambuc 
98f4a2713aSLionel Sambuc     /// \brief Retrieves the corresponding MacroInfo of a MacroDefinition.
99f4a2713aSLionel Sambuc     const MacroInfo *getMacroInfo(const MacroDefinition *MacroDef,
100f4a2713aSLionel Sambuc                                   CXTranslationUnit TU);
101f4a2713aSLionel Sambuc 
102f4a2713aSLionel Sambuc     /// \brief If \c Loc resides inside the definition of \c MI and it points at
103f4a2713aSLionel Sambuc     /// an identifier that has ever been a macro name, this returns the latest
104f4a2713aSLionel Sambuc     /// MacroDefinition for that name, otherwise it returns NULL.
105f4a2713aSLionel Sambuc     MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI,
106f4a2713aSLionel Sambuc                                                     SourceLocation Loc,
107f4a2713aSLionel Sambuc                                                     CXTranslationUnit TU);
108f4a2713aSLionel Sambuc 
109f4a2713aSLionel Sambuc     /// \brief If \c Tok resides inside the definition of \c MI and it points at
110f4a2713aSLionel Sambuc     /// an identifier that has ever been a macro name, this returns the latest
111f4a2713aSLionel Sambuc     /// MacroDefinition for that name, otherwise it returns NULL.
112f4a2713aSLionel Sambuc     MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI,
113f4a2713aSLionel Sambuc                                                     const Token &Tok,
114f4a2713aSLionel Sambuc                                                     CXTranslationUnit TU);
115f4a2713aSLionel Sambuc   }
116f4a2713aSLionel Sambuc }
117f4a2713aSLionel Sambuc 
118f4a2713aSLionel Sambuc #endif
119