Skip to content

Commit 0e27645

Browse files
committed
AST: The body of a GuardStmt is always a BraceStmt
1 parent 750735b commit 0e27645

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

include/swift/AST/Stmt.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,17 @@ class IfStmt : public LabeledConditionalStmt {
632632
///
633633
class GuardStmt : public LabeledConditionalStmt {
634634
SourceLoc GuardLoc;
635-
Stmt *Body;
635+
BraceStmt *Body;
636636

637637
public:
638638
GuardStmt(SourceLoc GuardLoc, StmtCondition Cond,
639-
Stmt *Body, Optional<bool> implicit = None)
639+
BraceStmt *Body, Optional<bool> implicit = None)
640640
: LabeledConditionalStmt(StmtKind::Guard,
641641
getDefaultImplicitFlag(implicit, GuardLoc),
642642
LabeledStmtInfo(), Cond),
643643
GuardLoc(GuardLoc), Body(Body) {}
644644

645-
GuardStmt(SourceLoc GuardLoc, Expr *Cond, Stmt *Body,
645+
GuardStmt(SourceLoc GuardLoc, Expr *Cond, BraceStmt *Body,
646646
Optional<bool> implicit, ASTContext &Ctx);
647647

648648
SourceLoc getGuardLoc() const { return GuardLoc; }
@@ -654,8 +654,8 @@ class GuardStmt : public LabeledConditionalStmt {
654654
return Body->getEndLoc();
655655
}
656656

657-
Stmt *getBody() const { return Body; }
658-
void setBody(Stmt *s) { Body = s; }
657+
BraceStmt *getBody() const { return Body; }
658+
void setBody(BraceStmt *s) { Body = s; }
659659

660660
// Implement isa/cast/dyncast/etc.
661661
static bool classof(const Stmt *S) { return S->getKind() == StmtKind::Guard; }

lib/AST/ASTWalker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ Stmt *Traversal::visitGuardStmt(GuardStmt *US) {
14781478
if (doIt(US->getCond()))
14791479
return nullptr;
14801480

1481-
if (Stmt *S2 = doIt(US->getBody()))
1481+
if (BraceStmt *S2 = cast_or_null<BraceStmt>(doIt(US->getBody())))
14821482
US->setBody(S2);
14831483
else
14841484
return nullptr;

lib/AST/Stmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ IfStmt::IfStmt(SourceLoc IfLoc, Expr *Cond, Stmt *Then, SourceLoc ElseLoc,
380380
implicit) {
381381
}
382382

383-
GuardStmt::GuardStmt(SourceLoc GuardLoc, Expr *Cond, Stmt *Body,
383+
GuardStmt::GuardStmt(SourceLoc GuardLoc, Expr *Cond, BraceStmt *Body,
384384
Optional<bool> implicit, ASTContext &Ctx)
385385
: GuardStmt(GuardLoc, exprToCond(Cond, Ctx), Body, implicit) {
386386

lib/Sema/PCMacro.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ class Instrumenter : InstrumenterBase {
187187
transformStmtCondition(SC, GS->getStartLoc());
188188
GS->setCond(SC);
189189

190-
if (Stmt *BS = GS->getBody())
191-
GS->setBody(transformStmt(BS));
190+
if (BraceStmt *BS = GS->getBody())
191+
GS->setBody(transformBraceStmt(BS));
192192
return GS;
193193
}
194194

lib/Sema/PlaygroundTransform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ class Instrumenter : InstrumenterBase {
204204
}
205205

206206
GuardStmt *transformGuardStmt(GuardStmt *GS) {
207-
if (Stmt *BS = GS->getBody())
208-
GS->setBody(transformStmt(BS));
207+
if (BraceStmt *BS = GS->getBody())
208+
GS->setBody(transformBraceStmt(BS));
209209
return GS;
210210
}
211211

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
912912
Stmt *visitGuardStmt(GuardStmt *GS) {
913913
typeCheckConditionForStatement(GS, DC);
914914

915-
Stmt *S = GS->getBody();
915+
BraceStmt *S = GS->getBody();
916916
typeCheckStmt(S);
917917
GS->setBody(S);
918918
return GS;

0 commit comments

Comments
 (0)