Skip to content

Commit 28ff5d9

Browse files
authored
Merge pull request #16803 from nkcsgexi/api-digester-alias-to-raw
2 parents 435375d + 82ca0a1 commit 28ff5d9

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ NODE_ANNOTATION_CHANGE_KIND(ArrayMemberUpdate)
7979
NODE_ANNOTATION_CHANGE_KIND(OptionalArrayMemberUpdate)
8080
NODE_ANNOTATION_CHANGE_KIND(SimpleStringRepresentableUpdate)
8181
NODE_ANNOTATION_CHANGE_KIND(SimpleOptionalStringRepresentableUpdate)
82+
NODE_ANNOTATION_CHANGE_KIND(TypeAliasDeclToRawRepresentable)
8283

8384
NODE_ANNOTATION_CHANGE_KIND(RevertDictionaryKeyUpdate)
8485
NODE_ANNOTATION_CHANGE_KIND(RevertOptionalDictionaryKeyUpdate)

test/api-digester/Inputs/APINotesLeft/APINotesTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ extern int ANTGlobalValue;
2828
@end
2929

3030
extern NSString *globalAttributeName;
31+
32+
typedef NSString * CatAttributeName;

test/api-digester/Inputs/APINotesRight/APINotesTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ typedef NSString * AnimalAttributeName NS_STRING_ENUM;
2828
@end
2929

3030
extern AnimalAttributeName globalAttributeName;
31+
32+
typedef NSString * CatAttributeName NS_STRING_ENUM;

test/api-digester/Outputs/apinotes-diags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
/* RawRepresentable Changes */
3+
APINotesTest(APINotesTest.h): TypeAlias CatAttributeName(NSString) is now String representable
34

45
/* Removed Decls */
56
APINotesTest(APINotesTest.h): Func ObjcProt.protMemberFunc2() has been removed

test/api-digester/Outputs/apinotes-migrator-gen.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
"RightComment": "AnimalAttributeName",
1111
"ModuleName": "APINotesTest"
1212
},
13+
{
14+
"DiffItemKind": "CommonDiffItem",
15+
"NodeKind": "TypeAlias",
16+
"NodeAnnotation": "TypeAliasDeclToRawRepresentable",
17+
"ChildIndex": "0",
18+
"LeftUsr": "c:APINotesTest.h@T@CatAttributeName",
19+
"LeftComment": "NSString",
20+
"RightUsr": "",
21+
"RightComment": "String",
22+
"ModuleName": "APINotesTest"
23+
},
1324
{
1425
"DiffItemKind": "CommonDiffItem",
1526
"NodeKind": "Function",

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3806,6 +3806,22 @@ static int compareSDKs(StringRef LeftPath, StringRef RightPath,
38063806
RefinementPass.pass(LeftModule, RightModule);
38073807
DiffVector AllItems;
38083808
DiffItemEmitter::collectDiffItems(LeftModule, AllItems);
3809+
3810+
auto &AliasMap = Ctx.getTypeAliasUpdateMap();
3811+
// Find type alias change first.
3812+
TypeAliasDiffFinder(LeftModule, RightModule, AliasMap).search();
3813+
3814+
for (auto Pair: AliasMap) {
3815+
auto Left = Pair.first->getAs<SDKNodeDeclTypeAlias>()->getUnderlyingType()->
3816+
getPrintedName();
3817+
auto Right = AliasMap[(SDKNode*)Pair.first]->getAs<SDKNodeDeclType>()->
3818+
getRawValueType()->getPrintedName();
3819+
auto *D = Pair.first->getAs<SDKNodeDecl>();
3820+
AllItems.emplace_back(SDKNodeKind::DeclTypeAlias,
3821+
NodeAnnotation::TypeAliasDeclToRawRepresentable, "0",
3822+
D->getUsr(), "", Left, Right, D->getModuleName());
3823+
}
3824+
38093825
AllItems.erase(std::remove_if(AllItems.begin(), AllItems.end(),
38103826
[&](CommonDiffItem &Item) {
38113827
return Item.DiffKind == NodeAnnotation::RemovedDecl &&

0 commit comments

Comments
 (0)