clang: lib/Index/IndexSymbol.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

16

17using namespace clang;

19

20

22 if (D)

23 return false;

25 if (SuperD->getName() == "XCTestCase")

26 return true;

27 D = SuperD;

28 }

29 return false;

30}

31

32

33

35 if (D->parameters().empty())

36 return false;

37 if (D->getReturnType()->isVoidType())

38 return false;

39 if (D->getSelector().getNameForSlot(0).starts_with("test"))

40 return false;

42}

43

45 if (D->hasAttr()) {

47 } else if (D->hasAttr()) {

50 }

51}

52

54 assert(D);

55

56 if (isa(D))

57 return true;

58

59 if (isa(D))

60 return true;

61

62 if (isa(D))

63 return false;

65 return false;

66

67 if (const NamedDecl *ND = dyn_cast(D)) {

68 switch (ND->getFormalLinkage()) {

69 case Linkage::Invalid:

70 llvm_unreachable("Linkage hasn't been computed!");

71 case Linkage::None:

72 case Linkage::Internal:

73 return true;

74 case Linkage::VisibleNone:

75 case Linkage::UniqueExternal:

76 llvm_unreachable("Not a sema linkage");

77 case Linkage::Module:

78 case Linkage::External:

79 return false;

80 }

81 }

82

83 return true;

84}

85

87 assert(D);

89 Info.Kind = SymbolKind::Unknown;

90 Info.SubKind = SymbolSubKind::None;

92 Info.Lang = SymbolLanguage::C;

93

96 }

99 }

100

101 if (auto *VT = dyn_cast(D)) {

103 Info.Lang = SymbolLanguage::CXX;

104

105 D = VT->getTemplatedDecl();

106 }

107

108 if (const TagDecl *TD = dyn_cast(D)) {

109 switch (TD->getTagKind()) {

110 case TagTypeKind::Struct:

111 Info.Kind = SymbolKind::Struct; break;

112 case TagTypeKind::Union:

113 Info.Kind = SymbolKind::Union; break;

114 case TagTypeKind::Class:

115 Info.Kind = SymbolKind::Class;

116 Info.Lang = SymbolLanguage::CXX;

117 break;

118 case TagTypeKind::Interface:

119 Info.Kind = SymbolKind::Protocol;

120 Info.Lang = SymbolLanguage::CXX;

121 break;

122 case TagTypeKind::Enum:

123 Info.Kind = SymbolKind::Enum; break;

124 }

125

126 if (const CXXRecordDecl *CXXRec = dyn_cast(D)) {

127 if (!CXXRec->isCLike()) {

128 Info.Lang = SymbolLanguage::CXX;

129 if (CXXRec->getDescribedClassTemplate()) {

131 }

132 }

133 }

134

135 if (isa(D)) {

138 (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization;

139 } else if (isa(D)) {

143 }

144

145 } else if (auto *VD = dyn_cast(D)) {

146 Info.Kind = SymbolKind::Variable;

147 if (isa(D)) {

148 Info.Kind = SymbolKind::Parameter;

150 Info.Kind = SymbolKind::StaticProperty;

151 Info.Lang = SymbolLanguage::CXX;

152 }

153

154 if (isa(D)) {

155 Info.Lang = SymbolLanguage::CXX;

158 (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization;

159 } else if (isa(D)) {

160 Info.Lang = SymbolLanguage::CXX;

164 } else if (VD->getDescribedVarTemplate()) {

165 Info.Lang = SymbolLanguage::CXX;

167 }

168

169 } else {

171 case Decl::Import:

172 Info.Kind = SymbolKind::Module;

173 break;

174 case Decl::Typedef:

175 Info.Kind = SymbolKind::TypeAlias; break;

176 case Decl::Function:

177 Info.Kind = SymbolKind::Function;

178 break;

179 case Decl::Field:

180 case Decl::IndirectField:

181 Info.Kind = SymbolKind::Field;

184 if (!CXXRec->isCLike())

185 Info.Lang = SymbolLanguage::CXX;

186 }

187 break;

188 case Decl::EnumConstant:

189 Info.Kind = SymbolKind::EnumConstant; break;

190 case Decl::ObjCInterface:

191 case Decl::ObjCImplementation: {

192 Info.Kind = SymbolKind::Class;

193 Info.Lang = SymbolLanguage::ObjC;

195 if (!ClsD)

196 ClsD = cast(D)->getClassInterface();

199 break;

200 }

201 case Decl::ObjCProtocol:

202 Info.Kind = SymbolKind::Protocol;

203 Info.Lang = SymbolLanguage::ObjC;

204 break;

205 case Decl::ObjCCategory:

206 case Decl::ObjCCategoryImpl: {

207 Info.Kind = SymbolKind::Extension;

208 Info.Lang = SymbolLanguage::ObjC;

210 if (auto *CatD = dyn_cast(D))

211 ClsD = CatD->getClassInterface();

212 else

213 ClsD = cast(D)->getClassInterface();

216 break;

217 }

218 case Decl::ObjCMethod: {

220 Info.Kind = MD->isInstanceMethod() ? SymbolKind::InstanceMethod : SymbolKind::ClassMethod;

223 Info.SubKind = SymbolSubKind::AccessorSetter;

224 else

225 Info.SubKind = SymbolSubKind::AccessorGetter;

226 }

227 Info.Lang = SymbolLanguage::ObjC;

230 if (D->hasAttr())

232 break;

233 }

234 case Decl::ObjCProperty:

235 Info.Kind = SymbolKind::InstanceProperty;

236 Info.Lang = SymbolLanguage::ObjC;

238 if (auto *Annot = D->getAttr()) {

239 if (Annot->getAnnotation() == "gk_inspectable")

241 }

242 break;

243 case Decl::ObjCIvar:

244 Info.Kind = SymbolKind::Field;

245 Info.Lang = SymbolLanguage::ObjC;

247 break;

248 case Decl::Namespace:

249 Info.Kind = SymbolKind::Namespace;

250 Info.Lang = SymbolLanguage::CXX;

251 break;

252 case Decl::NamespaceAlias:

253 Info.Kind = SymbolKind::NamespaceAlias;

254 Info.Lang = SymbolLanguage::CXX;

255 break;

256 case Decl::CXXConstructor: {

257 Info.Kind = SymbolKind::Constructor;

258 Info.Lang = SymbolLanguage::CXX;

259 auto *CD = cast(D);

260 if (CD->isCopyConstructor())

261 Info.SubKind = SymbolSubKind::CXXCopyConstructor;

262 else if (CD->isMoveConstructor())

263 Info.SubKind = SymbolSubKind::CXXMoveConstructor;

264 break;

265 }

266 case Decl::CXXDestructor:

267 Info.Kind = SymbolKind::Destructor;

268 Info.Lang = SymbolLanguage::CXX;

269 break;

270 case Decl::CXXConversion:

271 Info.Kind = SymbolKind::ConversionFunction;

272 Info.Lang = SymbolLanguage::CXX;

273 break;

274 case Decl::CXXMethod: {

277 Info.Kind = SymbolKind::StaticMethod;

278 else

279 Info.Kind = SymbolKind::InstanceMethod;

280 Info.Lang = SymbolLanguage::CXX;

281 break;

282 }

283 case Decl::ClassTemplate:

284 Info.Kind = SymbolKind::Class;

286 Info.Lang = SymbolLanguage::CXX;

287 break;

288 case Decl::FunctionTemplate:

289 Info.Kind = SymbolKind::Function;

291 Info.Lang = SymbolLanguage::CXX;

292 if (const CXXMethodDecl *MD = dyn_cast_or_null(

293 cast(D)->getTemplatedDecl())) {

294 if (isa(MD))

295 Info.Kind = SymbolKind::Constructor;

296 else if (isa(MD))

297 Info.Kind = SymbolKind::Destructor;

298 else if (isa(MD))

299 Info.Kind = SymbolKind::ConversionFunction;

300 else {

301 if (MD->isStatic())

302 Info.Kind = SymbolKind::StaticMethod;

303 else

304 Info.Kind = SymbolKind::InstanceMethod;

305 }

306 }

307 break;

308 case Decl::TypeAliasTemplate:

309 Info.Kind = SymbolKind::TypeAlias;

310 Info.Lang = SymbolLanguage::CXX;

312 break;

313 case Decl::TypeAlias:

314 Info.Kind = SymbolKind::TypeAlias;

315 Info.Lang = SymbolLanguage::CXX;

316 break;

317 case Decl::UnresolvedUsingTypename:

318 Info.Kind = SymbolKind::Using;

319 Info.SubKind = SymbolSubKind::UsingTypename;

320 Info.Lang = SymbolLanguage::CXX;

322 break;

323 case Decl::UnresolvedUsingValue:

324 Info.Kind = SymbolKind::Using;

325 Info.SubKind = SymbolSubKind::UsingValue;

326 Info.Lang = SymbolLanguage::CXX;

328 break;

329 case Decl::Using:

330 Info.Kind = SymbolKind::Using;

331 Info.Lang = SymbolLanguage::CXX;

332 break;

333 case Decl::UsingEnum:

334 Info.Kind = SymbolKind::Using;

335 Info.Lang = SymbolLanguage::CXX;

336 Info.SubKind = SymbolSubKind::UsingEnum;

337 break;

338 case Decl::Binding:

339 Info.Kind = SymbolKind::Variable;

340 Info.Lang = SymbolLanguage::CXX;

341 break;

342 case Decl::MSProperty:

343 Info.Kind = SymbolKind::InstanceProperty;

346 if (!CXXRec->isCLike())

347 Info.Lang = SymbolLanguage::CXX;

348 }

349 break;

350 case Decl::ClassTemplatePartialSpecialization:

351 case Decl::ClassTemplateSpecialization:

352 case Decl::CXXRecord:

353 case Decl::Enum:

354 case Decl::Record:

355 llvm_unreachable("records handled before");

356 break;

357 case Decl::VarTemplateSpecialization:

358 case Decl::VarTemplatePartialSpecialization:

359 case Decl::ImplicitParam:

360 case Decl::ParmVar:

361 case Decl::Var:

362 case Decl::VarTemplate:

363 llvm_unreachable("variables handled before");

364 break;

365 case Decl::TemplateTypeParm:

366 Info.Kind = SymbolKind::TemplateTypeParm;

367 break;

368 case Decl::TemplateTemplateParm:

369 Info.Kind = SymbolKind::TemplateTemplateParm;

370 break;

371 case Decl::NonTypeTemplateParm:

372 Info.Kind = SymbolKind::NonTypeTemplateParm;

373 break;

374 case Decl::Concept:

375 Info.Kind = SymbolKind::Concept;

376 break;

377

378 default:

379 break;

380 }

381 }

382

383 if (Info.Kind == SymbolKind::Unknown)

384 return Info;

385

386 if (const FunctionDecl *FD = dyn_cast(D)) {

387 if (FD->getTemplatedKind() ==

390 Info.Properties |=

392 }

393 }

394

395 if (Info.Properties & (SymbolPropertySet)SymbolProperty::Generic)

396 Info.Lang = SymbolLanguage::CXX;

397

399 if (attr->getLanguage() == "Swift")

400 Info.Lang = SymbolLanguage::Swift;

401 }

402

403 return Info;

404}

405

408 Info.Kind = SymbolKind::Macro;

409 Info.SubKind = SymbolSubKind::None;

411 Info.Lang = SymbolLanguage::C;

412 return Info;

413}

414

416 llvm::function_ref<bool(SymbolRole)> Fn) {

417#define APPLY_FOR_ROLE(Role) \

418 if (Roles & (unsigned)SymbolRole::Role) \

419 if (!Fn(SymbolRole::Role)) \

420 return false;

421

443

444#undef APPLY_FOR_ROLE

445

446 return true;

447}

448

450 llvm::function_ref<void(SymbolRole)> Fn) {

452 Fn(r);

453 return true;

454 });

455}

456

458 bool VisitedOnce = false;

460 if (VisitedOnce)

461 OS << ',';

462 else

463 VisitedOnce = true;

464 switch (Role) {

465 case SymbolRole::Declaration: OS << "Decl"; break;

466 case SymbolRole::Definition: OS << "Def"; break;

467 case SymbolRole::Reference: OS << "Ref"; break;

468 case SymbolRole::Read: OS << "Read"; break;

469 case SymbolRole::Write: OS << "Writ"; break;

470 case SymbolRole::Call: OS << "Call"; break;

471 case SymbolRole::Dynamic: OS << "Dyn"; break;

472 case SymbolRole::AddressOf: OS << "Addr"; break;

473 case SymbolRole::Implicit: OS << "Impl"; break;

474 case SymbolRole::Undefinition: OS << "Undef"; break;

475 case SymbolRole::RelationChildOf: OS << "RelChild"; break;

476 case SymbolRole::RelationBaseOf: OS << "RelBase"; break;

477 case SymbolRole::RelationOverrideOf: OS << "RelOver"; break;

478 case SymbolRole::RelationReceivedBy: OS << "RelRec"; break;

479 case SymbolRole::RelationCalledBy: OS << "RelCall"; break;

480 case SymbolRole::RelationExtendedBy: OS << "RelExt"; break;

481 case SymbolRole::RelationAccessorOf: OS << "RelAcc"; break;

482 case SymbolRole::RelationContainedBy: OS << "RelCont"; break;

483 case SymbolRole::RelationIBTypeOf: OS << "RelIBType"; break;

484 case SymbolRole::RelationSpecializationOf: OS << "RelSpecialization"; break;

485 case SymbolRole::NameReference: OS << "NameReference"; break;

486 }

487 });

488}

489

491 raw_ostream &OS) {

492 if (auto *ND = dyn_cast(D)) {

494

495

496

500 return true;

501 DeclName.print(OS, Policy);

502 return false;

503 } else {

504 return true;

505 }

506}

507

509 switch (K) {

510 case SymbolKind::Unknown: return "";

511 case SymbolKind::Module: return "module";

512 case SymbolKind::Namespace: return "namespace";

513 case SymbolKind::NamespaceAlias: return "namespace-alias";

514 case SymbolKind::Macro: return "macro";

515 case SymbolKind::Enum: return "enum";

516 case SymbolKind::Struct: return "struct";

517 case SymbolKind::Class: return "class";

518 case SymbolKind::Protocol: return "protocol";

519 case SymbolKind::Extension: return "extension";

520 case SymbolKind::Union: return "union";

521 case SymbolKind::TypeAlias: return "type-alias";

522 case SymbolKind::Function: return "function";

523 case SymbolKind::Variable: return "variable";

524 case SymbolKind::Field: return "field";

525 case SymbolKind::EnumConstant: return "enumerator";

526 case SymbolKind::InstanceMethod: return "instance-method";

527 case SymbolKind::ClassMethod: return "class-method";

528 case SymbolKind::StaticMethod: return "static-method";

529 case SymbolKind::InstanceProperty: return "instance-property";

530 case SymbolKind::ClassProperty: return "class-property";

531 case SymbolKind::StaticProperty: return "static-property";

532 case SymbolKind::Constructor: return "constructor";

533 case SymbolKind::Destructor: return "destructor";

534 case SymbolKind::ConversionFunction: return "conversion-func";

535 case SymbolKind::Parameter: return "param";

536 case SymbolKind::Using: return "using";

537 case SymbolKind::TemplateTypeParm: return "template-type-param";

538 case SymbolKind::TemplateTemplateParm: return "template-template-param";

539 case SymbolKind::NonTypeTemplateParm: return "non-type-template-param";

540 case SymbolKind::Concept:

541 return "concept";

542 }

543 llvm_unreachable("invalid symbol kind");

544}

545

547 switch (K) {

548 case SymbolSubKind::None: return "";

549 case SymbolSubKind::CXXCopyConstructor: return "cxx-copy-ctor";

550 case SymbolSubKind::CXXMoveConstructor: return "cxx-move-ctor";

551 case SymbolSubKind::AccessorGetter: return "acc-get";

552 case SymbolSubKind::AccessorSetter: return "acc-set";

553 case SymbolSubKind::UsingTypename: return "using-typename";

554 case SymbolSubKind::UsingValue: return "using-value";

555 case SymbolSubKind::UsingEnum: return "using-enum";

556 }

557 llvm_unreachable("invalid symbol subkind");

558}

559

561 switch (K) {

562 case SymbolLanguage::C: return "C";

563 case SymbolLanguage::ObjC: return "ObjC";

564 case SymbolLanguage::CXX: return "C++";

565 case SymbolLanguage::Swift: return "Swift";

566 }

567 llvm_unreachable("invalid symbol language kind");

568}

569

572#define APPLY_FOR_PROPERTY(K) \

573 if (Props & (SymbolPropertySet)SymbolProperty::K) \

574 Fn(SymbolProperty::K)

575

585

586#undef APPLY_FOR_PROPERTY

587}

588

590 bool VisitedOnce = false;

592 if (VisitedOnce)

593 OS << ',';

594 else

595 VisitedOnce = true;

596 switch (Prop) {

597 case SymbolProperty::Generic: OS << "Gen"; break;

598 case SymbolProperty::TemplatePartialSpecialization: OS << "TPS"; break;

599 case SymbolProperty::TemplateSpecialization: OS << "TS"; break;

600 case SymbolProperty::UnitTest: OS << "test"; break;

601 case SymbolProperty::IBAnnotated: OS << "IB"; break;

602 case SymbolProperty::IBOutletCollection: OS << "IBColl"; break;

603 case SymbolProperty::GKInspectable: OS << "GKI"; break;

604 case SymbolProperty::Local: OS << "local"; break;

605 case SymbolProperty::ProtocolInterface: OS << "protocol"; break;

606 }

607 });

608}

Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....

Defines the C++ template declaration subclasses.

#define APPLY_FOR_PROPERTY(K)

static bool isUnitTest(const ObjCMethodDecl *D)

#define APPLY_FOR_ROLE(Role)

static void checkForIBOutlets(const Decl *D, SymbolPropertySet &PropSet)

static bool isUnitTestCase(const ObjCInterfaceDecl *D)

Defines the clang::MacroInfo and clang::MacroDirective classes.

Represents a static or instance method of a struct/union/class.

Represents a C++ struct/union/class.

Decl - This represents one declaration (or definition), e.g.

const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const

If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...

ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const

Looks on this and related declarations for an applicable external source symbol attribute.

DeclContext * getDeclContext()

The name of a declaration.

void print(raw_ostream &OS, const PrintingPolicy &Policy) const

bool isEmpty() const

Evaluates true when this declaration name is empty.

Represents a function declaration or definition.

@ TK_FunctionTemplateSpecialization

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

Encapsulates the data about a macro definition (e.g.

This represents a decl that may have a name.

Represents an ObjC class declaration.

ObjCMethodDecl - Represents an instance or class method declaration.

unsigned param_size() const

bool isPropertyAccessor() const

bool isInstanceMethod() const

Represents the declaration of a struct/union/class/enum.

const internal::VariadicAllOfMatcher< Attr > attr

Matches attributes.

void applyForEachSymbolProperty(SymbolPropertySet Props, llvm::function_ref< void(SymbolProperty)> Fn)

SymbolRole

Set of roles that are attributed to symbol occurrences.

@ RelationSpecializationOf

StringRef getSymbolSubKindString(SymbolSubKind K)

void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS)

SymbolInfo getSymbolInfo(const Decl *D)

StringRef getSymbolKindString(SymbolKind K)

bool isFunctionLocalSymbol(const Decl *D)

void applyForEachSymbolRole(SymbolRoleSet Roles, llvm::function_ref< void(SymbolRole)> Fn)

void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS)

SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI)

bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS)

bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)

SymbolProperty

Set of properties that provide additional info about a symbol.

@ TemplatePartialSpecialization

@ ProtocolInterface

Symbol is part of a protocol interface.

uint16_t SymbolPropertySet

StringRef getSymbolLanguageString(SymbolLanguage K)

SymbolSubKind

Language specific sub-kinds.

The JSON file list parser is used to communicate input to InstallAPI.

if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))

@ Generic

not a target-specific vector type

Describes how types, statements, expressions, and declarations should be printed.

unsigned SuppressTemplateArgsInCXXConstructors

When true, suppresses printing template arguments in names of C++ constructors.

SymbolPropertySet Properties