2010-11-05 15:19:31 +08:00
|
|
|
//===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===//
|
2010-01-06 03:32:54 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines CIndexer, a subclass of Indexer that provides extra
|
|
|
|
// functionality needed by the CIndex library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H
|
|
|
|
#define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXER_H
|
2010-01-06 03:32:54 +08:00
|
|
|
|
|
|
|
#include "clang-c/Index.h"
|
2015-06-21 02:53:08 +08:00
|
|
|
#include "clang/Frontend/PCHContainerOperations.h"
|
2016-07-19 03:02:11 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2016-05-27 22:27:13 +08:00
|
|
|
#include <utility>
|
2010-01-06 03:32:54 +08:00
|
|
|
|
2010-11-05 15:19:31 +08:00
|
|
|
namespace llvm {
|
|
|
|
class CrashRecoveryContext;
|
|
|
|
}
|
|
|
|
|
2012-03-28 10:18:02 +08:00
|
|
|
namespace clang {
|
2015-05-04 10:25:31 +08:00
|
|
|
class ASTUnit;
|
|
|
|
class MacroInfo;
|
|
|
|
class MacroDefinitionRecord;
|
|
|
|
class SourceLocation;
|
|
|
|
class Token;
|
|
|
|
class IdentifierInfo;
|
2012-03-28 10:18:02 +08:00
|
|
|
|
2010-01-23 04:35:53 +08:00
|
|
|
class CIndexer {
|
2010-01-06 03:32:54 +08:00
|
|
|
bool OnlyLocalDecls;
|
2010-02-19 07:07:20 +08:00
|
|
|
bool DisplayDiagnostics;
|
2012-03-28 10:18:05 +08:00
|
|
|
unsigned Options; // CXGlobalOptFlags.
|
2010-02-19 07:07:20 +08:00
|
|
|
|
2013-06-13 21:56:37 +08:00
|
|
|
std::string ResourcesPath;
|
2015-06-21 02:53:08 +08:00
|
|
|
std::shared_ptr<PCHContainerOperations> PCHContainerOps;
|
2010-11-04 06:45:23 +08:00
|
|
|
|
2010-01-06 03:32:54 +08:00
|
|
|
public:
|
2015-06-21 02:53:08 +08:00
|
|
|
CIndexer(std::shared_ptr<PCHContainerOperations> PCHContainerOps =
|
2015-07-17 09:19:54 +08:00
|
|
|
std::make_shared<PCHContainerOperations>())
|
2015-06-21 02:53:08 +08:00
|
|
|
: OnlyLocalDecls(false), DisplayDiagnostics(false),
|
2016-05-27 22:27:13 +08:00
|
|
|
Options(CXGlobalOpt_None), PCHContainerOps(std::move(PCHContainerOps)) {
|
|
|
|
}
|
2015-06-21 02:53:08 +08:00
|
|
|
|
2010-01-06 03:32:54 +08:00
|
|
|
/// \brief Whether we only want to see "local" declarations (that did not
|
|
|
|
/// come from a previous precompiled header). If false, we want to see all
|
|
|
|
/// declarations.
|
|
|
|
bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
|
|
|
|
void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
|
|
|
|
|
2010-02-19 07:07:20 +08:00
|
|
|
bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
|
|
|
|
void setDisplayDiagnostics(bool Display = true) {
|
|
|
|
DisplayDiagnostics = Display;
|
|
|
|
}
|
|
|
|
|
2015-06-21 02:53:08 +08:00
|
|
|
std::shared_ptr<PCHContainerOperations> getPCHContainerOperations() const {
|
|
|
|
return PCHContainerOps;
|
|
|
|
}
|
|
|
|
|
2012-03-28 10:18:05 +08:00
|
|
|
unsigned getCXGlobalOptFlags() const { return Options; }
|
|
|
|
void setCXGlobalOptFlags(unsigned options) { Options = options; }
|
|
|
|
|
|
|
|
bool isOptEnabled(CXGlobalOptFlags opt) const {
|
2012-03-29 04:42:59 +08:00
|
|
|
return Options & opt;
|
2012-03-28 10:18:05 +08:00
|
|
|
}
|
|
|
|
|
2010-01-06 03:32:54 +08:00
|
|
|
/// \brief Get the path of the clang resource files.
|
2013-06-13 21:56:37 +08:00
|
|
|
const std::string &getClangResourcesPath();
|
2010-01-06 03:32:54 +08:00
|
|
|
};
|
|
|
|
|
2010-11-05 15:19:31 +08:00
|
|
|
/// \brief Return the current size to request for "safety".
|
|
|
|
unsigned GetSafetyThreadStackSize();
|
|
|
|
|
|
|
|
/// \brief Set the current size to request for "safety" (or 0, if safety
|
|
|
|
/// threads should not be used).
|
|
|
|
void SetSafetyThreadStackSize(unsigned Value);
|
|
|
|
|
|
|
|
/// \brief Execution the given code "safely", using crash recovery or safety
|
|
|
|
/// threads when possible.
|
|
|
|
///
|
|
|
|
/// \return False if a crash was detected.
|
2015-07-26 04:55:44 +08:00
|
|
|
bool RunSafely(llvm::CrashRecoveryContext &CRC, llvm::function_ref<void()> Fn,
|
|
|
|
unsigned Size = 0);
|
2011-05-06 04:27:22 +08:00
|
|
|
|
2012-03-28 10:18:05 +08:00
|
|
|
/// \brief Set the thread priority to background.
|
|
|
|
/// FIXME: Move to llvm/Support.
|
2012-03-28 10:49:54 +08:00
|
|
|
void setThreadBackgroundPriority();
|
2012-03-28 10:18:05 +08:00
|
|
|
|
2011-05-06 04:27:22 +08:00
|
|
|
/// \brief Print libclang's resource usage to standard error.
|
|
|
|
void PrintLibclangResourceUsage(CXTranslationUnit TU);
|
2012-04-11 10:11:16 +08:00
|
|
|
|
|
|
|
namespace cxindex {
|
|
|
|
void printDiagsToStderr(ASTUnit *Unit);
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
/// \brief If \c MacroDefLoc points at a macro definition with \c II as
|
|
|
|
/// its name, this retrieves its MacroInfo.
|
|
|
|
MacroInfo *getMacroInfo(const IdentifierInfo &II,
|
2015-05-04 10:25:31 +08:00
|
|
|
SourceLocation MacroDefLoc, CXTranslationUnit TU);
|
2013-01-08 03:16:25 +08:00
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
/// \brief Retrieves the corresponding MacroInfo of a MacroDefinitionRecord.
|
|
|
|
const MacroInfo *getMacroInfo(const MacroDefinitionRecord *MacroDef,
|
2013-01-12 05:01:49 +08:00
|
|
|
CXTranslationUnit TU);
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
/// \brief If \c Loc resides inside the definition of \c MI and it points at
|
|
|
|
/// an identifier that has ever been a macro name, this returns the latest
|
2015-05-04 10:25:31 +08:00
|
|
|
/// MacroDefinitionRecord for that name, otherwise it returns NULL.
|
|
|
|
MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
|
|
|
|
SourceLocation Loc,
|
|
|
|
CXTranslationUnit TU);
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
/// \brief If \c Tok resides inside the definition of \c MI and it points at
|
|
|
|
/// an identifier that has ever been a macro name, this returns the latest
|
2015-05-04 10:25:31 +08:00
|
|
|
/// MacroDefinitionRecord for that name, otherwise it returns NULL.
|
|
|
|
MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
|
|
|
|
const Token &Tok,
|
|
|
|
CXTranslationUnit TU);
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
2010-01-23 08:14:00 +08:00
|
|
|
|
2010-01-06 03:32:54 +08:00
|
|
|
#endif
|