Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:56

0001 //===- IndexSymbol.h - Types and functions for indexing symbols -*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H
0010 #define LLVM_CLANG_INDEX_INDEXSYMBOL_H
0011 
0012 #include "clang/Basic/LLVM.h"
0013 #include "clang/Lex/MacroInfo.h"
0014 #include "llvm/ADT/STLExtras.h"
0015 #include "llvm/Support/DataTypes.h"
0016 
0017 namespace clang {
0018   class Decl;
0019   class LangOptions;
0020 
0021 namespace index {
0022 
0023 enum class SymbolKind : uint8_t {
0024   Unknown,
0025 
0026   Module,
0027   Namespace,
0028   NamespaceAlias,
0029   Macro,
0030 
0031   Enum,
0032   Struct,
0033   Class,
0034   Protocol,
0035   Extension,
0036   Union,
0037   TypeAlias,
0038 
0039   Function,
0040   Variable,
0041   Field,
0042   EnumConstant,
0043 
0044   InstanceMethod,
0045   ClassMethod,
0046   StaticMethod,
0047   InstanceProperty,
0048   ClassProperty,
0049   StaticProperty,
0050 
0051   Constructor,
0052   Destructor,
0053   ConversionFunction,
0054 
0055   Parameter,
0056   Using,
0057   TemplateTypeParm,
0058   TemplateTemplateParm,
0059   NonTypeTemplateParm,
0060 
0061   Concept, /// C++20 concept.
0062 };
0063 
0064 enum class SymbolLanguage : uint8_t {
0065   C,
0066   ObjC,
0067   CXX,
0068   Swift,
0069 };
0070 
0071 /// Language specific sub-kinds.
0072 enum class SymbolSubKind : uint8_t {
0073   None,
0074   CXXCopyConstructor,
0075   CXXMoveConstructor,
0076   AccessorGetter,
0077   AccessorSetter,
0078   UsingTypename,
0079   UsingValue,
0080   UsingEnum,
0081 };
0082 
0083 typedef uint16_t SymbolPropertySet;
0084 /// Set of properties that provide additional info about a symbol.
0085 enum class SymbolProperty : SymbolPropertySet {
0086   Generic                       = 1 << 0,
0087   TemplatePartialSpecialization = 1 << 1,
0088   TemplateSpecialization        = 1 << 2,
0089   UnitTest                      = 1 << 3,
0090   IBAnnotated                   = 1 << 4,
0091   IBOutletCollection            = 1 << 5,
0092   GKInspectable                 = 1 << 6,
0093   Local                         = 1 << 7,
0094   /// Symbol is part of a protocol interface.
0095   ProtocolInterface             = 1 << 8,
0096 };
0097 static const unsigned SymbolPropertyBitNum = 9;
0098 
0099 /// Set of roles that are attributed to symbol occurrences.
0100 ///
0101 /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
0102 enum class SymbolRole : uint32_t {
0103   Declaration = 1 << 0,
0104   Definition = 1 << 1,
0105   Reference = 1 << 2,
0106   Read = 1 << 3,
0107   Write = 1 << 4,
0108   Call = 1 << 5,
0109   Dynamic = 1 << 6,
0110   AddressOf = 1 << 7,
0111   Implicit = 1 << 8,
0112   // FIXME: this is not mirrored in CXSymbolRole.
0113   // Note that macro occurrences aren't currently supported in libclang.
0114   Undefinition = 1 << 9, // macro #undef
0115 
0116   // Relation roles.
0117   RelationChildOf = 1 << 10,
0118   RelationBaseOf = 1 << 11,
0119   RelationOverrideOf = 1 << 12,
0120   RelationReceivedBy = 1 << 13,
0121   RelationCalledBy = 1 << 14,
0122   RelationExtendedBy = 1 << 15,
0123   RelationAccessorOf = 1 << 16,
0124   RelationContainedBy = 1 << 17,
0125   RelationIBTypeOf = 1 << 18,
0126   RelationSpecializationOf = 1 << 19,
0127 
0128   // Symbol only references the name of the object as written. For example, a
0129   // constructor references the class declaration using that role.
0130   NameReference = 1 << 20,
0131 };
0132 static const unsigned SymbolRoleBitNum = 21;
0133 typedef unsigned SymbolRoleSet;
0134 
0135 /// Represents a relation to another symbol for a symbol occurrence.
0136 struct SymbolRelation {
0137   SymbolRoleSet Roles;
0138   const Decl *RelatedSymbol;
0139 
0140   SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
0141     : Roles(Roles), RelatedSymbol(Sym) {}
0142 };
0143 
0144 struct SymbolInfo {
0145   SymbolKind Kind;
0146   SymbolSubKind SubKind;
0147   SymbolLanguage Lang;
0148   SymbolPropertySet Properties;
0149 };
0150 
0151 SymbolInfo getSymbolInfo(const Decl *D);
0152 
0153 SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
0154 
0155 bool isFunctionLocalSymbol(const Decl *D);
0156 
0157 void applyForEachSymbolRole(SymbolRoleSet Roles,
0158                             llvm::function_ref<void(SymbolRole)> Fn);
0159 bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
0160                             llvm::function_ref<bool(SymbolRole)> Fn);
0161 void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
0162 
0163 /// \returns true if no name was printed, false otherwise.
0164 bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
0165 
0166 StringRef getSymbolKindString(SymbolKind K);
0167 StringRef getSymbolSubKindString(SymbolSubKind K);
0168 StringRef getSymbolLanguageString(SymbolLanguage K);
0169 
0170 void applyForEachSymbolProperty(SymbolPropertySet Props,
0171                             llvm::function_ref<void(SymbolProperty)> Fn);
0172 void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
0173 
0174 } // namespace index
0175 } // namespace clang
0176 
0177 #endif