diff options
Diffstat (limited to 'clang-r353983/include/clang/Index')
| -rw-r--r-- | clang-r353983/include/clang/Index/CodegenNameGenerator.h | 51 | ||||
| -rw-r--r-- | clang-r353983/include/clang/Index/CommentToXML.h | 46 | ||||
| -rw-r--r-- | clang-r353983/include/clang/Index/IndexDataConsumer.h | 66 | ||||
| -rw-r--r-- | clang-r353983/include/clang/Index/IndexSymbol.h | 167 | ||||
| -rw-r--r-- | clang-r353983/include/clang/Index/IndexingAction.h | 79 | ||||
| -rw-r--r-- | clang-r353983/include/clang/Index/USRGeneration.h | 101 |
6 files changed, 510 insertions, 0 deletions
diff --git a/clang-r353983/include/clang/Index/CodegenNameGenerator.h b/clang-r353983/include/clang/Index/CodegenNameGenerator.h new file mode 100644 index 00000000..d2528a10 --- /dev/null +++ b/clang-r353983/include/clang/Index/CodegenNameGenerator.h @@ -0,0 +1,51 @@ +//===- CodegenNameGenerator.h - Codegen name generation -------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Determines the name that the symbol will get for code generation. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H +#define LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H + +#include "clang/Basic/LLVM.h" +#include <memory> +#include <string> +#include <vector> + +namespace clang { + class ASTContext; + class Decl; + +namespace index { + +class CodegenNameGenerator { +public: + explicit CodegenNameGenerator(ASTContext &Ctx); + ~CodegenNameGenerator(); + + /// \returns true on failure to produce a name for the given decl, false on + /// success. + bool writeName(const Decl *D, raw_ostream &OS); + + /// Version of \c writeName function that returns a string. + std::string getName(const Decl *D); + + /// This can return multiple mangled names when applicable, e.g. for C++ + /// constructors/destructors. + std::vector<std::string> getAllManglings(const Decl *D); + +private: + struct Implementation; + std::unique_ptr<Implementation> Impl; +}; + +} // namespace index +} // namespace clang + +#endif // LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H diff --git a/clang-r353983/include/clang/Index/CommentToXML.h b/clang-r353983/include/clang/Index/CommentToXML.h new file mode 100644 index 00000000..66b8650c --- /dev/null +++ b/clang-r353983/include/clang/Index/CommentToXML.h @@ -0,0 +1,46 @@ +//===--- CommentToXML.h - Convert comments to XML representation ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_INDEX_COMMENTTOXML_H +#define LLVM_CLANG_INDEX_COMMENTTOXML_H + +#include "clang/Basic/LLVM.h" +#include <memory> + +namespace clang { +class ASTContext; + +namespace comments { +class FullComment; +class HTMLTagComment; +} + +namespace index { +class CommentToXMLConverter { +public: + CommentToXMLConverter(); + ~CommentToXMLConverter(); + + void convertCommentToHTML(const comments::FullComment *FC, + SmallVectorImpl<char> &HTML, + const ASTContext &Context); + + void convertHTMLTagNodeToText(const comments::HTMLTagComment *HTC, + SmallVectorImpl<char> &Text, + const ASTContext &Context); + + void convertCommentToXML(const comments::FullComment *FC, + SmallVectorImpl<char> &XML, + const ASTContext &Context); +}; + +} // namespace index +} // namespace clang + +#endif // LLVM_CLANG_INDEX_COMMENTTOXML_H + diff --git a/clang-r353983/include/clang/Index/IndexDataConsumer.h b/clang-r353983/include/clang/Index/IndexDataConsumer.h new file mode 100644 index 00000000..bc1d8669 --- /dev/null +++ b/clang-r353983/include/clang/Index/IndexDataConsumer.h @@ -0,0 +1,66 @@ +//===--- IndexDataConsumer.h - Abstract index data consumer -----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_INDEX_INDEXDATACONSUMER_H +#define LLVM_CLANG_INDEX_INDEXDATACONSUMER_H + +#include "clang/Index/IndexSymbol.h" +#include "clang/Lex/Preprocessor.h" + +namespace clang { + class ASTContext; + class DeclContext; + class Expr; + class FileID; + class IdentifierInfo; + class ImportDecl; + class MacroInfo; + +namespace index { + +class IndexDataConsumer { +public: + struct ASTNodeInfo { + const Expr *OrigE; + const Decl *OrigD; + const Decl *Parent; + const DeclContext *ContainerDC; + }; + + virtual ~IndexDataConsumer() {} + + virtual void initialize(ASTContext &Ctx) {} + + virtual void setPreprocessor(std::shared_ptr<Preprocessor> PP) {} + + /// \returns true to continue indexing, or false to abort. + virtual bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles, + ArrayRef<SymbolRelation> Relations, + SourceLocation Loc, ASTNodeInfo ASTNode); + + /// \returns true to continue indexing, or false to abort. + virtual bool handleMacroOccurence(const IdentifierInfo *Name, + const MacroInfo *MI, SymbolRoleSet Roles, + SourceLocation Loc); + + /// \returns true to continue indexing, or false to abort. + /// + /// This will be called for each module reference in an import decl. + /// For "@import MyMod.SubMod", there will be a call for 'MyMod' with the + /// 'reference' role, and a call for 'SubMod' with the 'declaration' role. + virtual bool handleModuleOccurence(const ImportDecl *ImportD, + const Module *Mod, + SymbolRoleSet Roles, SourceLocation Loc); + + virtual void finish() {} +}; + +} // namespace index +} // namespace clang + +#endif diff --git a/clang-r353983/include/clang/Index/IndexSymbol.h b/clang-r353983/include/clang/Index/IndexSymbol.h new file mode 100644 index 00000000..0b15b6c3 --- /dev/null +++ b/clang-r353983/include/clang/Index/IndexSymbol.h @@ -0,0 +1,167 @@ +//===- IndexSymbol.h - Types and functions for indexing symbols -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H +#define LLVM_CLANG_INDEX_INDEXSYMBOL_H + +#include "clang/Basic/LLVM.h" +#include "clang/Lex/MacroInfo.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/Support/DataTypes.h" + +namespace clang { + class Decl; + class LangOptions; + +namespace index { + +enum class SymbolKind : uint8_t { + Unknown, + + Module, + Namespace, + NamespaceAlias, + Macro, + + Enum, + Struct, + Class, + Protocol, + Extension, + Union, + TypeAlias, + + Function, + Variable, + Field, + EnumConstant, + + InstanceMethod, + ClassMethod, + StaticMethod, + InstanceProperty, + ClassProperty, + StaticProperty, + + Constructor, + Destructor, + ConversionFunction, + + Parameter, + Using, +}; + +enum class SymbolLanguage : uint8_t { + C, + ObjC, + CXX, + Swift, +}; + +/// Language specific sub-kinds. +enum class SymbolSubKind : uint8_t { + None, + CXXCopyConstructor, + CXXMoveConstructor, + AccessorGetter, + AccessorSetter, + UsingTypename, + UsingValue, +}; + +typedef uint16_t SymbolPropertySet; +/// Set of properties that provide additional info about a symbol. +enum class SymbolProperty : SymbolPropertySet { + Generic = 1 << 0, + TemplatePartialSpecialization = 1 << 1, + TemplateSpecialization = 1 << 2, + UnitTest = 1 << 3, + IBAnnotated = 1 << 4, + IBOutletCollection = 1 << 5, + GKInspectable = 1 << 6, + Local = 1 << 7, + /// Symbol is part of a protocol interface. + ProtocolInterface = 1 << 8, +}; +static const unsigned SymbolPropertyBitNum = 9; + +/// Set of roles that are attributed to symbol occurrences. +/// +/// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum. +enum class SymbolRole : uint32_t { + Declaration = 1 << 0, + Definition = 1 << 1, + Reference = 1 << 2, + Read = 1 << 3, + Write = 1 << 4, + Call = 1 << 5, + Dynamic = 1 << 6, + AddressOf = 1 << 7, + Implicit = 1 << 8, + // FIXME: this is not mirrored in CXSymbolRole. + // Note that macro occurrences aren't currently supported in libclang. + Undefinition = 1 << 9, // macro #undef + + // Relation roles. + RelationChildOf = 1 << 10, + RelationBaseOf = 1 << 11, + RelationOverrideOf = 1 << 12, + RelationReceivedBy = 1 << 13, + RelationCalledBy = 1 << 14, + RelationExtendedBy = 1 << 15, + RelationAccessorOf = 1 << 16, + RelationContainedBy = 1 << 17, + RelationIBTypeOf = 1 << 18, + RelationSpecializationOf = 1 << 19, +}; +static const unsigned SymbolRoleBitNum = 20; +typedef unsigned SymbolRoleSet; + +/// Represents a relation to another symbol for a symbol occurrence. +struct SymbolRelation { + SymbolRoleSet Roles; + const Decl *RelatedSymbol; + + SymbolRelation(SymbolRoleSet Roles, const Decl *Sym) + : Roles(Roles), RelatedSymbol(Sym) {} +}; + +struct SymbolInfo { + SymbolKind Kind; + SymbolSubKind SubKind; + SymbolLanguage Lang; + SymbolPropertySet Properties; +}; + +SymbolInfo getSymbolInfo(const Decl *D); + +SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI); + +bool isFunctionLocalSymbol(const Decl *D); + +void applyForEachSymbolRole(SymbolRoleSet Roles, + llvm::function_ref<void(SymbolRole)> Fn); +bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, + llvm::function_ref<bool(SymbolRole)> Fn); +void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS); + +/// \returns true if no name was printed, false otherwise. +bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS); + +StringRef getSymbolKindString(SymbolKind K); +StringRef getSymbolSubKindString(SymbolSubKind K); +StringRef getSymbolLanguageString(SymbolLanguage K); + +void applyForEachSymbolProperty(SymbolPropertySet Props, + llvm::function_ref<void(SymbolProperty)> Fn); +void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS); + +} // namespace index +} // namespace clang + +#endif diff --git a/clang-r353983/include/clang/Index/IndexingAction.h b/clang-r353983/include/clang/Index/IndexingAction.h new file mode 100644 index 00000000..8b3d5415 --- /dev/null +++ b/clang-r353983/include/clang/Index/IndexingAction.h @@ -0,0 +1,79 @@ +//===--- IndexingAction.h - Frontend index action ---------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_INDEX_INDEXINGACTION_H +#define LLVM_CLANG_INDEX_INDEXINGACTION_H + +#include "clang/Basic/LLVM.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" +#include "llvm/ADT/ArrayRef.h" +#include <memory> + +namespace clang { + class ASTContext; + class ASTReader; + class ASTUnit; + class Decl; + class FrontendAction; + +namespace serialization { + class ModuleFile; +} + +namespace index { + class IndexDataConsumer; + +struct IndexingOptions { + enum class SystemSymbolFilterKind { + None, + DeclarationsOnly, + All, + }; + + SystemSymbolFilterKind SystemSymbolFilter + = SystemSymbolFilterKind::DeclarationsOnly; + bool IndexFunctionLocals = false; + bool IndexImplicitInstantiation = false; + // Whether to index macro definitions in the Preprocesor when preprocessor + // callback is not available (e.g. after parsing has finished). Note that + // macro references are not available in Proprocessor. + bool IndexMacrosInPreprocessor = false; + // Has no effect if IndexFunctionLocals are false. + bool IndexParametersInDeclarations = false; +}; + +/// Creates a frontend action that indexes all symbols (macros and AST decls). +/// \param WrappedAction another frontend action to wrap over or null. +std::unique_ptr<FrontendAction> +createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer, + IndexingOptions Opts, + std::unique_ptr<FrontendAction> WrappedAction); + +/// Recursively indexes all decls in the AST. +void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer, + IndexingOptions Opts); + +/// Recursively indexes \p Decls. +void indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP, + ArrayRef<const Decl *> Decls, + IndexDataConsumer &DataConsumer, IndexingOptions Opts); + +/// Creates a PPCallbacks that indexes macros and feeds macros to \p Consumer. +/// The caller is responsible for calling `Consumer.setPreprocessor()`. +std::unique_ptr<PPCallbacks> indexMacrosCallback(IndexDataConsumer &Consumer, + IndexingOptions Opts); + +/// Recursively indexes all top-level decls in the module. +void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader, + IndexDataConsumer &DataConsumer, IndexingOptions Opts); + +} // namespace index +} // namespace clang + +#endif diff --git a/clang-r353983/include/clang/Index/USRGeneration.h b/clang-r353983/include/clang/Index/USRGeneration.h new file mode 100644 index 00000000..f89fc5cf --- /dev/null +++ b/clang-r353983/include/clang/Index/USRGeneration.h @@ -0,0 +1,101 @@ +//===- USRGeneration.h - Routines for USR generation ------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_INDEX_USRGENERATION_H +#define LLVM_CLANG_INDEX_USRGENERATION_H + +#include "clang/Basic/LLVM.h" +#include "llvm/ADT/StringRef.h" + +namespace clang { +class ASTContext; +class Decl; +class MacroDefinitionRecord; +class Module; +class SourceLocation; +class SourceManager; +class QualType; + +namespace index { + +static inline StringRef getUSRSpacePrefix() { + return "c:"; +} + +/// Generate a USR for a Decl, including the USR prefix. +/// \returns true if the results should be ignored, false otherwise. +bool generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf); + +/// Generate a USR fragment for an Objective-C class. +void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS, + StringRef ExtSymbolDefinedIn = "", + StringRef CategoryContextExtSymbolDefinedIn = ""); + +/// Generate a USR fragment for an Objective-C class category. +void generateUSRForObjCCategory(StringRef Cls, StringRef Cat, raw_ostream &OS, + StringRef ClsExtSymbolDefinedIn = "", + StringRef CatExtSymbolDefinedIn = ""); + +/// Generate a USR fragment for an Objective-C instance variable. The +/// complete USR can be created by concatenating the USR for the +/// encompassing class with this USR fragment. +void generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS); + +/// Generate a USR fragment for an Objective-C method. +void generateUSRForObjCMethod(StringRef Sel, bool IsInstanceMethod, + raw_ostream &OS); + +/// Generate a USR fragment for an Objective-C property. +void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS); + +/// Generate a USR fragment for an Objective-C protocol. +void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS, + StringRef ExtSymbolDefinedIn = ""); + +/// Generate USR fragment for a global (non-nested) enum. +void generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS, + StringRef ExtSymbolDefinedIn = ""); + +/// Generate a USR fragment for an enum constant. +void generateUSRForEnumConstant(StringRef EnumConstantName, raw_ostream &OS); + +/// Generate a USR for a macro, including the USR prefix. +/// +/// \returns true on error, false on success. +bool generateUSRForMacro(const MacroDefinitionRecord *MD, + const SourceManager &SM, SmallVectorImpl<char> &Buf); +bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc, + const SourceManager &SM, SmallVectorImpl<char> &Buf); + +/// Generates a USR for a type. +/// +/// \return true on error, false on success. +bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl<char> &Buf); + +/// Generate a USR for a module, including the USR prefix. +/// \returns true on error, false on success. +bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS); + +/// Generate a USR for a top-level module name, including the USR prefix. +/// \returns true on error, false on success. +bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS); + +/// Generate a USR fragment for a module. +/// \returns true on error, false on success. +bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS); + +/// Generate a USR fragment for a module name. +/// \returns true on error, false on success. +bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS); + + +} // namespace index +} // namespace clang + +#endif // LLVM_CLANG_INDEX_USRGENERATION_H + |
