IndexSymbol.h revision 355940
138786Sdfr//===- IndexSymbol.h - Types and functions for indexing symbols -*- C++ -*-===// 238786Sdfr// 338786Sdfr// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 438786Sdfr// See https://llvm.org/LICENSE.txt for license information. 538786Sdfr// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 638786Sdfr// 738786Sdfr//===----------------------------------------------------------------------===// 838786Sdfr 938786Sdfr#ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H 1038786Sdfr#define LLVM_CLANG_INDEX_INDEXSYMBOL_H 1138786Sdfr 1238786Sdfr#include "clang/Basic/LLVM.h" 1338786Sdfr#include "clang/Lex/MacroInfo.h" 1438786Sdfr#include "llvm/ADT/STLExtras.h" 1538786Sdfr#include "llvm/Support/DataTypes.h" 1638786Sdfr 1738786Sdfrnamespace clang { 1838786Sdfr class Decl; 1938786Sdfr class LangOptions; 2038786Sdfr 2138786Sdfrnamespace index { 2238786Sdfr 2338786Sdfrenum class SymbolKind : uint8_t { 2438786Sdfr Unknown, 2538786Sdfr 2638786Sdfr Module, 2738786Sdfr Namespace, 2838786Sdfr NamespaceAlias, 2950476Speter Macro, 3038786Sdfr 3138786Sdfr Enum, 3249831Smpp Struct, 3379538Sru Class, 3438786Sdfr Protocol, 3538786Sdfr Extension, 3638786Sdfr Union, 3738786Sdfr TypeAlias, 3884306Sru 3984306Sru Function, 4038786Sdfr Variable, 4138786Sdfr Field, 4238786Sdfr EnumConstant, 4338786Sdfr 44121380Shmp InstanceMethod, 45121380Shmp ClassMethod, 4638786Sdfr StaticMethod, 4738786Sdfr InstanceProperty, 4838786Sdfr ClassProperty, 4938786Sdfr StaticProperty, 5038786Sdfr 5138786Sdfr Constructor, 5238786Sdfr Destructor, 5338786Sdfr ConversionFunction, 5438786Sdfr 5538786Sdfr Parameter, 5638786Sdfr Using, 5738786Sdfr}; 5838786Sdfr 5938786Sdfrenum class SymbolLanguage : uint8_t { 60121414Shmp C, 6138786Sdfr ObjC, 62 CXX, 63 Swift, 64}; 65 66/// Language specific sub-kinds. 67enum class SymbolSubKind : uint8_t { 68 None, 69 CXXCopyConstructor, 70 CXXMoveConstructor, 71 AccessorGetter, 72 AccessorSetter, 73 UsingTypename, 74 UsingValue, 75}; 76 77typedef uint16_t SymbolPropertySet; 78/// Set of properties that provide additional info about a symbol. 79enum class SymbolProperty : SymbolPropertySet { 80 Generic = 1 << 0, 81 TemplatePartialSpecialization = 1 << 1, 82 TemplateSpecialization = 1 << 2, 83 UnitTest = 1 << 3, 84 IBAnnotated = 1 << 4, 85 IBOutletCollection = 1 << 5, 86 GKInspectable = 1 << 6, 87 Local = 1 << 7, 88 /// Symbol is part of a protocol interface. 89 ProtocolInterface = 1 << 8, 90}; 91static const unsigned SymbolPropertyBitNum = 9; 92 93/// Set of roles that are attributed to symbol occurrences. 94/// 95/// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum. 96enum class SymbolRole : uint32_t { 97 Declaration = 1 << 0, 98 Definition = 1 << 1, 99 Reference = 1 << 2, 100 Read = 1 << 3, 101 Write = 1 << 4, 102 Call = 1 << 5, 103 Dynamic = 1 << 6, 104 AddressOf = 1 << 7, 105 Implicit = 1 << 8, 106 // FIXME: this is not mirrored in CXSymbolRole. 107 // Note that macro occurrences aren't currently supported in libclang. 108 Undefinition = 1 << 9, // macro #undef 109 110 // Relation roles. 111 RelationChildOf = 1 << 10, 112 RelationBaseOf = 1 << 11, 113 RelationOverrideOf = 1 << 12, 114 RelationReceivedBy = 1 << 13, 115 RelationCalledBy = 1 << 14, 116 RelationExtendedBy = 1 << 15, 117 RelationAccessorOf = 1 << 16, 118 RelationContainedBy = 1 << 17, 119 RelationIBTypeOf = 1 << 18, 120 RelationSpecializationOf = 1 << 19, 121 122 // Symbol only references the name of the object as written. For example, a 123 // constructor references the class declaration using that role. 124 NameReference = 1 << 20, 125}; 126static const unsigned SymbolRoleBitNum = 21; 127typedef unsigned SymbolRoleSet; 128 129/// Represents a relation to another symbol for a symbol occurrence. 130struct SymbolRelation { 131 SymbolRoleSet Roles; 132 const Decl *RelatedSymbol; 133 134 SymbolRelation(SymbolRoleSet Roles, const Decl *Sym) 135 : Roles(Roles), RelatedSymbol(Sym) {} 136}; 137 138struct SymbolInfo { 139 SymbolKind Kind; 140 SymbolSubKind SubKind; 141 SymbolLanguage Lang; 142 SymbolPropertySet Properties; 143}; 144 145SymbolInfo getSymbolInfo(const Decl *D); 146 147SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI); 148 149bool isFunctionLocalSymbol(const Decl *D); 150 151void applyForEachSymbolRole(SymbolRoleSet Roles, 152 llvm::function_ref<void(SymbolRole)> Fn); 153bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, 154 llvm::function_ref<bool(SymbolRole)> Fn); 155void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS); 156 157/// \returns true if no name was printed, false otherwise. 158bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS); 159 160StringRef getSymbolKindString(SymbolKind K); 161StringRef getSymbolSubKindString(SymbolSubKind K); 162StringRef getSymbolLanguageString(SymbolLanguage K); 163 164void applyForEachSymbolProperty(SymbolPropertySet Props, 165 llvm::function_ref<void(SymbolProperty)> Fn); 166void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS); 167 168} // namespace index 169} // namespace clang 170 171#endif 172