2424#include " swift/AST/ConcreteDeclRef.h"
2525#include " swift/AST/IfConfigClause.h"
2626#include " swift/AST/TypeAlignments.h"
27+ #include " swift/AST/TypeLoc.h"
2728#include " swift/AST/ThrownErrorDestination.h"
2829#include " swift/Basic/Debug.h"
2930#include " swift/Basic/NullablePtr.h"
@@ -1381,16 +1382,25 @@ class DoCatchStmt final
13811382 : public LabeledStmt,
13821383 private llvm::TrailingObjects<DoCatchStmt, CaseStmt *> {
13831384 friend TrailingObjects;
1385+ friend class DoCatchExplicitThrownTypeRequest ;
13841386
13851387 SourceLoc DoLoc;
1388+
1389+ // / Location of the 'throws' token.
1390+ SourceLoc ThrowsLoc;
1391+
1392+ // / The error type that is being thrown.
1393+ TypeLoc ThrownType;
1394+
13861395 Stmt *Body;
13871396 ThrownErrorDestination RethrowDest;
13881397
1389- DoCatchStmt (LabeledStmtInfo labelInfo, SourceLoc doLoc, Stmt *body,
1398+ DoCatchStmt (LabeledStmtInfo labelInfo, SourceLoc doLoc,
1399+ SourceLoc throwsLoc, TypeLoc thrownType, Stmt *body,
13901400 ArrayRef<CaseStmt *> catches, llvm::Optional<bool > implicit)
13911401 : LabeledStmt(StmtKind::DoCatch, getDefaultImplicitFlag(implicit, doLoc),
13921402 labelInfo),
1393- DoLoc (doLoc), Body(body) {
1403+ DoLoc (doLoc), ThrowsLoc(throwsLoc), ThrownType(thrownType), Body(body) {
13941404 Bits.DoCatchStmt .NumCatches = catches.size ();
13951405 std::uninitialized_copy (catches.begin (), catches.end (),
13961406 getTrailingObjects<CaseStmt *>());
@@ -1400,15 +1410,28 @@ class DoCatchStmt final
14001410
14011411public:
14021412 static DoCatchStmt *create (ASTContext &ctx, LabeledStmtInfo labelInfo,
1403- SourceLoc doLoc, Stmt *body,
1413+ SourceLoc doLoc,
1414+ SourceLoc throwsLoc, TypeLoc thrownType,
1415+ Stmt *body,
14041416 ArrayRef<CaseStmt *> catches,
14051417 llvm::Optional<bool > implicit = llvm::None);
14061418
14071419 SourceLoc getDoLoc () const { return DoLoc; }
14081420
1421+ // / Retrieve the location of the 'throws' keyword, if present.
1422+ SourceLoc getThrowsLoc () const { return ThrowsLoc; }
1423+
14091424 SourceLoc getStartLoc () const { return getLabelLocOrKeywordLoc (DoLoc); }
14101425 SourceLoc getEndLoc () const { return getCatches ().back ()->getEndLoc (); }
14111426
1427+ // / Retrieves the type representation for the thrown type.
1428+ TypeRepr *getThrownTypeRepr () const {
1429+ return ThrownType.getTypeRepr ();
1430+ }
1431+
1432+ // Get the explicitly-specified thrown error type.
1433+ Type getExplicitlyThrownType (DeclContext *dc) const ;
1434+
14121435 Stmt *getBody () const { return Body; }
14131436 void setBody (Stmt *s) { Body = s; }
14141437
@@ -1433,7 +1456,7 @@ class DoCatchStmt final
14331456 // and caught by the various 'catch' clauses. If this the catch clauses
14341457 // aren't exhausive, this is also the type of the error that is implicitly
14351458 // rethrown.
1436- Type getCaughtErrorType () const ;
1459+ Type getCaughtErrorType (DeclContext *dc ) const ;
14371460
14381461 // / Retrieves the rethrown error and its conversion to the error type
14391462 // / expected by the enclosing context.
0 commit comments