24
24
using namespace swift ;
25
25
using namespace swift ::index;
26
26
27
- static SymbolSubKind getSubKindForAccessor (AccessorKind AK) {
28
- switch (AK) {
29
- case AccessorKind::NotAccessor: return SymbolSubKind::None;
30
- case AccessorKind::IsGetter: return SymbolSubKind::AccessorGetter;
31
- case AccessorKind::IsSetter: return SymbolSubKind::AccessorSetter;
32
- case AccessorKind::IsWillSet: return SymbolSubKind::AccessorWillSet;
33
- case AccessorKind::IsDidSet: return SymbolSubKind::AccessorDidSet;
34
- case AccessorKind::IsAddressor: return SymbolSubKind::AccessorAddressor;
35
- case AccessorKind::IsMutableAddressor:
36
- return SymbolSubKind::AccessorMutableAddressor;
37
- case AccessorKind::IsMaterializeForSet:
38
- llvm_unreachable (" unexpected MaterializeForSet" );
39
- }
40
-
41
- llvm_unreachable (" Unhandled AccessorKind in switch." );
42
- }
43
-
44
27
static bool
45
28
printArtificialName (const swift::AbstractStorageDecl *ASD, AccessorKind AK, llvm::raw_ostream &OS) {
46
29
switch (AK) {
@@ -132,8 +115,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
132
115
bool isSystemModule = false ;
133
116
struct Entity {
134
117
Decl *D;
135
- SymbolKind Kind;
136
- SymbolSubKindSet SubKinds;
118
+ SymbolInfo SymInfo;
137
119
SymbolRoleSet Roles;
138
120
SmallVector<SourceLoc, 6 > RefsToSuppress;
139
121
};
@@ -204,17 +186,14 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
204
186
bool addRelation (IndexSymbol &Info, SymbolRoleSet RelationRoles, ValueDecl *D) {
205
187
assert (D);
206
188
StringRef Name, USR;
207
- SymbolKind Kind = getSymbolKindForDecl (D);
208
- SymbolSubKindSet SubKinds = 0 ;
189
+ SymbolInfo SymInfo = getSymbolInfoForDecl (D);
209
190
210
- if (Kind == SymbolKind::Unknown)
191
+ if (SymInfo. Kind == SymbolKind::Unknown)
211
192
return true ;
212
- if (Kind == SymbolKind::Accessor)
213
- SubKinds |= getSubKindForAccessor (cast<FuncDecl>(D)->getAccessorKind ());
214
193
if (getNameAndUSR (D, Name, USR))
215
194
return true ;
216
195
217
- Info.Relations .push_back (IndexRelation (RelationRoles, D, Kind, SubKinds , Name, USR));
196
+ Info.Relations .push_back (IndexRelation (RelationRoles, D, SymInfo , Name, USR));
218
197
Info.roles |= RelationRoles;
219
198
return false ;
220
199
}
@@ -371,9 +350,8 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
371
350
372
351
bool finishCurrentEntity () {
373
352
Entity CurrEnt = EntitiesStack.pop_back_val ();
374
- assert (CurrEnt.Kind != SymbolKind::Unknown);
375
- if (!IdxConsumer.finishSourceEntity (CurrEnt.Kind , CurrEnt.SubKinds ,
376
- CurrEnt.Roles )) {
353
+ assert (CurrEnt.SymInfo .Kind != SymbolKind::Unknown);
354
+ if (!IdxConsumer.finishSourceEntity (CurrEnt.SymInfo , CurrEnt.Roles )) {
377
355
Cancelled = true ;
378
356
return false ;
379
357
}
@@ -512,43 +490,44 @@ bool IndexSwiftASTWalker::visitImports(
512
490
if (Path.empty () || Path == TopMod.getFilename ())
513
491
continue ; // this is a submodule.
514
492
515
- SymbolKind ImportKind = SymbolKind::Unknown ;
493
+ Optional< bool > IsClangModuleOpt ;
516
494
for (auto File : Mod->getFiles ()) {
517
495
switch (File->getKind ()) {
518
496
case FileUnitKind::Source:
519
497
case FileUnitKind::Builtin:
520
498
case FileUnitKind::Derived:
521
499
break ;
522
500
case FileUnitKind::SerializedAST:
523
- assert (ImportKind == SymbolKind::Unknown &&
501
+ assert (!IsClangModuleOpt. hasValue () &&
524
502
" cannot handle multi-file modules" );
525
- ImportKind = SymbolKind::Module ;
503
+ IsClangModuleOpt = false ;
526
504
break ;
527
505
case FileUnitKind::ClangModule:
528
- assert (ImportKind == SymbolKind::Unknown &&
506
+ assert (!IsClangModuleOpt. hasValue () &&
529
507
" cannot handle multi-file modules" );
530
- ImportKind = SymbolKind::ClangModule ;
508
+ IsClangModuleOpt = true ;
531
509
break ;
532
510
}
533
511
}
534
- if (ImportKind == SymbolKind::Unknown )
512
+ if (!IsClangModuleOpt. hasValue () )
535
513
continue ;
514
+ bool IsClangModule = *IsClangModuleOpt;
536
515
537
516
StringRef Hash;
538
517
SmallString<32 > HashBuf;
539
- if (ImportKind != SymbolKind::ClangModule ) {
518
+ if (!IsClangModule ) {
540
519
llvm::raw_svector_ostream HashOS (HashBuf);
541
520
getModuleHash (*Mod, HashOS);
542
521
Hash = HashOS.str ();
543
522
}
544
523
545
- if (!IdxConsumer.startDependency (ImportKind, Mod->getName ().str (), Path,
524
+ if (!IdxConsumer.startDependency (Mod->getName ().str (), Path, IsClangModule ,
546
525
Mod->isSystemModule (), Hash))
547
526
return false ;
548
- if (ImportKind != SymbolKind::ClangModule )
527
+ if (!IsClangModule )
549
528
if (!visitImports (*Mod, Visited))
550
529
return false ;
551
- if (!IdxConsumer.finishDependency (ImportKind ))
530
+ if (!IdxConsumer.finishDependency (IsClangModule ))
552
531
return false ;
553
532
}
554
533
@@ -563,7 +542,7 @@ bool IndexSwiftASTWalker::startEntity(Decl *D, IndexSymbol &Info) {
563
542
case swift::index::IndexDataConsumer::Skip:
564
543
return false ;
565
544
case swift::index::IndexDataConsumer::Continue:
566
- EntitiesStack.push_back ({D, Info.kind , Info. subKinds , Info.roles , {}});
545
+ EntitiesStack.push_back ({D, Info.symInfo , Info.roles , {}});
567
546
return true ;
568
547
}
569
548
}
@@ -598,7 +577,8 @@ bool IndexSwiftASTWalker::startEntityDecl(ValueDecl *D) {
598
577
// FIXME handle extensions properly
599
578
if (auto ParentVD = dyn_cast<ValueDecl>(Parent)) {
600
579
SymbolRoleSet RelationsToParent = (SymbolRoleSet)SymbolRole::RelationChildOf;
601
- if (Info.kind == SymbolKind::Accessor)
580
+ if (Info.symInfo .SubKind >= SymbolSubKind::SwiftAccessorGetter &&
581
+ Info.symInfo .SubKind <= SymbolSubKind::SwiftAccessorMutableAddressor)
602
582
RelationsToParent |= (SymbolRoleSet)SymbolRole::RelationAccessorOf;
603
583
if (addRelation (Info, RelationsToParent, ParentVD))
604
584
return false ;
@@ -670,8 +650,8 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
670
650
auto updateInfo = [this , D, AccKind](IndexSymbol &Info) {
671
651
if (getPseudoAccessorNameAndUSR (D, AccKind, Info.name , Info.USR ))
672
652
return true ;
673
- Info.kind = SymbolKind::Accessor ;
674
- Info.subKinds | = getSubKindForAccessor (AccKind);
653
+ Info.symInfo . Kind = SymbolKind::Function ;
654
+ Info.symInfo . SubKind = getSubKindForAccessor (AccKind);
675
655
Info.roles |= (SymbolRoleSet)SymbolRole::Implicit;
676
656
Info.group = " " ;
677
657
return false ;
@@ -684,7 +664,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
684
664
if (updateInfo (Info))
685
665
return true ;
686
666
687
- if (!IdxConsumer.startSourceEntity (Info) || !IdxConsumer.finishSourceEntity (Info.kind , Info. subKinds , Info.roles ))
667
+ if (!IdxConsumer.startSourceEntity (Info) || !IdxConsumer.finishSourceEntity (Info.symInfo , Info.roles ))
688
668
Cancelled = true ;
689
669
} else {
690
670
IndexSymbol Info;
@@ -695,7 +675,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
695
675
if (addRelation (Info, (SymbolRoleSet) SymbolRole::RelationAccessorOf, D))
696
676
return true ;
697
677
698
- if (!IdxConsumer.startSourceEntity (Info) || !IdxConsumer.finishSourceEntity (Info.kind , Info. subKinds , Info.roles ))
678
+ if (!IdxConsumer.startSourceEntity (Info) || !IdxConsumer.finishSourceEntity (Info.symInfo , Info.roles ))
699
679
Cancelled = true ;
700
680
}
701
681
return !Cancelled;
@@ -727,17 +707,7 @@ bool IndexSwiftASTWalker::reportExtension(ExtensionDecl *D) {
727
707
if (initIndexSymbol (NTD, Loc, /* IsRef=*/ false , Info))
728
708
return true ;
729
709
730
- Info.kind = getSymbolKindForDecl (D);
731
- if (isa<StructDecl>(NTD))
732
- Info.subKinds |= SymbolSubKind::ExtensionOfStruct;
733
- else if (isa<ClassDecl>(NTD))
734
- Info.subKinds |= SymbolSubKind::ExtensionOfClass;
735
- else if (isa<EnumDecl>(NTD))
736
- Info.subKinds |= SymbolSubKind::ExtensionOfEnum;
737
- else if (isa<ProtocolDecl>(NTD))
738
- Info.subKinds |= SymbolSubKind::ExtensionOfProtocol;
739
-
740
- assert (Info.subKinds != 0 );
710
+ Info.symInfo = getSymbolInfoForDecl (D);
741
711
742
712
if (!startEntity (D, Info))
743
713
return false ;
@@ -850,12 +820,10 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
850
820
bool IsRef, IndexSymbol &Info) {
851
821
assert (D);
852
822
Info.decl = D;
853
- Info.kind = getSymbolKindForDecl (D);
854
- if (Info.kind == SymbolKind::Unknown)
823
+ Info.symInfo = getSymbolInfoForDecl (D);
824
+ if (Info.symInfo . Kind == SymbolKind::Unknown)
855
825
return true ;
856
826
857
- if (Info.kind == SymbolKind::Accessor)
858
- Info.subKinds |= getSubKindForAccessor (cast<FuncDecl>(D)->getAccessorKind ());
859
827
// Cannot be extension, which is not a ValueDecl.
860
828
861
829
if (IsRef)
@@ -931,7 +899,7 @@ bool IndexSwiftASTWalker::initFuncDeclIndexSymbol(ValueDecl *D,
931
899
return true ;
932
900
933
901
if (isTestCandidate (D))
934
- Info.subKinds |= SymbolSubKind ::UnitTest;
902
+ Info.symInfo . Properties |= SymbolProperty ::UnitTest;
935
903
936
904
if (auto Group = D->getGroupName ())
937
905
Info.group = Group.getValue ();
0 commit comments