Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 1 | //===--- IndexSymbol.cpp - Types and functions for indexing symbols -------===// |
| 2 | // |
Chandler Carruth | 324f918 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "clang/Index/IndexSymbol.h" |
| 10 | #include "clang/AST/DeclCXX.h" |
| 11 | #include "clang/AST/DeclObjC.h" |
| 12 | #include "clang/AST/DeclTemplate.h" |
Argyrios Kyrtzidis | 1c8c471 | 2016-02-15 01:32:36 +0000 | [diff] [blame] | 13 | #include "clang/AST/PrettyPrinter.h" |
Eric Liu | 8576df5 | 2018-07-09 08:44:05 +0000 | [diff] [blame] | 14 | #include "clang/Lex/MacroInfo.h" |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace clang; |
| 17 | using namespace clang::index; |
| 18 | |
Argyrios Kyrtzidis | 17e8020 | 2016-04-22 07:21:10 +0000 | [diff] [blame] | 19 | /// \returns true if \c D is a subclass of 'XCTestCase'. |
| 20 | static bool isUnitTestCase(const ObjCInterfaceDecl *D) { |
| 21 | if (!D) |
| 22 | return false; |
| 23 | while (const ObjCInterfaceDecl *SuperD = D->getSuperClass()) { |
| 24 | if (SuperD->getName() == "XCTestCase") |
| 25 | return true; |
| 26 | D = SuperD; |
| 27 | } |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | /// \returns true if \c D is in a subclass of 'XCTestCase', returns void, has |
| 32 | /// no parameters, and its name starts with 'test'. |
| 33 | static bool isUnitTest(const ObjCMethodDecl *D) { |
| 34 | if (!D->parameters().empty()) |
| 35 | return false; |
| 36 | if (!D->getReturnType()->isVoidType()) |
| 37 | return false; |
| 38 | if (!D->getSelector().getNameForSlot(0).startswith("test")) |
| 39 | return false; |
| 40 | return isUnitTestCase(D->getClassInterface()); |
| 41 | } |
| 42 | |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 43 | static void checkForIBOutlets(const Decl *D, SymbolPropertySet &PropSet) { |
Argyrios Kyrtzidis | 9a54e81 | 2016-04-22 07:21:16 +0000 | [diff] [blame] | 44 | if (D->hasAttr<IBOutletAttr>()) { |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 45 | PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated; |
Argyrios Kyrtzidis | 9a54e81 | 2016-04-22 07:21:16 +0000 | [diff] [blame] | 46 | } else if (D->hasAttr<IBOutletCollectionAttr>()) { |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 47 | PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated; |
| 48 | PropSet |= (SymbolPropertySet)SymbolProperty::IBOutletCollection; |
Argyrios Kyrtzidis | 9a54e81 | 2016-04-22 07:21:16 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 52 | bool index::isFunctionLocalSymbol(const Decl *D) { |
| 53 | assert(D); |
| 54 | |
| 55 | if (isa<ParmVarDecl>(D)) |
| 56 | return true; |
| 57 | |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 58 | if (isa<ObjCTypeParamDecl>(D)) |
| 59 | return true; |
| 60 | |
Alex Lorenz | d22768f | 2017-05-22 14:39:39 +0000 | [diff] [blame] | 61 | if (isa<UsingDirectiveDecl>(D)) |
| 62 | return false; |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 63 | if (!D->getParentFunctionOrMethod()) |
| 64 | return false; |
| 65 | |
| 66 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) { |
| 67 | switch (ND->getFormalLinkage()) { |
| 68 | case NoLinkage: |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 69 | case InternalLinkage: |
| 70 | return true; |
Richard Smith | affbdbb | 2017-07-07 20:04:28 +0000 | [diff] [blame] | 71 | case VisibleNoLinkage: |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 72 | case UniqueExternalLinkage: |
Richard Smith | affbdbb | 2017-07-07 20:04:28 +0000 | [diff] [blame] | 73 | case ModuleInternalLinkage: |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 74 | llvm_unreachable("Not a sema linkage"); |
Richard Smith | affbdbb | 2017-07-07 20:04:28 +0000 | [diff] [blame] | 75 | case ModuleLinkage: |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 76 | case ExternalLinkage: |
| 77 | return false; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return true; |
| 82 | } |
| 83 | |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 84 | SymbolInfo index::getSymbolInfo(const Decl *D) { |
| 85 | assert(D); |
| 86 | SymbolInfo Info; |
| 87 | Info.Kind = SymbolKind::Unknown; |
Argyrios Kyrtzidis | c900a4b | 2017-01-08 23:21:35 +0000 | [diff] [blame] | 88 | Info.SubKind = SymbolSubKind::None; |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 89 | Info.Properties = SymbolPropertySet(); |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 90 | Info.Lang = SymbolLanguage::C; |
| 91 | |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 92 | if (isFunctionLocalSymbol(D)) { |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 93 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Local; |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 94 | } |
Argyrios Kyrtzidis | 1e8f9cd | 2018-08-26 06:27:23 +0000 | [diff] [blame] | 95 | if (isa<ObjCProtocolDecl>(D->getDeclContext())) { |
| 96 | Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface; |
| 97 | } |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 98 | |
Ilya Biryukov | 93cc0ae | 2019-05-29 17:49:30 +0000 | [diff] [blame] | 99 | if (auto *VT = dyn_cast<VarTemplateDecl>(D)) { |
| 100 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
| 101 | Info.Lang = SymbolLanguage::CXX; |
| 102 | // All other fields are filled from the templated decl. |
| 103 | D = VT->getTemplatedDecl(); |
| 104 | } |
| 105 | |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 106 | if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 107 | switch (TD->getTagKind()) { |
| 108 | case TTK_Struct: |
| 109 | Info.Kind = SymbolKind::Struct; break; |
| 110 | case TTK_Union: |
| 111 | Info.Kind = SymbolKind::Union; break; |
| 112 | case TTK_Class: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 113 | Info.Kind = SymbolKind::Class; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 114 | Info.Lang = SymbolLanguage::CXX; |
| 115 | break; |
| 116 | case TTK_Interface: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 117 | Info.Kind = SymbolKind::Protocol; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 118 | Info.Lang = SymbolLanguage::CXX; |
| 119 | break; |
| 120 | case TTK_Enum: |
| 121 | Info.Kind = SymbolKind::Enum; break; |
| 122 | } |
| 123 | |
Argyrios Kyrtzidis | cf55f26 | 2016-11-07 21:20:08 +0000 | [diff] [blame] | 124 | if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) { |
| 125 | if (!CXXRec->isCLike()) { |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 126 | Info.Lang = SymbolLanguage::CXX; |
Argyrios Kyrtzidis | cf55f26 | 2016-11-07 21:20:08 +0000 | [diff] [blame] | 127 | if (CXXRec->getDescribedClassTemplate()) { |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 128 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
Argyrios Kyrtzidis | cf55f26 | 2016-11-07 21:20:08 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | } |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 132 | |
| 133 | if (isa<ClassTemplatePartialSpecializationDecl>(D)) { |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 134 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
| 135 | Info.Properties |= |
| 136 | (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 137 | } else if (isa<ClassTemplateSpecializationDecl>(D)) { |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 138 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
| 139 | Info.Properties |= |
| 140 | (SymbolPropertySet)SymbolProperty::TemplateSpecialization; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Argyrios Kyrtzidis | 0e2326e | 2016-11-07 21:20:15 +0000 | [diff] [blame] | 143 | } else if (auto *VD = dyn_cast<VarDecl>(D)) { |
| 144 | Info.Kind = SymbolKind::Variable; |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 145 | if (isa<ParmVarDecl>(D)) { |
| 146 | Info.Kind = SymbolKind::Parameter; |
| 147 | } else if (isa<CXXRecordDecl>(D->getDeclContext())) { |
Argyrios Kyrtzidis | 0e2326e | 2016-11-07 21:20:15 +0000 | [diff] [blame] | 148 | Info.Kind = SymbolKind::StaticProperty; |
| 149 | Info.Lang = SymbolLanguage::CXX; |
| 150 | } |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 151 | |
Argyrios Kyrtzidis | 0e2326e | 2016-11-07 21:20:15 +0000 | [diff] [blame] | 152 | if (isa<VarTemplatePartialSpecializationDecl>(D)) { |
| 153 | Info.Lang = SymbolLanguage::CXX; |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 154 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
| 155 | Info.Properties |= |
| 156 | (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization; |
Argyrios Kyrtzidis | 0e2326e | 2016-11-07 21:20:15 +0000 | [diff] [blame] | 157 | } else if (isa<VarTemplateSpecializationDecl>(D)) { |
| 158 | Info.Lang = SymbolLanguage::CXX; |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 159 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
| 160 | Info.Properties |= |
| 161 | (SymbolPropertySet)SymbolProperty::TemplateSpecialization; |
Argyrios Kyrtzidis | 0e2326e | 2016-11-07 21:20:15 +0000 | [diff] [blame] | 162 | } else if (VD->getDescribedVarTemplate()) { |
| 163 | Info.Lang = SymbolLanguage::CXX; |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 164 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
Argyrios Kyrtzidis | 0e2326e | 2016-11-07 21:20:15 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 167 | } else { |
| 168 | switch (D->getKind()) { |
Argyrios Kyrtzidis | cf6bc2f | 2016-02-29 07:56:07 +0000 | [diff] [blame] | 169 | case Decl::Import: |
| 170 | Info.Kind = SymbolKind::Module; |
| 171 | break; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 172 | case Decl::Typedef: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 173 | Info.Kind = SymbolKind::TypeAlias; break; // Lang = C |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 174 | case Decl::Function: |
| 175 | Info.Kind = SymbolKind::Function; |
| 176 | break; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 177 | case Decl::Field: |
Ilya Biryukov | a77a165 | 2019-05-29 10:11:14 +0000 | [diff] [blame] | 178 | case Decl::IndirectField: |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 179 | Info.Kind = SymbolKind::Field; |
| 180 | if (const CXXRecordDecl * |
| 181 | CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext())) { |
| 182 | if (!CXXRec->isCLike()) |
| 183 | Info.Lang = SymbolLanguage::CXX; |
| 184 | } |
| 185 | break; |
| 186 | case Decl::EnumConstant: |
| 187 | Info.Kind = SymbolKind::EnumConstant; break; |
| 188 | case Decl::ObjCInterface: |
Argyrios Kyrtzidis | 17e8020 | 2016-04-22 07:21:10 +0000 | [diff] [blame] | 189 | case Decl::ObjCImplementation: { |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 190 | Info.Kind = SymbolKind::Class; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 191 | Info.Lang = SymbolLanguage::ObjC; |
Argyrios Kyrtzidis | 17e8020 | 2016-04-22 07:21:10 +0000 | [diff] [blame] | 192 | const ObjCInterfaceDecl *ClsD = dyn_cast<ObjCInterfaceDecl>(D); |
| 193 | if (!ClsD) |
| 194 | ClsD = cast<ObjCImplementationDecl>(D)->getClassInterface(); |
| 195 | if (isUnitTestCase(ClsD)) |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 196 | Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 197 | break; |
Argyrios Kyrtzidis | 17e8020 | 2016-04-22 07:21:10 +0000 | [diff] [blame] | 198 | } |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 199 | case Decl::ObjCProtocol: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 200 | Info.Kind = SymbolKind::Protocol; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 201 | Info.Lang = SymbolLanguage::ObjC; |
| 202 | break; |
| 203 | case Decl::ObjCCategory: |
Argyrios Kyrtzidis | 0bfb9a5 | 2017-03-07 09:38:08 +0000 | [diff] [blame] | 204 | case Decl::ObjCCategoryImpl: { |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 205 | Info.Kind = SymbolKind::Extension; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 206 | Info.Lang = SymbolLanguage::ObjC; |
Argyrios Kyrtzidis | 0bfb9a5 | 2017-03-07 09:38:08 +0000 | [diff] [blame] | 207 | const ObjCInterfaceDecl *ClsD = nullptr; |
| 208 | if (auto *CatD = dyn_cast<ObjCCategoryDecl>(D)) |
| 209 | ClsD = CatD->getClassInterface(); |
| 210 | else |
| 211 | ClsD = cast<ObjCCategoryImplDecl>(D)->getClassInterface(); |
| 212 | if (isUnitTestCase(ClsD)) |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 213 | Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 214 | break; |
Argyrios Kyrtzidis | 0bfb9a5 | 2017-03-07 09:38:08 +0000 | [diff] [blame] | 215 | } |
Ben Langmuir | a50011f | 2017-07-21 23:04:27 +0000 | [diff] [blame] | 216 | case Decl::ObjCMethod: { |
| 217 | const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(D); |
| 218 | Info.Kind = MD->isInstanceMethod() ? SymbolKind::InstanceMethod : SymbolKind::ClassMethod; |
| 219 | if (MD->isPropertyAccessor()) { |
| 220 | if (MD->param_size()) |
| 221 | Info.SubKind = SymbolSubKind::AccessorSetter; |
| 222 | else |
| 223 | Info.SubKind = SymbolSubKind::AccessorGetter; |
Argyrios Kyrtzidis | 4a19ab5 | 2017-01-11 21:42:48 +0000 | [diff] [blame] | 224 | } |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 225 | Info.Lang = SymbolLanguage::ObjC; |
Ben Langmuir | a50011f | 2017-07-21 23:04:27 +0000 | [diff] [blame] | 226 | if (isUnitTest(MD)) |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 227 | Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest; |
Argyrios Kyrtzidis | 9a54e81 | 2016-04-22 07:21:16 +0000 | [diff] [blame] | 228 | if (D->hasAttr<IBActionAttr>()) |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 229 | Info.Properties |= (SymbolPropertySet)SymbolProperty::IBAnnotated; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 230 | break; |
Ben Langmuir | a50011f | 2017-07-21 23:04:27 +0000 | [diff] [blame] | 231 | } |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 232 | case Decl::ObjCProperty: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 233 | Info.Kind = SymbolKind::InstanceProperty; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 234 | Info.Lang = SymbolLanguage::ObjC; |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 235 | checkForIBOutlets(D, Info.Properties); |
Argyrios Kyrtzidis | b5e3c67 | 2016-11-10 23:27:11 +0000 | [diff] [blame] | 236 | if (auto *Annot = D->getAttr<AnnotateAttr>()) { |
| 237 | if (Annot->getAnnotation() == "gk_inspectable") |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 238 | Info.Properties |= (SymbolPropertySet)SymbolProperty::GKInspectable; |
Argyrios Kyrtzidis | b5e3c67 | 2016-11-10 23:27:11 +0000 | [diff] [blame] | 239 | } |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 240 | break; |
| 241 | case Decl::ObjCIvar: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 242 | Info.Kind = SymbolKind::Field; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 243 | Info.Lang = SymbolLanguage::ObjC; |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 244 | checkForIBOutlets(D, Info.Properties); |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 245 | break; |
| 246 | case Decl::Namespace: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 247 | Info.Kind = SymbolKind::Namespace; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 248 | Info.Lang = SymbolLanguage::CXX; |
| 249 | break; |
| 250 | case Decl::NamespaceAlias: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 251 | Info.Kind = SymbolKind::NamespaceAlias; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 252 | Info.Lang = SymbolLanguage::CXX; |
| 253 | break; |
Argyrios Kyrtzidis | c900a4b | 2017-01-08 23:21:35 +0000 | [diff] [blame] | 254 | case Decl::CXXConstructor: { |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 255 | Info.Kind = SymbolKind::Constructor; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 256 | Info.Lang = SymbolLanguage::CXX; |
Argyrios Kyrtzidis | c900a4b | 2017-01-08 23:21:35 +0000 | [diff] [blame] | 257 | auto *CD = cast<CXXConstructorDecl>(D); |
| 258 | if (CD->isCopyConstructor()) |
| 259 | Info.SubKind = SymbolSubKind::CXXCopyConstructor; |
| 260 | else if (CD->isMoveConstructor()) |
| 261 | Info.SubKind = SymbolSubKind::CXXMoveConstructor; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 262 | break; |
Argyrios Kyrtzidis | c900a4b | 2017-01-08 23:21:35 +0000 | [diff] [blame] | 263 | } |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 264 | case Decl::CXXDestructor: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 265 | Info.Kind = SymbolKind::Destructor; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 266 | Info.Lang = SymbolLanguage::CXX; |
| 267 | break; |
| 268 | case Decl::CXXConversion: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 269 | Info.Kind = SymbolKind::ConversionFunction; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 270 | Info.Lang = SymbolLanguage::CXX; |
| 271 | break; |
| 272 | case Decl::CXXMethod: { |
| 273 | const CXXMethodDecl *MD = cast<CXXMethodDecl>(D); |
| 274 | if (MD->isStatic()) |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 275 | Info.Kind = SymbolKind::StaticMethod; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 276 | else |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 277 | Info.Kind = SymbolKind::InstanceMethod; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 278 | Info.Lang = SymbolLanguage::CXX; |
| 279 | break; |
| 280 | } |
| 281 | case Decl::ClassTemplate: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 282 | Info.Kind = SymbolKind::Class; |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 283 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 284 | Info.Lang = SymbolLanguage::CXX; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 285 | break; |
| 286 | case Decl::FunctionTemplate: |
| 287 | Info.Kind = SymbolKind::Function; |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 288 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 289 | Info.Lang = SymbolLanguage::CXX; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 290 | if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>( |
| 291 | cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) { |
| 292 | if (isa<CXXConstructorDecl>(MD)) |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 293 | Info.Kind = SymbolKind::Constructor; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 294 | else if (isa<CXXDestructorDecl>(MD)) |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 295 | Info.Kind = SymbolKind::Destructor; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 296 | else if (isa<CXXConversionDecl>(MD)) |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 297 | Info.Kind = SymbolKind::ConversionFunction; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 298 | else { |
| 299 | if (MD->isStatic()) |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 300 | Info.Kind = SymbolKind::StaticMethod; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 301 | else |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 302 | Info.Kind = SymbolKind::InstanceMethod; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | break; |
| 306 | case Decl::TypeAliasTemplate: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 307 | Info.Kind = SymbolKind::TypeAlias; |
| 308 | Info.Lang = SymbolLanguage::CXX; |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 309 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 310 | break; |
| 311 | case Decl::TypeAlias: |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 312 | Info.Kind = SymbolKind::TypeAlias; |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 313 | Info.Lang = SymbolLanguage::CXX; |
| 314 | break; |
Ben Langmuir | 1cfec5f | 2017-08-16 23:12:21 +0000 | [diff] [blame] | 315 | case Decl::UnresolvedUsingTypename: |
| 316 | Info.Kind = SymbolKind::Using; |
| 317 | Info.SubKind = SymbolSubKind::UsingTypename; |
| 318 | Info.Lang = SymbolLanguage::CXX; |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 319 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
Ben Langmuir | 1cfec5f | 2017-08-16 23:12:21 +0000 | [diff] [blame] | 320 | break; |
| 321 | case Decl::UnresolvedUsingValue: |
| 322 | Info.Kind = SymbolKind::Using; |
| 323 | Info.SubKind = SymbolSubKind::UsingValue; |
| 324 | Info.Lang = SymbolLanguage::CXX; |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 325 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
Ben Langmuir | 1cfec5f | 2017-08-16 23:12:21 +0000 | [diff] [blame] | 326 | break; |
Kadir Cetinkaya | 1540b2e | 2019-02-26 14:23:12 +0000 | [diff] [blame] | 327 | case Decl::Using: |
| 328 | Info.Kind = SymbolKind::Using; |
| 329 | Info.Lang = SymbolLanguage::CXX; |
| 330 | break; |
Alex Lorenz | 4d2e73a | 2017-06-15 21:19:01 +0000 | [diff] [blame] | 331 | case Decl::Binding: |
| 332 | Info.Kind = SymbolKind::Variable; |
| 333 | Info.Lang = SymbolLanguage::CXX; |
| 334 | break; |
Volodymyr Sapsai | 33184f7 | 2019-02-27 01:04:53 +0000 | [diff] [blame] | 335 | case Decl::MSProperty: |
| 336 | Info.Kind = SymbolKind::InstanceProperty; |
| 337 | if (const CXXRecordDecl *CXXRec = |
| 338 | dyn_cast<CXXRecordDecl>(D->getDeclContext())) { |
| 339 | if (!CXXRec->isCLike()) |
| 340 | Info.Lang = SymbolLanguage::CXX; |
| 341 | } |
| 342 | break; |
Ilya Biryukov | 93cc0ae | 2019-05-29 17:49:30 +0000 | [diff] [blame] | 343 | case Decl::ClassTemplatePartialSpecialization: |
| 344 | case Decl::ClassScopeFunctionSpecialization: |
| 345 | case Decl::ClassTemplateSpecialization: |
| 346 | case Decl::CXXRecord: |
| 347 | case Decl::Enum: |
| 348 | case Decl::Record: |
| 349 | llvm_unreachable("records handled before"); |
| 350 | break; |
| 351 | case Decl::VarTemplateSpecialization: |
| 352 | case Decl::VarTemplatePartialSpecialization: |
| 353 | case Decl::ImplicitParam: |
| 354 | case Decl::ParmVar: |
| 355 | case Decl::Var: |
| 356 | case Decl::VarTemplate: |
| 357 | llvm_unreachable("variables handled before"); |
| 358 | break; |
| 359 | // Other decls get the 'unknown' kind. |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 360 | default: |
| 361 | break; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | if (Info.Kind == SymbolKind::Unknown) |
| 366 | return Info; |
| 367 | |
| 368 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 369 | if (FD->getTemplatedKind() == |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 370 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 371 | Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; |
| 372 | Info.Properties |= |
| 373 | (SymbolPropertySet)SymbolProperty::TemplateSpecialization; |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 374 | } |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 377 | if (Info.Properties & (SymbolPropertySet)SymbolProperty::Generic) |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 378 | Info.Lang = SymbolLanguage::CXX; |
| 379 | |
Argyrios Kyrtzidis | 088eaf5 | 2017-05-20 04:11:33 +0000 | [diff] [blame] | 380 | if (auto *attr = D->getExternalSourceSymbolAttr()) { |
Argyrios Kyrtzidis | 8f2ae42 | 2017-04-24 14:52:00 +0000 | [diff] [blame] | 381 | if (attr->getLanguage() == "Swift") |
| 382 | Info.Lang = SymbolLanguage::Swift; |
| 383 | } |
| 384 | |
Argyrios Kyrtzidis | 754b721 | 2016-02-12 23:10:59 +0000 | [diff] [blame] | 385 | return Info; |
| 386 | } |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 387 | |
Eric Liu | 8576df5 | 2018-07-09 08:44:05 +0000 | [diff] [blame] | 388 | SymbolInfo index::getSymbolInfoForMacro(const MacroInfo &) { |
| 389 | SymbolInfo Info; |
| 390 | Info.Kind = SymbolKind::Macro; |
| 391 | Info.SubKind = SymbolSubKind::None; |
| 392 | Info.Properties = SymbolPropertySet(); |
| 393 | Info.Lang = SymbolLanguage::C; |
| 394 | return Info; |
| 395 | } |
| 396 | |
Argyrios Kyrtzidis | 53160ec | 2017-03-23 16:34:47 +0000 | [diff] [blame] | 397 | bool index::applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, |
| 398 | llvm::function_ref<bool(SymbolRole)> Fn) { |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 399 | #define APPLY_FOR_ROLE(Role) \ |
| 400 | if (Roles & (unsigned)SymbolRole::Role) \ |
Argyrios Kyrtzidis | 53160ec | 2017-03-23 16:34:47 +0000 | [diff] [blame] | 401 | if (!Fn(SymbolRole::Role)) \ |
| 402 | return false; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 403 | |
| 404 | APPLY_FOR_ROLE(Declaration); |
| 405 | APPLY_FOR_ROLE(Definition); |
| 406 | APPLY_FOR_ROLE(Reference); |
| 407 | APPLY_FOR_ROLE(Read); |
| 408 | APPLY_FOR_ROLE(Write); |
| 409 | APPLY_FOR_ROLE(Call); |
| 410 | APPLY_FOR_ROLE(Dynamic); |
| 411 | APPLY_FOR_ROLE(AddressOf); |
| 412 | APPLY_FOR_ROLE(Implicit); |
Eric Liu | 8576df5 | 2018-07-09 08:44:05 +0000 | [diff] [blame] | 413 | APPLY_FOR_ROLE(Undefinition); |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 414 | APPLY_FOR_ROLE(RelationChildOf); |
| 415 | APPLY_FOR_ROLE(RelationBaseOf); |
| 416 | APPLY_FOR_ROLE(RelationOverrideOf); |
| 417 | APPLY_FOR_ROLE(RelationReceivedBy); |
Argyrios Kyrtzidis | 46f43fd | 2016-02-29 07:56:00 +0000 | [diff] [blame] | 418 | APPLY_FOR_ROLE(RelationCalledBy); |
Argyrios Kyrtzidis | 5692230 | 2016-10-25 21:11:22 +0000 | [diff] [blame] | 419 | APPLY_FOR_ROLE(RelationExtendedBy); |
| 420 | APPLY_FOR_ROLE(RelationAccessorOf); |
Argyrios Kyrtzidis | 231cda6 | 2017-01-11 20:51:10 +0000 | [diff] [blame] | 421 | APPLY_FOR_ROLE(RelationContainedBy); |
Argyrios Kyrtzidis | 8293248 | 2017-01-11 21:01:07 +0000 | [diff] [blame] | 422 | APPLY_FOR_ROLE(RelationIBTypeOf); |
Alex Lorenz | 59a0c5e | 2017-04-20 10:43:22 +0000 | [diff] [blame] | 423 | APPLY_FOR_ROLE(RelationSpecializationOf); |
Kadir Cetinkaya | 87becae | 2019-03-08 08:30:20 +0000 | [diff] [blame] | 424 | APPLY_FOR_ROLE(NameReference); |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 425 | |
| 426 | #undef APPLY_FOR_ROLE |
Argyrios Kyrtzidis | 53160ec | 2017-03-23 16:34:47 +0000 | [diff] [blame] | 427 | |
| 428 | return true; |
| 429 | } |
| 430 | |
| 431 | void index::applyForEachSymbolRole(SymbolRoleSet Roles, |
| 432 | llvm::function_ref<void(SymbolRole)> Fn) { |
| 433 | applyForEachSymbolRoleInterruptible(Roles, [&](SymbolRole r) -> bool { |
| 434 | Fn(r); |
| 435 | return true; |
| 436 | }); |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | void index::printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS) { |
| 440 | bool VisitedOnce = false; |
| 441 | applyForEachSymbolRole(Roles, [&](SymbolRole Role) { |
| 442 | if (VisitedOnce) |
Argyrios Kyrtzidis | 340ce98 | 2016-02-29 07:55:51 +0000 | [diff] [blame] | 443 | OS << ','; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 444 | else |
| 445 | VisitedOnce = true; |
| 446 | switch (Role) { |
| 447 | case SymbolRole::Declaration: OS << "Decl"; break; |
| 448 | case SymbolRole::Definition: OS << "Def"; break; |
| 449 | case SymbolRole::Reference: OS << "Ref"; break; |
| 450 | case SymbolRole::Read: OS << "Read"; break; |
| 451 | case SymbolRole::Write: OS << "Writ"; break; |
| 452 | case SymbolRole::Call: OS << "Call"; break; |
| 453 | case SymbolRole::Dynamic: OS << "Dyn"; break; |
| 454 | case SymbolRole::AddressOf: OS << "Addr"; break; |
| 455 | case SymbolRole::Implicit: OS << "Impl"; break; |
Eric Liu | 8576df5 | 2018-07-09 08:44:05 +0000 | [diff] [blame] | 456 | case SymbolRole::Undefinition: OS << "Undef"; break; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 457 | case SymbolRole::RelationChildOf: OS << "RelChild"; break; |
| 458 | case SymbolRole::RelationBaseOf: OS << "RelBase"; break; |
| 459 | case SymbolRole::RelationOverrideOf: OS << "RelOver"; break; |
| 460 | case SymbolRole::RelationReceivedBy: OS << "RelRec"; break; |
Argyrios Kyrtzidis | 46f43fd | 2016-02-29 07:56:00 +0000 | [diff] [blame] | 461 | case SymbolRole::RelationCalledBy: OS << "RelCall"; break; |
Argyrios Kyrtzidis | 5692230 | 2016-10-25 21:11:22 +0000 | [diff] [blame] | 462 | case SymbolRole::RelationExtendedBy: OS << "RelExt"; break; |
| 463 | case SymbolRole::RelationAccessorOf: OS << "RelAcc"; break; |
Argyrios Kyrtzidis | 231cda6 | 2017-01-11 20:51:10 +0000 | [diff] [blame] | 464 | case SymbolRole::RelationContainedBy: OS << "RelCont"; break; |
Argyrios Kyrtzidis | 8293248 | 2017-01-11 21:01:07 +0000 | [diff] [blame] | 465 | case SymbolRole::RelationIBTypeOf: OS << "RelIBType"; break; |
Alex Lorenz | 59a0c5e | 2017-04-20 10:43:22 +0000 | [diff] [blame] | 466 | case SymbolRole::RelationSpecializationOf: OS << "RelSpecialization"; break; |
Kadir Cetinkaya | 87becae | 2019-03-08 08:30:20 +0000 | [diff] [blame] | 467 | case SymbolRole::NameReference: OS << "NameReference"; break; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 468 | } |
| 469 | }); |
| 470 | } |
| 471 | |
Argyrios Kyrtzidis | 1c8c471 | 2016-02-15 01:32:36 +0000 | [diff] [blame] | 472 | bool index::printSymbolName(const Decl *D, const LangOptions &LO, |
| 473 | raw_ostream &OS) { |
| 474 | if (auto *ND = dyn_cast<NamedDecl>(D)) { |
| 475 | PrintingPolicy Policy(LO); |
| 476 | // Forward references can have different template argument names. Suppress |
| 477 | // the template argument names in constructors to make their name more |
| 478 | // stable. |
| 479 | Policy.SuppressTemplateArgsInCXXConstructors = true; |
| 480 | DeclarationName DeclName = ND->getDeclName(); |
| 481 | if (DeclName.isEmpty()) |
| 482 | return true; |
| 483 | DeclName.print(OS, Policy); |
| 484 | return false; |
| 485 | } else { |
| 486 | return true; |
| 487 | } |
| 488 | } |
| 489 | |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 490 | StringRef index::getSymbolKindString(SymbolKind K) { |
| 491 | switch (K) { |
| 492 | case SymbolKind::Unknown: return "<unknown>"; |
| 493 | case SymbolKind::Module: return "module"; |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 494 | case SymbolKind::Namespace: return "namespace"; |
| 495 | case SymbolKind::NamespaceAlias: return "namespace-alias"; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 496 | case SymbolKind::Macro: return "macro"; |
| 497 | case SymbolKind::Enum: return "enum"; |
| 498 | case SymbolKind::Struct: return "struct"; |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 499 | case SymbolKind::Class: return "class"; |
| 500 | case SymbolKind::Protocol: return "protocol"; |
| 501 | case SymbolKind::Extension: return "extension"; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 502 | case SymbolKind::Union: return "union"; |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 503 | case SymbolKind::TypeAlias: return "type-alias"; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 504 | case SymbolKind::Function: return "function"; |
| 505 | case SymbolKind::Variable: return "variable"; |
| 506 | case SymbolKind::Field: return "field"; |
| 507 | case SymbolKind::EnumConstant: return "enumerator"; |
Ben Langmuir | eacdb14 | 2016-03-25 17:01:59 +0000 | [diff] [blame] | 508 | case SymbolKind::InstanceMethod: return "instance-method"; |
| 509 | case SymbolKind::ClassMethod: return "class-method"; |
| 510 | case SymbolKind::StaticMethod: return "static-method"; |
| 511 | case SymbolKind::InstanceProperty: return "instance-property"; |
| 512 | case SymbolKind::ClassProperty: return "class-property"; |
| 513 | case SymbolKind::StaticProperty: return "static-property"; |
| 514 | case SymbolKind::Constructor: return "constructor"; |
| 515 | case SymbolKind::Destructor: return "destructor"; |
Jan Korous | 84cc1b7 | 2019-07-23 16:54:11 +0000 | [diff] [blame] | 516 | case SymbolKind::ConversionFunction: return "conversion-func"; |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 517 | case SymbolKind::Parameter: return "param"; |
Ben Langmuir | 1cfec5f | 2017-08-16 23:12:21 +0000 | [diff] [blame] | 518 | case SymbolKind::Using: return "using"; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 519 | } |
Saleem Abdulrasool | 73a2603 | 2016-02-15 00:36:52 +0000 | [diff] [blame] | 520 | llvm_unreachable("invalid symbol kind"); |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Argyrios Kyrtzidis | c900a4b | 2017-01-08 23:21:35 +0000 | [diff] [blame] | 523 | StringRef index::getSymbolSubKindString(SymbolSubKind K) { |
| 524 | switch (K) { |
| 525 | case SymbolSubKind::None: return "<none>"; |
| 526 | case SymbolSubKind::CXXCopyConstructor: return "cxx-copy-ctor"; |
| 527 | case SymbolSubKind::CXXMoveConstructor: return "cxx-move-ctor"; |
Argyrios Kyrtzidis | 4a19ab5 | 2017-01-11 21:42:48 +0000 | [diff] [blame] | 528 | case SymbolSubKind::AccessorGetter: return "acc-get"; |
| 529 | case SymbolSubKind::AccessorSetter: return "acc-set"; |
Ben Langmuir | 1cfec5f | 2017-08-16 23:12:21 +0000 | [diff] [blame] | 530 | case SymbolSubKind::UsingTypename: return "using-typename"; |
| 531 | case SymbolSubKind::UsingValue: return "using-value"; |
Argyrios Kyrtzidis | c900a4b | 2017-01-08 23:21:35 +0000 | [diff] [blame] | 532 | } |
| 533 | llvm_unreachable("invalid symbol subkind"); |
| 534 | } |
| 535 | |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 536 | StringRef index::getSymbolLanguageString(SymbolLanguage K) { |
| 537 | switch (K) { |
| 538 | case SymbolLanguage::C: return "C"; |
| 539 | case SymbolLanguage::ObjC: return "ObjC"; |
| 540 | case SymbolLanguage::CXX: return "C++"; |
Argyrios Kyrtzidis | 8f2ae42 | 2017-04-24 14:52:00 +0000 | [diff] [blame] | 541 | case SymbolLanguage::Swift: return "Swift"; |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 542 | } |
Saleem Abdulrasool | 73a2603 | 2016-02-15 00:36:52 +0000 | [diff] [blame] | 543 | llvm_unreachable("invalid symbol language kind"); |
Argyrios Kyrtzidis | 4d8332a | 2016-02-14 06:39:11 +0000 | [diff] [blame] | 544 | } |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 545 | |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 546 | void index::applyForEachSymbolProperty(SymbolPropertySet Props, |
| 547 | llvm::function_ref<void(SymbolProperty)> Fn) { |
Sam McCall | 48fa9ac | 2017-12-23 19:31:24 +0000 | [diff] [blame] | 548 | #define APPLY_FOR_PROPERTY(K) \ |
| 549 | if (Props & (SymbolPropertySet)SymbolProperty::K) \ |
| 550 | Fn(SymbolProperty::K) |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 551 | |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 552 | APPLY_FOR_PROPERTY(Generic); |
| 553 | APPLY_FOR_PROPERTY(TemplatePartialSpecialization); |
| 554 | APPLY_FOR_PROPERTY(TemplateSpecialization); |
| 555 | APPLY_FOR_PROPERTY(UnitTest); |
| 556 | APPLY_FOR_PROPERTY(IBAnnotated); |
| 557 | APPLY_FOR_PROPERTY(IBOutletCollection); |
| 558 | APPLY_FOR_PROPERTY(GKInspectable); |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 559 | APPLY_FOR_PROPERTY(Local); |
Argyrios Kyrtzidis | 1e8f9cd | 2018-08-26 06:27:23 +0000 | [diff] [blame] | 560 | APPLY_FOR_PROPERTY(ProtocolInterface); |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 561 | |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 562 | #undef APPLY_FOR_PROPERTY |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 565 | void index::printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS) { |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 566 | bool VisitedOnce = false; |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 567 | applyForEachSymbolProperty(Props, [&](SymbolProperty Prop) { |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 568 | if (VisitedOnce) |
| 569 | OS << ','; |
| 570 | else |
| 571 | VisitedOnce = true; |
Argyrios Kyrtzidis | 0e0e98c | 2016-11-11 23:49:55 +0000 | [diff] [blame] | 572 | switch (Prop) { |
| 573 | case SymbolProperty::Generic: OS << "Gen"; break; |
| 574 | case SymbolProperty::TemplatePartialSpecialization: OS << "TPS"; break; |
| 575 | case SymbolProperty::TemplateSpecialization: OS << "TS"; break; |
| 576 | case SymbolProperty::UnitTest: OS << "test"; break; |
| 577 | case SymbolProperty::IBAnnotated: OS << "IB"; break; |
| 578 | case SymbolProperty::IBOutletCollection: OS << "IBColl"; break; |
| 579 | case SymbolProperty::GKInspectable: OS << "GKI"; break; |
Argyrios Kyrtzidis | 1d680d2 | 2017-02-26 05:37:56 +0000 | [diff] [blame] | 580 | case SymbolProperty::Local: OS << "local"; break; |
Argyrios Kyrtzidis | 1e8f9cd | 2018-08-26 06:27:23 +0000 | [diff] [blame] | 581 | case SymbolProperty::ProtocolInterface: OS << "protocol"; break; |
Argyrios Kyrtzidis | a0cb91f | 2016-04-22 07:21:04 +0000 | [diff] [blame] | 582 | } |
| 583 | }); |
| 584 | } |