mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma- separated list of patterns. The body will be executed if any one of those patterns is matched. This patch replaces `CatchStmt` with `CaseStmt` as the children of `DoCatchStmt` in the AST. This necessitates a number of changes throughout the compiler, including: - Parser & libsyntax support for the new syntax and AST structure - Typechecking of multi-pattern catches, including those which contain bindings. - SILGen support - Code completion updates - Profiler updates - Name lookup changes
This commit is contained in:
@@ -225,8 +225,9 @@ deriveBodyCodingKey_enum_stringValue(AbstractFunctionDecl *strValDecl, void *) {
|
||||
auto *returnStmt = new (C) ReturnStmt(SourceLoc(), caseValue);
|
||||
auto *caseBody = BraceStmt::create(C, SourceLoc(), ASTNode(returnStmt),
|
||||
SourceLoc());
|
||||
cases.push_back(CaseStmt::create(C, SourceLoc(), labelItem, SourceLoc(),
|
||||
SourceLoc(), caseBody,
|
||||
cases.push_back(CaseStmt::create(C, CaseParentKind::Switch, SourceLoc(),
|
||||
labelItem, SourceLoc(), SourceLoc(),
|
||||
caseBody,
|
||||
/*case body var decls*/ None));
|
||||
}
|
||||
|
||||
@@ -292,8 +293,8 @@ deriveBodyCodingKey_init_stringValue(AbstractFunctionDecl *initDecl, void *) {
|
||||
|
||||
auto *body = BraceStmt::create(C, SourceLoc(), ASTNode(assignment),
|
||||
SourceLoc());
|
||||
cases.push_back(CaseStmt::create(C, SourceLoc(), labelItem, SourceLoc(),
|
||||
SourceLoc(), body,
|
||||
cases.push_back(CaseStmt::create(C, CaseParentKind::Switch, SourceLoc(),
|
||||
labelItem, SourceLoc(), SourceLoc(), body,
|
||||
/*case body var decls*/ None));
|
||||
}
|
||||
|
||||
@@ -304,8 +305,9 @@ deriveBodyCodingKey_init_stringValue(AbstractFunctionDecl *initDecl, void *) {
|
||||
auto *dfltReturnStmt = new (C) FailStmt(SourceLoc(), SourceLoc());
|
||||
auto *dfltBody = BraceStmt::create(C, SourceLoc(), ASTNode(dfltReturnStmt),
|
||||
SourceLoc());
|
||||
cases.push_back(CaseStmt::create(C, SourceLoc(), dfltLabelItem, SourceLoc(),
|
||||
SourceLoc(), dfltBody,
|
||||
cases.push_back(CaseStmt::create(C, CaseParentKind::Switch, SourceLoc(),
|
||||
dfltLabelItem, SourceLoc(), SourceLoc(),
|
||||
dfltBody,
|
||||
/*case body var decls*/ None));
|
||||
|
||||
auto *stringValueDecl = initDecl->getParameters()->get(0);
|
||||
|
||||
Reference in New Issue
Block a user