Skip to content

Commit f4c39a6

Browse files
authored
Merge pull request #16484 from nkcsgexi/migrator-cherry-pick-05-09-4-30
[4.2-04-30] Cherry-pick migrator changes
2 parents be3158c + fbe76e8 commit f4c39a6

File tree

11 files changed

+119
-35
lines changed

11 files changed

+119
-35
lines changed

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
347347
Editor.replace(Range, RepText);
348348
return true;
349349
}
350-
if (updateStringRepresentableDeclRef(Item, Range)) {
351-
return true;
352-
}
353350
}
354351
return true;
355352
}
@@ -683,20 +680,30 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
683680
auto *RD = getReferencedDecl(Reference);
684681
if (!RD)
685682
return false;
683+
std::string Func;
684+
std::string Rename;
686685
for (auto *Item: getRelatedDiffItems(RD)) {
687-
if (auto *CI = dyn_cast<CommonDiffItem>(Item)) {
686+
if (isSimpleReplacement(Item, Rename)) {
687+
} else if (auto *CI = dyn_cast<CommonDiffItem>(Item)) {
688688
if (CI->isStringRepresentableChange() &&
689689
CI->NodeKind == SDKNodeKind::DeclVar) {
690690
SmallString<256> Buffer;
691-
auto Func = insertHelperFunction(CI->DiffKind, CI->RightComment,
692-
Buffer, FromString);
693-
Editor.insert(WrapperTarget->getStartLoc(), (Twine(Func) + "(").str());
694-
Editor.insertAfterToken(WrapperTarget->getEndLoc(), ")");
695-
return true;
691+
Func = insertHelperFunction(CI->DiffKind, CI->RightComment, Buffer,
692+
FromString);
696693
}
697694
}
698695
}
699-
return false;
696+
if (Func.empty())
697+
return false;
698+
699+
Editor.insert(WrapperTarget->getStartLoc(), (Twine(Func) + "(").str());
700+
Editor.insertAfterToken(WrapperTarget->getEndLoc(), ")");
701+
if (!Rename.empty()) {
702+
auto Range = CharSourceRange(SM, Reference->getStartLoc(),
703+
Lexer::getLocForEndOfToken(SM, Reference->getEndLoc()));
704+
Editor.replace(Range, Rename);
705+
}
706+
return true;
700707
}
701708

702709
bool handleAssignDestMigration(Expr *E) {
@@ -827,7 +834,9 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
827834
bool walkToExprPre(Expr *E) override {
828835
if (handleQualifiedReplacement(E))
829836
return false;
830-
if (handleAssignDestMigration(E) || handleAttributeReference(E))
837+
if (handleAssignDestMigration(E))
838+
return false;
839+
if (handleAttributeReference(E))
831840
return false;
832841
if (auto *CE = dyn_cast<CallExpr>(E)) {
833842
auto Fn = CE->getFn();

test/Migrator/Inputs/Cities.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ public class ToplevelType {
5959
public init() {}
6060
public init(recordName: String) {}
6161
}
62+
63+
public var GlobalAttribute: String = ""

test/Migrator/Inputs/string-representable.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,23 @@
197197
"RightComment": "SimpleAttribute",
198198
"ModuleName": "Cities"
199199
},
200+
{
201+
"DiffItemKind": "CommonDiffItem",
202+
"NodeKind": "Var",
203+
"NodeAnnotation": "SimpleStringRepresentableUpdate",
204+
"ChildIndex": "0",
205+
"LeftUsr": "s:6Cities15GlobalAttributeSSvp",
206+
"LeftComment": "",
207+
"RightUsr": "",
208+
"RightComment": "NewAttribute",
209+
"ModuleName": "Cities"
210+
},
211+
{
212+
"DiffItemKind": "TypeMemberDiffItem",
213+
"Usr": "s:6Cities15GlobalAttributeSSvp",
214+
"OldPrintedName": "GlobalAttribute",
215+
"OldTypeName": "",
216+
"NewPrintedName": "NewAttribute",
217+
"NewTypeName": "AttributeWrapper"
218+
},
200219
]

test/Migrator/string-representable.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ func foo(_ c: Container) -> String {
3434
c.adding(attributes: c.attrDict)
3535
_ = Container(optionalAttrArray: c.attrArr)
3636
c.adding(optionalAttributes: c.optionalAttrDict)
37+
_ = GlobalAttribute
3738
return c.Value
3839
}

test/Migrator/string-representable.swift.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func foo(_ c: Container) -> String {
3434
c.adding(attributes: convertToSimpleAttributeDictionary(convertFromSimpleAttributeDictionary(c.attrDict)))
3535
_ = Container(optionalAttrArray: convertToOptionalSimpleAttributeArray(convertFromSimpleAttributeArray(c.attrArr)))
3636
c.adding(optionalAttributes: convertToOptionalSimpleAttributeDictionary(convertFromOptionalSimpleAttributeDictionary(c.optionalAttrDict)))
37+
_ = convertFromNewAttribute(AttributeWrapper.NewAttribute)
3738
return convertFromNewAttribute(c.Value)
3839
}
3940

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ extern int ANTGlobalValue;
2626
+ (nonnull AnimalStatusDescriptor *)animalStatusSingleOptionalAttribute:(nullable NSString *)attributes;
2727
+ (nonnull AnimalStatusDescriptor *)animalStatusSingleAttribute:(nonnull NSString *)attributes;
2828
@end
29+
30+
extern NSString *globalAttributeName;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ typedef NSString * AnimalAttributeName NS_STRING_ENUM;
2626
+ (nonnull AnimalStatusDescriptor *)animalStatusSingleOptionalAttribute:(nullable AnimalAttributeName)attributes;
2727
+ (nonnull AnimalStatusDescriptor *)animalStatusSingleAttribute:(nonnull AnimalAttributeName)attributes;
2828
@end
29+
30+
extern AnimalAttributeName globalAttributeName;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ APINotesTest(APINotesTest.h): TypeAlias AnimalAttributeName(NSString) is now Str
77
/* Moved Decls */
88

99
/* Renamed Decls */
10+
APINotesTest(APINotesTest.h): Var globalAttributeName has been renamed to Var AnimalAttributeName.globalAttributeName
1011

1112
/* Type Changes */
1213
APINotesTest(APINotesTest.h): Func AnimalStatusDescriptor.addingAttributes(_:) has parameter 0 type change from [String : Any] to [AnimalAttributeName : Any]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ APINotesTest(APINotesTest.h): Func SwiftTypeWithMethodLeft.getPropertyA() has be
1111
/* Renamed Decls */
1212
APINotesTest(APINotesTest.h): Protocol SwiftTypeWithMethodLeft has been renamed to Protocol SwiftTypeWithMethodRight
1313
APINotesTest(APINotesTest.h): Var OldType.oldMember has been renamed to Var NewType.newMember
14+
APINotesTest(APINotesTest.h): Var globalAttributeName has been renamed to Var AnimalAttributeName.globalAttributeName
1415

1516
/* Type Changes */
1617
APINotesTest(APINotesTest.h): Func AnimalStatusDescriptor.addingAttributes(_:) has parameter 0 type change from [String : Any] to [AnimalAttributeName : Any]

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@
230230
"RightComment": "SwiftTypeWithMethodRight",
231231
"ModuleName": "APINotesTest"
232232
},
233+
{
234+
"DiffItemKind": "CommonDiffItem",
235+
"NodeKind": "Var",
236+
"NodeAnnotation": "SimpleStringRepresentableUpdate",
237+
"ChildIndex": "0",
238+
"LeftUsr": "c:@globalAttributeName",
239+
"LeftComment": "",
240+
"RightUsr": "",
241+
"RightComment": "AnimalAttributeName",
242+
"ModuleName": "APINotesTest"
243+
},
244+
{
245+
"DiffItemKind": "TypeMemberDiffItem",
246+
"Usr": "c:@globalAttributeName",
247+
"OldPrintedName": "globalAttributeName",
248+
"OldTypeName": "",
249+
"NewPrintedName": "globalAttributeName",
250+
"NewTypeName": "AnimalAttributeName"
251+
},
233252
{
234253
"DiffItemKind": "TypeMemberDiffItem",
235254
"Usr": "c:@ANTGlobalValue",

0 commit comments

Comments
 (0)