1//===--- IndexSymbol.h - Types and functions for indexing symbols ---------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H 11#define LLVM_CLANG_INDEX_INDEXSYMBOL_H 12 13#include "clang/Basic/LLVM.h" 14#include "llvm/ADT/STLExtras.h" 15#include "llvm/Support/DataTypes.h" 16 17namespace clang { 18 class Decl; 19 class LangOptions; 20 21namespace index { 22 23enum class SymbolKind : uint8_t { 24 Unknown, 25 26 Module, 27 Namespace, 28 NamespaceAlias, 29 Macro, 30 31 Enum, 32 Struct, 33 Class, 34 Protocol, 35 Extension, 36 Union, 37 TypeAlias, 38 39 Function, 40 Variable, 41 Field, 42 EnumConstant, 43 44 InstanceMethod, 45 ClassMethod, 46 StaticMethod, 47 InstanceProperty, 48 ClassProperty, 49 StaticProperty, 50 51 Constructor, 52 Destructor, 53 ConversionFunction, 54 55 Parameter, 56 Using, 57}; 58 59enum class SymbolLanguage { 60 C, 61 ObjC, 62 CXX, 63 Swift, 64}; 65 66/// Language specific sub-kinds. 67enum class SymbolSubKind { 68 None, 69 CXXCopyConstructor, 70 CXXMoveConstructor, 71 AccessorGetter, 72 AccessorSetter, 73 UsingTypename, 74 UsingValue, 75}; 76 77/// Set of properties that provide additional info about a symbol. 78enum class SymbolProperty : uint8_t { 79 Generic = 1 << 0, 80 TemplatePartialSpecialization = 1 << 1, 81 TemplateSpecialization = 1 << 2, 82 UnitTest = 1 << 3, 83 IBAnnotated = 1 << 4, 84 IBOutletCollection = 1 << 5, 85 GKInspectable = 1 << 6, 86 Local = 1 << 7, 87}; 88static const unsigned SymbolPropertyBitNum = 8; 89typedef unsigned SymbolPropertySet; 90 91/// Set of roles that are attributed to symbol occurrences. 92enum class SymbolRole : uint32_t { 93 Declaration = 1 << 0, 94 Definition = 1 << 1, 95 Reference = 1 << 2, 96 Read = 1 << 3, 97 Write = 1 << 4, 98 Call = 1 << 5, 99 Dynamic = 1 << 6, 100 AddressOf = 1 << 7, 101 Implicit = 1 << 8, 102 103 // Relation roles. 104 RelationChildOf = 1 << 9, 105 RelationBaseOf = 1 << 10, 106 RelationOverrideOf = 1 << 11, 107 RelationReceivedBy = 1 << 12, 108 RelationCalledBy = 1 << 13, 109 RelationExtendedBy = 1 << 14, 110 RelationAccessorOf = 1 << 15, 111 RelationContainedBy = 1 << 16, 112 RelationIBTypeOf = 1 << 17, 113 RelationSpecializationOf = 1 << 18, 114}; 115static const unsigned SymbolRoleBitNum = 19; 116typedef unsigned SymbolRoleSet; 117 118/// Represents a relation to another symbol for a symbol occurrence. 119struct SymbolRelation { 120 SymbolRoleSet Roles; 121 const Decl *RelatedSymbol; 122 123 SymbolRelation(SymbolRoleSet Roles, const Decl *Sym) 124 : Roles(Roles), RelatedSymbol(Sym) {} 125}; 126 127struct SymbolInfo { 128 SymbolKind Kind; 129 SymbolSubKind SubKind; 130 SymbolPropertySet Properties; 131 SymbolLanguage Lang; 132}; 133 134SymbolInfo getSymbolInfo(const Decl *D); 135 136bool isFunctionLocalSymbol(const Decl *D); 137 138void applyForEachSymbolRole(SymbolRoleSet Roles, 139 llvm::function_ref<void(SymbolRole)> Fn); 140bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, 141 llvm::function_ref<bool(SymbolRole)> Fn); 142void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS); 143 144/// \returns true if no name was printed, false otherwise. 145bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS); 146 147StringRef getSymbolKindString(SymbolKind K); 148StringRef getSymbolSubKindString(SymbolSubKind K); 149StringRef getSymbolLanguageString(SymbolLanguage K); 150 151void applyForEachSymbolProperty(SymbolPropertySet Props, 152 llvm::function_ref<void(SymbolProperty)> Fn); 153void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS); 154 155} // namespace index 156} // namespace clang 157 158#endif 159