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