@@ -2361,8 +2361,7 @@ class ChangeRefinementPass : public SDKTreeDiffPass, public SDKNodeVisitor {
2361
2361
// Similarly, the second JSON element describes a type parameter down cast in the
2362
2362
// second parameter of function "c:objc(cs)NSXMLDocument(im)insertChildren:atIndex:".
2363
2363
// We keep both usrs because in the future this may support auto-rename.
2364
- class DiffItem {
2365
- public:
2364
+ struct DiffItem {
2366
2365
SDKNodeKind NodeKind;
2367
2366
NodeAnnotation DiffKind;
2368
2367
StringRef ChildIndex;
@@ -2381,6 +2380,10 @@ class DiffItem {
2381
2380
assert (!ChildIndex.empty () && " Child index is empty." );
2382
2381
}
2383
2382
2383
+ static StringRef head () {
2384
+ return " SDK_CHANGE" ;
2385
+ }
2386
+
2384
2387
bool operator <(DiffItem Other) const {
2385
2388
if (auto UsrCompare = LeftUsr.compare (Other.LeftUsr ))
2386
2389
return UsrCompare < 0 ;
@@ -2394,16 +2397,19 @@ class DiffItem {
2394
2397
}
2395
2398
2396
2399
static void describe (llvm::raw_ostream &os) {
2397
- os << " // SDK_CHANGE(node kind, diff kind, child index, left USR, "
2398
- " right USR, left comment, right comment)\n " ;
2400
+ os << " #ifndef " << head () << " \n " ;
2401
+ os << " #define " << head () << " (NODE_KIND, DIFF_KIND, CHILD_INDEX, LEFT_USR, "
2402
+ " RIGHT_USR, LEFT_COMMENT, RIGHT_COMMENT, "
2403
+ " MODULENAME)\n " ;
2404
+ os << " #endif\n " ;
2399
2405
}
2400
2406
2401
2407
static void undef (llvm::raw_ostream &os) {
2402
- os << " #undef SDK_CHANGE \n " ;
2408
+ os << " #undef " << head () << " \n " ;
2403
2409
}
2404
2410
2405
2411
void streamDef (llvm::raw_ostream &S) const {
2406
- S << " SDK_CHANGE (" << NodeKind << " , " << DiffKind << " , \" " << ChildIndex
2412
+ S << head () << " (" << NodeKind << " , " << DiffKind << " , \" " << ChildIndex
2407
2413
<< " \" , \" " << LeftUsr << " \" , \" " << RightUsr << " \" , \" "
2408
2414
<< LeftComment << " \" , \" " << RightComment
2409
2415
<< " \" , \" " << ModuleName << " \" )" ;
@@ -2500,20 +2506,26 @@ struct TypeMemberDiffItem {
2500
2506
Optional<uint8_t > selfIndex;
2501
2507
StringRef oldPrintedName;
2502
2508
2509
+ static StringRef head () {
2510
+ return " SDK_CHANGE_TYPE_MEMBER" ;
2511
+ }
2512
+
2503
2513
static void describe (llvm::raw_ostream &os) {
2504
- os << " // SDK_CHANGE_TYPE_MEMBER(USR, new typename, new printed name, "
2505
- " self index, old printed name)\n " ;
2514
+ os << " #ifndef " << head () << " \n " ;
2515
+ os << " #define " << head () << " (USR, NEW_TYPE_NAME, NEW_PRINTED_NAME, "
2516
+ " SELF_INDEX, OLD_PRINTED_NAME)\n " ;
2517
+ os << " #endif\n " ;
2506
2518
}
2507
2519
2508
2520
static void undef (llvm::raw_ostream &os) {
2509
- os << " #undef SDK_CHANGE_TYPE_MEMBER \n " ;
2521
+ os << " #undef " << head () << " \n " ;
2510
2522
}
2511
2523
2512
2524
void streamDef (llvm::raw_ostream &os) const {
2513
2525
std::string IndexContent = selfIndex.hasValue () ?
2514
2526
std::to_string (selfIndex.getValue ()) : " " ;
2515
2527
2516
- os << " SDK_CHANGE_TYPE_MEMBER ("
2528
+ os << head () << " ("
2517
2529
<< " \" " << usr << " \" " << " , "
2518
2530
<< " \" " << newTypeName << " \" " << " , "
2519
2531
<< " \" " << newPrintedName << " \" " << " , "
@@ -2583,6 +2595,8 @@ void removeRedundantAndSort(std::vector<T> &Diffs) {
2583
2595
template <typename T>
2584
2596
void serializeDiffs (llvm::raw_ostream &Fs, std::vector<T> &Diffs) {
2585
2597
removeRedundantAndSort (Diffs);
2598
+ if (Diffs.empty ())
2599
+ return ;
2586
2600
Fs << " \n " ;
2587
2601
T::describe (Fs);
2588
2602
for (auto &Diff : Diffs) {
@@ -2603,61 +2617,68 @@ static bool isTypeChangeInterestedFuncNode(NodePtr Decl) {
2603
2617
}
2604
2618
}
2605
2619
2606
- static bool isInterested (SDKNodeDecl* Decl, NodeAnnotation Anno) {
2607
- switch (Anno) {
2608
- case NodeAnnotation::WrapOptional:
2609
- case NodeAnnotation::UnwrapOptional:
2610
- case NodeAnnotation::ImplicitOptionalToOptional:
2611
- case NodeAnnotation::OptionalToImplicitOptional:
2612
- case NodeAnnotation::UnwrapUnmanaged:
2613
- case NodeAnnotation::TypeRewritten:
2614
- return isTypeChangeInterestedFuncNode (Decl) &&
2615
- Decl->getParent ()->getKind () == SDKNodeKind::TypeDecl;
2616
- default :
2617
- return true ;
2618
- }
2619
- }
2620
-
2621
2620
class DiffItemEmitter : public SDKNodeVisitor {
2622
2621
DiffVector &AllItems;
2623
2622
2623
+ static bool isInterested (SDKNodeDecl* Decl, NodeAnnotation Anno) {
2624
+ switch (Anno) {
2625
+ case NodeAnnotation::WrapOptional:
2626
+ case NodeAnnotation::UnwrapOptional:
2627
+ case NodeAnnotation::ImplicitOptionalToOptional:
2628
+ case NodeAnnotation::OptionalToImplicitOptional:
2629
+ case NodeAnnotation::UnwrapUnmanaged:
2630
+ case NodeAnnotation::TypeRewritten:
2631
+ return isTypeChangeInterestedFuncNode (Decl) &&
2632
+ Decl->getParent ()->getKind () == SDKNodeKind::TypeDecl;
2633
+ default :
2634
+ return true ;
2635
+ }
2636
+ }
2637
+
2624
2638
bool doesAncestorHaveTypeRewritten () {
2625
2639
return std::find_if (Ancestors.begin (), Ancestors.end (),[](NodePtr N) {
2626
2640
return N->isAnnotatedAs (NodeAnnotation::TypeRewritten);
2627
2641
}) != Ancestors.end ();
2628
2642
}
2629
2643
2630
- StringRef getLeftComment (NodePtr Node, NodeAnnotation Anno) {
2631
- if (Anno == NodeAnnotation::TypeRewritten)
2632
- return Node->getAnnotateComment (NodeAnnotation::TypeRewrittenLeft);
2633
- else if (Anno == NodeAnnotation::Rename)
2634
- return Node->getAnnotateComment (NodeAnnotation::RenameOldName);
2635
- return StringRef ();
2636
- }
2637
-
2638
- StringRef getRightComment (NodePtr Node, NodeAnnotation Anno) {
2639
- if (Anno == NodeAnnotation::TypeRewritten)
2640
- return Node->getAnnotateComment (NodeAnnotation::TypeRewrittenRight);
2641
- else if (Anno == NodeAnnotation::ModernizeEnum)
2642
- return Node->getAnnotateComment (NodeAnnotation::ModernizeEnum);
2643
- else if (Anno == NodeAnnotation::Rename)
2644
- return Node->getAnnotateComment (NodeAnnotation::RenameNewName);
2645
- return StringRef ();
2646
- }
2647
-
2648
- bool handleAnnotation (NodePtr Node, SDKNodeDecl *NonTypeParent,
2649
- StringRef Index, NodeAnnotation Annotation) {
2650
- if (isInterested (NonTypeParent, Annotation) &&
2651
- Node->isAnnotatedAs (Annotation)) {
2652
- auto Kind = NonTypeParent->getKind ();
2653
- StringRef LC = getLeftComment (Node, Annotation);
2654
- StringRef RC = getRightComment (Node, Annotation);
2655
- AllItems.emplace_back (Kind, Annotation, Index,
2656
- NonTypeParent->getUsr (), StringRef (), LC, RC,
2657
- NonTypeParent->getModuleName ());
2658
- return true ;
2644
+ static StringRef getLeftComment (NodePtr Node, NodeAnnotation Anno) {
2645
+ switch (Anno) {
2646
+ case NodeAnnotation::TypeRewritten:
2647
+ return Node->getAnnotateComment (NodeAnnotation::TypeRewrittenLeft);
2648
+ case NodeAnnotation::Rename:
2649
+ return Node->getAnnotateComment (NodeAnnotation::RenameOldName);
2650
+ default :
2651
+ return StringRef ();
2652
+ }
2653
+ }
2654
+
2655
+ static StringRef getRightComment (NodePtr Node, NodeAnnotation Anno) {
2656
+ switch (Anno) {
2657
+ case NodeAnnotation::TypeRewritten:
2658
+ return Node->getAnnotateComment (NodeAnnotation::TypeRewrittenRight);
2659
+ case NodeAnnotation::ModernizeEnum:
2660
+ return Node->getAnnotateComment (NodeAnnotation::ModernizeEnum);
2661
+ case NodeAnnotation::Rename:
2662
+ return Node->getAnnotateComment (NodeAnnotation::RenameNewName);
2663
+ default :
2664
+ return StringRef ();
2665
+ }
2666
+ }
2667
+
2668
+ void handleAnnotations (NodePtr Node, SDKNodeDecl *NonTypeParent,
2669
+ StringRef Index, ArrayRef<NodeAnnotation> Annotations) {
2670
+ for (auto Annotation: Annotations) {
2671
+ if (isInterested (NonTypeParent, Annotation) &&
2672
+ Node->isAnnotatedAs (Annotation)) {
2673
+ auto Kind = NonTypeParent->getKind ();
2674
+ StringRef LC = getLeftComment (Node, Annotation);
2675
+ StringRef RC = getRightComment (Node, Annotation);
2676
+ AllItems.emplace_back (Kind, Annotation, Index,
2677
+ NonTypeParent->getUsr (), StringRef (), LC, RC,
2678
+ NonTypeParent->getModuleName ());
2679
+ return ;
2680
+ }
2659
2681
}
2660
- return false ;
2661
2682
}
2662
2683
2663
2684
void visit (NodePtr Node) override {
@@ -2670,22 +2691,24 @@ class DiffItemEmitter : public SDKNodeVisitor {
2670
2691
2671
2692
if (!Parent)
2672
2693
return ;
2673
- auto Index = isa<SDKNodeType>(Node) ? getIndexString (Node) : " 0" ;
2674
-
2675
- bool Result =
2676
- doesAncestorHaveTypeRewritten () ||
2677
- handleAnnotation (Node, Parent, Index, NodeAnnotation::WrapOptional) ||
2678
- handleAnnotation (Node, Parent, Index, NodeAnnotation::UnwrapOptional) ||
2679
- handleAnnotation (Node, Parent, Index, NodeAnnotation::ImplicitOptionalToOptional) ||
2680
- handleAnnotation (Node, Parent, Index, NodeAnnotation::OptionalToImplicitOptional) ||
2681
- handleAnnotation (Node, Parent, Index, NodeAnnotation::UnwrapUnmanaged) ||
2682
- handleAnnotation (Node, Parent, Index, NodeAnnotation::TypeRewritten) ||
2683
- handleAnnotation (Node, Parent, Index, NodeAnnotation::SetterToProperty) ||
2684
- handleAnnotation (Node, Parent, Index, NodeAnnotation::GetterToProperty) ||
2685
- handleAnnotation (Node, Parent, Index, NodeAnnotation::ModernizeEnum) ||
2686
- handleAnnotation (Node, Parent, Index, NodeAnnotation::Rename) ||
2687
- handleAnnotation (Node, Parent, Index, NodeAnnotation::NowThrowing);
2688
- (void ) Result;
2694
+ if (doesAncestorHaveTypeRewritten ())
2695
+ return ;
2696
+
2697
+ handleAnnotations (Node, Parent,
2698
+ isa<SDKNodeType>(Node) ? getIndexString (Node) : " 0" ,
2699
+ {
2700
+ NodeAnnotation::WrapOptional,
2701
+ NodeAnnotation::UnwrapOptional,
2702
+ NodeAnnotation::ImplicitOptionalToOptional,
2703
+ NodeAnnotation::OptionalToImplicitOptional,
2704
+ NodeAnnotation::UnwrapUnmanaged,
2705
+ NodeAnnotation::TypeRewritten,
2706
+ NodeAnnotation::SetterToProperty,
2707
+ NodeAnnotation::GetterToProperty,
2708
+ NodeAnnotation::ModernizeEnum,
2709
+ NodeAnnotation::Rename,
2710
+ NodeAnnotation::NowThrowing
2711
+ });
2689
2712
}
2690
2713
2691
2714
StringRef getIndexString (NodePtr Node) {
@@ -3053,17 +3076,22 @@ struct NoEscapeFuncParam {
3053
3076
3054
3077
NoEscapeFuncParam (StringRef Usr, unsigned Index) : Usr(Usr), Index(Index) {}
3055
3078
3079
+ static StringRef head () {
3080
+ return " NOESCAPE_FUNC_PARAM" ;
3081
+ }
3082
+
3056
3083
static void describe (llvm::raw_ostream &os) {
3057
- os << " // NOESCAPE_FUNC_PARAM(USR, Index)\n " ;
3084
+ os << " #ifndef " << head () << " \n " ;
3085
+ os << " #define " << head () << " (USR, Index)\n " ;
3086
+ os << " #endif\n " ;
3058
3087
}
3059
3088
3060
3089
static void undef (llvm::raw_ostream &os) {
3061
- os << " #undef NOESCAPE_FUNC_PARAM \n " ;
3090
+ os << " #undef " << head () << " \n " ;
3062
3091
}
3063
3092
3064
3093
void streamDef (llvm::raw_ostream &os) const {
3065
- os << " NOESCAPE_FUNC_PARAM("
3066
- << " \" " << Usr << " \" " << " , "
3094
+ os << head () << " (" << " \" " << Usr << " \" " << " , "
3067
3095
<< " \" " << Index << " \" " << " )" ;
3068
3096
}
3069
3097
@@ -3108,17 +3136,22 @@ struct OverloadedFuncInfo {
3108
3136
StringRef Usr;
3109
3137
OverloadedFuncInfo (StringRef Usr) : Usr(Usr) {}
3110
3138
3139
+ static StringRef head () {
3140
+ return " OVERLOAD_FUNC_TRAILING_CLOSURE" ;
3141
+ }
3142
+
3111
3143
static void describe (llvm::raw_ostream &os) {
3112
- os << " // OVERLOAD_FUNC_TRAILING_CLOSURE(USR)\n " ;
3144
+ os << " #ifndef " << head () << " \n " ;
3145
+ os << " #define " << head () << " (USR)\n " ;
3146
+ os << " #endif\n " ;
3113
3147
}
3114
3148
3115
3149
static void undef (llvm::raw_ostream &os) {
3116
- os << " #undef OVERLOAD_FUNC_TRAILING_CLOSURE \n " ;
3150
+ os << " #undef " << head () << " \n " ;
3117
3151
}
3118
3152
3119
3153
void streamDef (llvm::raw_ostream &os) const {
3120
- os << " OVERLOAD_FUNC_TRAILING_CLOSURE("
3121
- << " \" " << Usr << " \" " << " )" ;
3154
+ os << head () << " (" << " \" " << Usr << " \" " << " )" ;
3122
3155
}
3123
3156
3124
3157
bool operator <(OverloadedFuncInfo Other) const {
0 commit comments