@@ -893,6 +893,33 @@ namespace {
893
893
printFieldQuotedRaw ([&](raw_ostream &OS) { declRef.dump (OS); }, label,
894
894
Color);
895
895
}
896
+
897
+ void printThrowDest (ThrownErrorDestination throws, bool wantNothrow) {
898
+ if (!throws) {
899
+ if (wantNothrow)
900
+ printFlag (" nothrow" , ExprModifierColor);
901
+
902
+ return ;
903
+ }
904
+
905
+ auto thrownError = throws.getThrownErrorType ();
906
+ auto contextError = throws.getContextErrorType ();
907
+ if (thrownError->isEqual (contextError)) {
908
+ // No translation of the thrown error type is required, so ony print
909
+ // the thrown error type.
910
+ Type errorExistentialType =
911
+ contextError->getASTContext ().getErrorExistentialType ();
912
+ if (errorExistentialType && thrownError->isEqual (errorExistentialType))
913
+ printFlag (" throws" , ExprModifierColor);
914
+ else {
915
+ printFlag (" throws(" + thrownError.getString () + " )" , ExprModifierColor);
916
+ }
917
+ return ;
918
+ }
919
+
920
+ printFlag (" throws(" + thrownError.getString () + " to " +
921
+ contextError.getString () + " )" , ExprModifierColor);
922
+ }
896
923
};
897
924
898
925
class PrintPattern : public PatternVisitor <PrintPattern, void , StringRef>,
@@ -2021,6 +2048,7 @@ class PrintStmt : public StmtVisitor<PrintStmt, void, StringRef>,
2021
2048
2022
2049
void visitDoCatchStmt (DoCatchStmt *S, StringRef label) {
2023
2050
printCommon (S, " do_catch_stmt" , label);
2051
+ printThrowDest (S->rethrows (), /* wantNothrow=*/ true );
2024
2052
printRec (S->getBody (), " body" );
2025
2053
printRecRange (S->getCatches (), Ctx, " catch_stmts" );
2026
2054
printFoot ();
@@ -2208,6 +2236,7 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
2208
2236
2209
2237
void visitDeclRefExpr (DeclRefExpr *E, StringRef label) {
2210
2238
printCommon (E, " declref_expr" , label);
2239
+ printThrowDest (E->throws (), /* wantNothrow=*/ false );
2211
2240
2212
2241
printDeclRefField (E->getDeclRef (), " decl" );
2213
2242
if (E->getAccessSemantics () != AccessSemantics::Ordinary)
@@ -2279,6 +2308,7 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
2279
2308
2280
2309
void visitMemberRefExpr (MemberRefExpr *E, StringRef label) {
2281
2310
printCommon (E, " member_ref_expr" , label);
2311
+ printThrowDest (E->throws (), /* wantNothrow=*/ false );
2282
2312
2283
2313
printDeclRefField (E->getMember (), " decl" );
2284
2314
if (E->getAccessSemantics () != AccessSemantics::Ordinary)
@@ -2290,6 +2320,7 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
2290
2320
}
2291
2321
void visitDynamicMemberRefExpr (DynamicMemberRefExpr *E, StringRef label) {
2292
2322
printCommon (E, " dynamic_member_ref_expr" , label);
2323
+ printThrowDest (E->throws (), /* wantNothrow=*/ false );
2293
2324
2294
2325
printDeclRefField (E->getMember (), " decl" );
2295
2326
@@ -2389,6 +2420,7 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
2389
2420
}
2390
2421
void visitSubscriptExpr (SubscriptExpr *E, StringRef label) {
2391
2422
printCommon (E, " subscript_expr" , label);
2423
+ printThrowDest (E->throws (), /* wantNothrow=*/ false );
2392
2424
2393
2425
if (E->getAccessSemantics () != AccessSemantics::Ordinary)
2394
2426
printFlag (getDumpString (E->getAccessSemantics ()), AccessLevelColor);
@@ -2410,6 +2442,7 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
2410
2442
}
2411
2443
void visitDynamicSubscriptExpr (DynamicSubscriptExpr *E, StringRef label) {
2412
2444
printCommon (E, " dynamic_subscript_expr" , label);
2445
+ printThrowDest (E->throws (), /* wantNothrow=*/ false );
2413
2446
2414
2447
printDeclRefField (E->getMember (), " decl" );
2415
2448
@@ -2798,7 +2831,7 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
2798
2831
void printApplyExpr (ApplyExpr *E, const char *NodeName, StringRef label) {
2799
2832
printCommon (E, NodeName, label);
2800
2833
if (E->isThrowsSet ()) {
2801
- printFlag (E->throws () ? " throws " : " nothrow " , ExprModifierColor );
2834
+ printThrowDest (E->throws (), /* wantNothrow= */ true );
2802
2835
}
2803
2836
printFieldQuotedRaw ([&](raw_ostream &OS) {
2804
2837
auto isolationCrossing = E->getIsolationCrossing ();
0 commit comments