@@ -314,6 +314,8 @@ class SDKNode {
314
314
bool operator ==(const SDKNode &Other) const ;
315
315
bool operator !=(const SDKNode &Other) const { return !((*this ) == Other); }
316
316
317
+ ArrayRef<NodeAnnotation>
318
+ getAnnotations (std::vector<NodeAnnotation> &Scrach) const ;
317
319
bool isLeaf () const { return Children.empty (); }
318
320
SDKNodeKind getKind () const { return SDKNodeKind (TheKind); }
319
321
StringRef getName () const { return Name; }
@@ -364,10 +366,10 @@ class SDKNodeDecl : public SDKNode {
364
366
bool isObjc () const { return Usr.startswith (" c:" ); }
365
367
static bool classof (const SDKNode *N);
366
368
DeclKind getDeclKind () const { return DKind; }
367
- void printFullyQualifiedName (llvm::raw_ostream &OS);
368
- StringRef getFullyQualifiedName ();
369
- bool isSDKPrivate ();
370
- bool isDeprecated ();
369
+ void printFullyQualifiedName (llvm::raw_ostream &OS) const ;
370
+ StringRef getFullyQualifiedName () const ;
371
+ bool isSDKPrivate () const ;
372
+ bool isDeprecated () const ;
371
373
bool isStatic () const { return IsStatic; };
372
374
};
373
375
@@ -431,9 +433,9 @@ unsigned SDKNode::getChildIndex(NodePtr Child) const {
431
433
}
432
434
433
435
NodePtr SDKNode::getOnlyChild () const {
434
- assert (Children.size () == 1 && " more that one child." );
435
- return (*Children.begin ()).get ();
436
- }
436
+ assert (Children.size () == 1 && " more that one child." );
437
+ return (*Children.begin ()).get ();
438
+ }
437
439
438
440
void SDKNode::addChild (NodeUniquePtr Child) {
439
441
Child->Parent = this ;
@@ -468,6 +470,13 @@ StringRef SDKNode::getAnnotateComment(NodeAnnotation Anno) const {
468
470
return AnnotateComments.find (Anno)->second ;
469
471
}
470
472
473
+ ArrayRef<NodeAnnotation> SDKNode::
474
+ getAnnotations (std::vector<NodeAnnotation> &Scratch) const {
475
+ for (auto Ann : Annotations)
476
+ Scratch.push_back (Ann);
477
+ return llvm::makeArrayRef (Scratch);
478
+ }
479
+
471
480
bool SDKNode::isAnnotatedAs (NodeAnnotation Anno) const {
472
481
return Annotations.find (Anno) != Annotations.end ();;
473
482
}
@@ -588,19 +597,19 @@ SDKNode* SDKNodeNil::getInstance() {
588
597
return Instance.get ();
589
598
}
590
599
591
- bool SDKNodeDecl::isDeprecated () {
600
+ bool SDKNodeDecl::isDeprecated () const {
592
601
return hasDeclAttribute (SDKDeclAttrKind::DAK_deprecated);
593
602
}
594
603
595
- bool SDKNodeDecl::isSDKPrivate () {
604
+ bool SDKNodeDecl::isSDKPrivate () const {
596
605
if (getName ().startswith (" __" ))
597
606
return true ;
598
607
if (auto *PD = dyn_cast<SDKNodeDecl>(getParent ()))
599
608
return PD->isSDKPrivate ();
600
609
return false ;
601
610
}
602
611
603
- void SDKNodeDecl::printFullyQualifiedName (llvm::raw_ostream &OS) {
612
+ void SDKNodeDecl::printFullyQualifiedName (llvm::raw_ostream &OS) const {
604
613
std::vector<NodePtr> Parent;
605
614
for (auto *P = getParent (); isa<SDKNodeDecl>(P); P = P->getParent ())
606
615
Parent.push_back (P);
@@ -609,7 +618,7 @@ void SDKNodeDecl::printFullyQualifiedName(llvm::raw_ostream &OS) {
609
618
OS << getPrintedName ();
610
619
}
611
620
612
- StringRef SDKNodeDecl::getFullyQualifiedName () {
621
+ StringRef SDKNodeDecl::getFullyQualifiedName () const {
613
622
llvm::SmallString<32 > Buffer;
614
623
llvm::raw_svector_ostream OS (Buffer);
615
624
printFullyQualifiedName (OS);
@@ -1936,7 +1945,7 @@ class UpdatedNodesMap : public MatchedNodeListener {
1936
1945
MapImpl.push_back (std::make_pair (Left, Right));
1937
1946
}
1938
1947
1939
- NodePtr findUpdateCounterpart (NodePtr Node) const {
1948
+ NodePtr findUpdateCounterpart (const SDKNode * Node) const {
1940
1949
assert (Node->isAnnotatedAs (NodeAnnotation::Updated) && " Not update operation." );
1941
1950
auto FoundPair = std::find_if (MapImpl.begin (), MapImpl.end (),
1942
1951
[&](std::pair<NodePtr, NodePtr> Pair) {
@@ -2688,10 +2697,11 @@ class DiffItemEmitter : public SDKNodeVisitor {
2688
2697
};
2689
2698
2690
2699
class DiagnosisEmitter : public SDKNodeVisitor {
2700
+ void handle (const SDKNodeDecl *D, NodeAnnotation Anno);
2691
2701
void visitType (SDKNodeType *T);
2692
2702
void visitDecl (SDKNodeDecl *D);
2693
2703
void visit (NodePtr Node) override ;
2694
- SDKNodeDecl *findAddedDecl (SDKNodeDecl *Node);
2704
+ SDKNodeDecl *findAddedDecl (const SDKNodeDecl *Node);
2695
2705
static StringRef printName (StringRef Name);
2696
2706
static StringRef printDiagKeyword (StringRef Name);
2697
2707
static void collectAddedDecls (NodePtr Root, std::set<SDKNodeDecl*> &Results);
@@ -2805,7 +2815,7 @@ void DiagnosisEmitter::collectAddedDecls(NodePtr Root,
2805
2815
collectAddedDecls (C.get (), Results);
2806
2816
}
2807
2817
2808
- SDKNodeDecl *DiagnosisEmitter::findAddedDecl (SDKNodeDecl *Root) {
2818
+ SDKNodeDecl *DiagnosisEmitter::findAddedDecl (const SDKNodeDecl *Root) {
2809
2819
for (auto *Added : AddedDecls) {
2810
2820
if (Root->getKind () == Added->getKind () &&
2811
2821
Root->getPrintedName () == Added->getPrintedName ())
@@ -2904,11 +2914,10 @@ void DiagnosisEmitter::diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
2904
2914
SDKNode::postorderVisit (LeftRoot, Emitter);
2905
2915
}
2906
2916
2907
- void DiagnosisEmitter::visitDecl (SDKNodeDecl *Node) {
2908
- if (Node->isSDKPrivate ())
2909
- return ;
2910
- if (Node->isAnnotatedAs (NodeAnnotation::Removed) &&
2911
- !Node->isAnnotatedAs (NodeAnnotation::Rename)) {
2917
+ void DiagnosisEmitter::handle (const SDKNodeDecl *Node, NodeAnnotation Anno) {
2918
+ assert (Node->isAnnotatedAs (Anno));
2919
+ switch (Anno) {
2920
+ case NodeAnnotation::Removed: {
2912
2921
if (auto *Added = findAddedDecl (Node)) {
2913
2922
MovedDecls.Diags .emplace_back (Node->getDeclKind (),
2914
2923
Added->getDeclKind (),
@@ -2919,29 +2928,34 @@ void DiagnosisEmitter::visitDecl(SDKNodeDecl *Node) {
2919
2928
Node->getFullyQualifiedName (),
2920
2929
Node->isDeprecated ());
2921
2930
}
2931
+ return ;
2922
2932
}
2923
- if (Node-> isAnnotatedAs ( NodeAnnotation::Rename)) {
2933
+ case NodeAnnotation::Rename: {
2924
2934
auto *Count = UpdateMap.findUpdateCounterpart (Node)->getAs <SDKNodeDecl>();
2925
2935
RenamedDecls.Diags .emplace_back (Node->getDeclKind (), Count->getDeclKind (),
2926
2936
Node->getFullyQualifiedName (),
2927
2937
Count->getFullyQualifiedName ());
2938
+ return ;
2928
2939
}
2929
- if (Node-> isAnnotatedAs ( NodeAnnotation::NowMutating)) {
2940
+ case NodeAnnotation::NowMutating: {
2930
2941
AttrChangedDecls.Diags .emplace_back (Node->getDeclKind (),
2931
2942
Node->getFullyQualifiedName (),
2932
2943
InsertToBuffer (" mutating" ));
2944
+ return ;
2933
2945
}
2934
- if (Node-> isAnnotatedAs ( NodeAnnotation::NowThrowing)) {
2946
+ case NodeAnnotation::NowThrowing: {
2935
2947
AttrChangedDecls.Diags .emplace_back (Node->getDeclKind (),
2936
2948
Node->getFullyQualifiedName (),
2937
2949
InsertToBuffer (" throwing" ));
2950
+ return ;
2938
2951
}
2939
- if (Node-> isAnnotatedAs ( NodeAnnotation::StaticChange)) {
2952
+ case NodeAnnotation::StaticChange: {
2940
2953
AttrChangedDecls.Diags .emplace_back (Node->getDeclKind (),
2941
2954
Node->getFullyQualifiedName (),
2942
2955
InsertToBuffer (Node->isStatic () ? " not static" : " static" ));
2956
+ return ;
2943
2957
}
2944
- if (Node-> isAnnotatedAs ( NodeAnnotation::OwnershipChange)) {
2958
+ case NodeAnnotation::OwnershipChange: {
2945
2959
auto getOwnershipDescription = [](swift::Ownership O) {
2946
2960
switch (O) {
2947
2961
case Ownership::Strong: return InsertToBuffer (" strong" );
@@ -2955,8 +2969,21 @@ void DiagnosisEmitter::visitDecl(SDKNodeDecl *Node) {
2955
2969
Node->getFullyQualifiedName (),
2956
2970
getOwnershipDescription (Node->getOwnership ()),
2957
2971
getOwnershipDescription (Count->getOwnership ()));
2972
+ return ;
2973
+ }
2974
+ default :
2975
+ return ;
2958
2976
}
2959
2977
}
2978
+
2979
+ void DiagnosisEmitter::visitDecl (SDKNodeDecl *Node) {
2980
+ if (Node->isSDKPrivate ())
2981
+ return ;
2982
+ std::vector<NodeAnnotation> Scratch;
2983
+ for (auto Anno : Node->getAnnotations (Scratch))
2984
+ handle (Node, Anno);
2985
+ }
2986
+
2960
2987
void DiagnosisEmitter::visitType (SDKNodeType *Node) {
2961
2988
auto *Parent = Node->getParent ()->getAs <SDKNodeDecl>();
2962
2989
if (!Parent || Parent->isSDKPrivate ())
0 commit comments