Skip to content

A few small ASTScope-related refactorings #34204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions include/swift/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,17 @@ class IfStmt : public LabeledConditionalStmt {
///
class GuardStmt : public LabeledConditionalStmt {
SourceLoc GuardLoc;
Stmt *Body;
BraceStmt *Body;

public:
GuardStmt(SourceLoc GuardLoc, StmtCondition Cond,
Stmt *Body, Optional<bool> implicit = None)
BraceStmt *Body, Optional<bool> implicit = None)
: LabeledConditionalStmt(StmtKind::Guard,
getDefaultImplicitFlag(implicit, GuardLoc),
LabeledStmtInfo(), Cond),
GuardLoc(GuardLoc), Body(Body) {}

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

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

Stmt *getBody() const { return Body; }
void setBody(Stmt *s) { Body = s; }
BraceStmt *getBody() const { return Body; }
void setBody(BraceStmt *s) { Body = s; }

// Implement isa/cast/dyncast/etc.
static bool classof(const Stmt *S) { return S->getKind() == StmtKind::Guard; }
Expand Down Expand Up @@ -945,13 +945,13 @@ class CaseStmt final
SourceLoc ItemTerminatorLoc;
CaseParentKind ParentKind;

llvm::PointerIntPair<Stmt *, 1, bool> BodyAndHasFallthrough;
llvm::PointerIntPair<BraceStmt *, 1, bool> BodyAndHasFallthrough;

Optional<MutableArrayRef<VarDecl *>> CaseBodyVariables;

CaseStmt(CaseParentKind ParentKind, SourceLoc ItemIntroducerLoc,
ArrayRef<CaseLabelItem> CaseLabelItems, SourceLoc UnknownAttrLoc,
SourceLoc ItemTerminatorLoc, Stmt *Body,
SourceLoc ItemTerminatorLoc, BraceStmt *Body,
Optional<MutableArrayRef<VarDecl *>> CaseBodyVariables,
Optional<bool> Implicit,
NullablePtr<FallthroughStmt> fallthroughStmt);
Expand All @@ -960,7 +960,7 @@ class CaseStmt final
static CaseStmt *
create(ASTContext &C, CaseParentKind ParentKind, SourceLoc ItemIntroducerLoc,
ArrayRef<CaseLabelItem> CaseLabelItems, SourceLoc UnknownAttrLoc,
SourceLoc ItemTerminatorLoc, Stmt *Body,
SourceLoc ItemTerminatorLoc, BraceStmt *Body,
Optional<MutableArrayRef<VarDecl *>> CaseBodyVariables,
Optional<bool> Implicit = None,
NullablePtr<FallthroughStmt> fallthroughStmt = nullptr);
Expand Down Expand Up @@ -997,8 +997,8 @@ class CaseStmt final

bool hasFallthroughDest() const { return BodyAndHasFallthrough.getInt(); }

Stmt *getBody() const { return BodyAndHasFallthrough.getPointer(); }
void setBody(Stmt *body) { BodyAndHasFallthrough.setPointer(body); }
BraceStmt *getBody() const { return BodyAndHasFallthrough.getPointer(); }
void setBody(BraceStmt *body) { BodyAndHasFallthrough.setPointer(body); }

/// True if the case block declares any patterns with local variable bindings.
bool hasBoundDecls() const { return CaseBodyVariables.hasValue(); }
Expand Down
33 changes: 19 additions & 14 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,10 @@ namespace {
void visitExtensionDecl(ExtensionDecl *ED) {
printCommon(ED, "extension_decl", ExtensionColor);
OS << ' ';
ED->getExtendedType().print(OS);
if (ED->hasBeenBound())
ED->getExtendedType().print(OS);
else
ED->getExtendedTypeRepr()->print(OS);
printCommonPost(ED);
}

Expand Down Expand Up @@ -854,20 +857,22 @@ namespace {
if (D->isStatic())
PrintWithColorRAII(OS, DeclModifierColor) << " type";

auto impl = D->getImplInfo();
PrintWithColorRAII(OS, DeclModifierColor)
<< " readImpl="
<< getReadImplKindName(impl.getReadImpl());
if (!impl.supportsMutation()) {
PrintWithColorRAII(OS, DeclModifierColor)
<< " immutable";
} else {
if (D->hasInterfaceType()) {
auto impl = D->getImplInfo();
PrintWithColorRAII(OS, DeclModifierColor)
<< " writeImpl="
<< getWriteImplKindName(impl.getWriteImpl());
PrintWithColorRAII(OS, DeclModifierColor)
<< " readWriteImpl="
<< getReadWriteImplKindName(impl.getReadWriteImpl());
<< " readImpl="
<< getReadImplKindName(impl.getReadImpl());
if (!impl.supportsMutation()) {
PrintWithColorRAII(OS, DeclModifierColor)
<< " immutable";
} else {
PrintWithColorRAII(OS, DeclModifierColor)
<< " writeImpl="
<< getWriteImplKindName(impl.getWriteImpl());
PrintWithColorRAII(OS, DeclModifierColor)
<< " readWriteImpl="
<< getReadWriteImplKindName(impl.getReadWriteImpl());
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ Stmt *Traversal::visitGuardStmt(GuardStmt *US) {
if (doIt(US->getCond()))
return nullptr;

if (Stmt *S2 = doIt(US->getBody()))
if (BraceStmt *S2 = cast_or_null<BraceStmt>(doIt(US->getBody())))
US->setBody(S2);
else
return nullptr;
Expand Down Expand Up @@ -1631,7 +1631,7 @@ Stmt *Traversal::visitCaseStmt(CaseStmt *S) {
}
}

if (Stmt *newBody = doIt(S->getBody()))
if (BraceStmt *newBody = cast_or_null<BraceStmt>(doIt(S->getBody())))
S->setBody(newBody);
else
return nullptr;
Expand Down
6 changes: 3 additions & 3 deletions lib/AST/Stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ IfStmt::IfStmt(SourceLoc IfLoc, Expr *Cond, Stmt *Then, SourceLoc ElseLoc,
implicit) {
}

GuardStmt::GuardStmt(SourceLoc GuardLoc, Expr *Cond, Stmt *Body,
GuardStmt::GuardStmt(SourceLoc GuardLoc, Expr *Cond, BraceStmt *Body,
Optional<bool> implicit, ASTContext &Ctx)
: GuardStmt(GuardLoc, exprToCond(Cond, Ctx), Body, implicit) {

Expand All @@ -407,7 +407,7 @@ SourceLoc CaseLabelItem::getEndLoc() const {
CaseStmt::CaseStmt(CaseParentKind parentKind, SourceLoc itemIntroducerLoc,
ArrayRef<CaseLabelItem> caseLabelItems,
SourceLoc unknownAttrLoc, SourceLoc itemTerminatorLoc,
Stmt *body,
BraceStmt *body,
Optional<MutableArrayRef<VarDecl *>> caseBodyVariables,
Optional<bool> implicit,
NullablePtr<FallthroughStmt> fallthroughStmt)
Expand Down Expand Up @@ -445,7 +445,7 @@ CaseStmt *CaseStmt::create(ASTContext &ctx, CaseParentKind ParentKind,
SourceLoc caseLoc,
ArrayRef<CaseLabelItem> caseLabelItems,
SourceLoc unknownAttrLoc, SourceLoc colonLoc,
Stmt *body,
BraceStmt *body,
Optional<MutableArrayRef<VarDecl *>> caseVarDecls,
Optional<bool> implicit,
NullablePtr<FallthroughStmt> fallthroughStmt) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6000,7 +6000,7 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
// up in Decls to be returned to caller.
if (topLevelDecl) {
PBD->setDeclContext(topLevelDecl);
auto range = PBD->getSourceRange();
auto range = PBD->getSourceRangeIncludingAttrs();
topLevelDecl->setBody(BraceStmt::create(Context, range.Start,
ASTNode(PBD), range.End, true));
Decls.insert(Decls.begin()+NumDeclsInResult, topLevelDecl);
Expand Down
3 changes: 1 addition & 2 deletions lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,9 +1876,8 @@ ParserResult<Stmt> Parser::parseStmtRepeat(LabeledStmtInfo labelInfo) {

ParserResult<Expr> condition;
if (Tok.is(tok::l_brace)) {
SourceLoc lbraceLoc = Tok.getLoc();
diagnose(whileLoc, diag::missing_condition_after_while);
condition = makeParserErrorResult(new (Context) ErrorExpr(lbraceLoc));
condition = makeParserErrorResult(new (Context) ErrorExpr(whileLoc));
} else {
condition = parseExpr(diag::expected_expr_repeat_while);
status |= condition;
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/PCMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class Instrumenter : InstrumenterBase {
transformStmtCondition(SC, GS->getStartLoc());
GS->setCond(SC);

if (Stmt *BS = GS->getBody())
GS->setBody(transformStmt(BS));
if (BraceStmt *BS = GS->getBody())
GS->setBody(transformBraceStmt(BS));
return GS;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/PlaygroundTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ class Instrumenter : InstrumenterBase {
}

GuardStmt *transformGuardStmt(GuardStmt *GS) {
if (Stmt *BS = GS->getBody())
GS->setBody(transformStmt(BS));
if (BraceStmt *BS = GS->getBody())
GS->setBody(transformBraceStmt(BS));
return GS;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
Stmt *visitGuardStmt(GuardStmt *GS) {
typeCheckConditionForStatement(GS, DC);

Stmt *S = GS->getBody();
BraceStmt *S = GS->getBody();
typeCheckStmt(S);
GS->setBody(S);
return GS;
Expand Down Expand Up @@ -1150,7 +1150,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
getASTContext(), caseBlock, limitExhaustivityChecks);
}

Stmt *body = caseBlock->getBody();
BraceStmt *body = caseBlock->getBody();
limitExhaustivityChecks |= typeCheckStmt(body);
caseBlock->setBody(body);
}
Expand Down