@@ -231,21 +231,6 @@ class ChildIndexFinder : public TypeReprVisitor<ChildIndexFinder, FoundResult> {
231
231
}
232
232
};
233
233
234
- static ValueDecl* getReferencedDecl (Expr *E) {
235
- // Get the syntactic expression out of an implicit expression.
236
- if (auto *ICE = dyn_cast<ImplicitConversionExpr>(E))
237
- E = ICE->getSyntacticSubExpr ();
238
- if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
239
- return DRE->getDecl ();
240
- } else if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {
241
- return MRE->getMember ().getDecl ();
242
- } else if (auto OtherCtorE = dyn_cast<OtherConstructorDeclRefExpr>(E)) {
243
- return OtherCtorE->getDecl ();
244
- } else {
245
- return nullptr ;
246
- }
247
- }
248
-
249
234
struct ConversionFunctionInfo {
250
235
Expr *ExpressionToWrap;
251
236
SmallString<256 > Buffer;
@@ -582,15 +567,10 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
582
567
}
583
568
return false ;
584
569
};
585
- if (auto *DSC = dyn_cast<DotSyntaxCallExpr>(Call)) {
586
- if (auto FD = DSC->getFn ()->getReferencedDecl ().getDecl ()) {
587
- if (handleDecl (FD, Call->getSourceRange ()))
588
- return true ;
589
- }
590
- } else if (auto MRE = dyn_cast<MemberRefExpr>(Call)) {
591
- if (handleDecl (MRE->getReferencedDecl ().getDecl (), MRE->getSourceRange ()))
570
+ if (auto *VD = getReferencedDecl (Call).second .getDecl ())
571
+ if (handleDecl (VD, Call->getSourceRange ()))
592
572
return true ;
593
- }
573
+
594
574
return false ;
595
575
}
596
576
@@ -858,11 +838,12 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
858
838
Lexer::getLocForEndOfToken (SM, E->getEndLoc ())), Text);
859
839
}
860
840
861
- bool wrapAttributeReference (Expr* Reference, Expr* WrapperTarget,
841
+ bool wrapAttributeReference (Expr * Reference, Expr * WrapperTarget,
862
842
bool FromString) {
863
- auto *RD = getReferencedDecl (Reference );
843
+ auto *RD = Reference-> getReferencedDecl (). getDecl ( );
864
844
if (!RD)
865
845
return false ;
846
+
866
847
std::string Rename;
867
848
Optional<NodeAnnotation> Kind;
868
849
StringRef LeftComment;
@@ -1110,7 +1091,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
1110
1091
// reference of the property.
1111
1092
bool handlePropertyTypeChange (Expr *E) {
1112
1093
if (auto MRE = dyn_cast<MemberRefExpr>(E)) {
1113
- if (auto *VD = MRE->getReferencedDecl ().getDecl ()) {
1094
+ if (auto *VD = MRE->getMember ().getDecl ()) {
1114
1095
for (auto *I: getRelatedDiffItems (VD)) {
1115
1096
if (auto *Item = dyn_cast<CommonDiffItem>(I)) {
1116
1097
if (Item->DiffKind == NodeAnnotation::WrapOptional &&
@@ -1143,46 +1124,36 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
1143
1124
if (auto *CE = dyn_cast<CallExpr>(E)) {
1144
1125
auto Fn = CE->getFn ();
1145
1126
auto Args = CE->getArg ();
1146
- switch (Fn->getKind ()) {
1147
- case ExprKind::DeclRef: {
1148
- if (auto FD = Fn->getReferencedDecl ().getDecl ()) {
1149
- handleFuncRename (FD, Fn, Args);
1150
- handleTypeHoist (FD, CE, Args);
1151
- handleSpecialCases (FD, CE, Args);
1152
- handleStringRepresentableArg (FD, Args, CE);
1153
- handleResultTypeChange (FD, CE);
1154
- }
1155
- break ;
1156
- }
1157
- case ExprKind::DotSyntaxCall: {
1158
- auto DSC = cast<DotSyntaxCallExpr>(Fn);
1159
- if (auto FD = DSC->getFn ()->getReferencedDecl ().getDecl ()) {
1160
- handleFuncRename (FD, DSC->getFn (), Args);
1161
- handleFunctionCallToPropertyChange (FD, DSC->getFn (), Args);
1162
- handleSpecialCases (FD, CE, Args);
1163
- handleStringRepresentableArg (FD, Args, CE);
1164
- handleResultTypeChange (FD, CE);
1127
+
1128
+ if (auto *DRE = dyn_cast<DeclRefExpr>(Fn)) {
1129
+ if (auto *VD = DRE->getDecl ()) {
1130
+ if (VD->getNumCurryLevels () == 1 ) {
1131
+ handleFuncRename (VD, Fn, Args);
1132
+ handleTypeHoist (VD, CE, Args);
1133
+ handleSpecialCases (VD, CE, Args);
1134
+ handleStringRepresentableArg (VD, Args, CE);
1135
+ handleResultTypeChange (VD, CE);
1136
+ }
1165
1137
}
1166
- break ;
1167
1138
}
1168
- case ExprKind::ConstructorRefCall: {
1169
- auto CCE = cast<ConstructorRefCallExpr>(Fn);
1170
- if (auto FD = CCE->getFn ()->getReferencedDecl ().getDecl ()) {
1171
- handleFuncRename (FD, CE, Args);
1172
- handleStringRepresentableArg (FD, Args, CE);
1173
- handleResultTypeChange (FD, CE);
1139
+
1140
+ if (auto *SelfApply = dyn_cast<ApplyExpr>(Fn)) {
1141
+ if (auto VD = SelfApply->getFn ()->getReferencedDecl ().getDecl ()) {
1142
+ if (VD->getNumCurryLevels () == 2 ) {
1143
+ handleFuncRename (VD, SelfApply->getFn (), Args);
1144
+ handleFunctionCallToPropertyChange (VD, SelfApply->getFn (), Args);
1145
+ handleSpecialCases (VD, CE, Args);
1146
+ handleStringRepresentableArg (VD, Args, CE);
1147
+ handleResultTypeChange (VD, CE);
1148
+ }
1174
1149
}
1175
- break ;
1176
- }
1177
- default :
1178
- break ;
1179
1150
}
1180
1151
}
1181
1152
return true ;
1182
1153
}
1183
1154
1184
- static void collectParamters (AbstractFunctionDecl *AFD,
1185
- SmallVectorImpl<ParamDecl*> &Results) {
1155
+ static void collectParameters (AbstractFunctionDecl *AFD,
1156
+ SmallVectorImpl<ParamDecl*> &Results) {
1186
1157
for (auto PD : *AFD->getParameters ()) {
1187
1158
Results.push_back (PD);
1188
1159
}
@@ -1197,7 +1168,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
1197
1168
Editor.replace (NameRange, View.base ());
1198
1169
unsigned Index = 0 ;
1199
1170
SmallVector<ParamDecl*, 4 > Params;
1200
- collectParamters (AFD, Params);
1171
+ collectParameters (AFD, Params);
1201
1172
for (auto *PD: Params) {
1202
1173
if (Index == View.argSize ())
1203
1174
break ;
@@ -1322,7 +1293,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
1322
1293
return ;
1323
1294
Idx --;
1324
1295
SmallVector<ParamDecl*, 4 > Params;
1325
- collectParamters (AFD, Params);
1296
+ collectParameters (AFD, Params);
1326
1297
if (Params.size () <= Idx)
1327
1298
return ;
1328
1299
@@ -1397,11 +1368,11 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
1397
1368
Editor (Editor), USRs(USRs) {}
1398
1369
bool isSuperExpr (Expr *E) {
1399
1370
if (E->isImplicit ())
1400
- return false ;
1371
+ return false ;
1401
1372
// Check if the expression is super.foo().
1402
1373
if (auto *CE = dyn_cast<CallExpr>(E)) {
1403
1374
if (auto *DSC = dyn_cast<DotSyntaxCallExpr>(CE->getFn ())) {
1404
- if (DSC->getBase ()-> getKind () != ExprKind::SuperRef )
1375
+ if (!isa<SuperRefExpr>( DSC->getBase ()) )
1405
1376
return false ;
1406
1377
llvm::SmallString<64 > Buffer;
1407
1378
llvm::raw_svector_ostream OS (Buffer);
@@ -1419,9 +1390,9 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
1419
1390
}
1420
1391
std::pair<bool , Stmt*> walkToStmtPre (Stmt *S) override {
1421
1392
if (auto *BS = dyn_cast<BraceStmt>(S)) {
1422
- for (auto Ele: BS->getElements ()) {
1423
- if (Ele.is <Expr*>() && isSuperExpr (Ele.get <Expr*>())) {
1424
- Editor.remove (Ele.getSourceRange ());
1393
+ for (auto Ele: BS->getElements ()) {
1394
+ if (Ele.is <Expr*>() && isSuperExpr (Ele.get <Expr*>())) {
1395
+ Editor.remove (Ele.getSourceRange ());
1425
1396
}
1426
1397
}
1427
1398
}
0 commit comments