Requestify FallthroughStmt source and destination lookup

Follow a similar pattern to BreakTargetRequest
and ContinueTargetRequest.
This commit is contained in:
Hamish Knight
2024-08-14 19:59:05 +01:00
parent 4470814db8
commit 55aed16ee6
12 changed files with 103 additions and 66 deletions

View File

@@ -1491,10 +1491,10 @@ BridgedDoCatchStmt BridgedDoCatchStmt_createParsed(
BridgedNullableTypeRepr cThrownType, BridgedStmt cBody,
BridgedArrayRef cCatches);
SWIFT_NAME("BridgedFallthroughStmt.createParsed(_:loc:)")
SWIFT_NAME("BridgedFallthroughStmt.createParsed(loc:declContext:)")
BridgedFallthroughStmt
BridgedFallthroughStmt_createParsed(BridgedASTContext cContext,
BridgedSourceLoc cLoc);
BridgedFallthroughStmt_createParsed(BridgedSourceLoc cLoc,
BridgedDeclContext cDC);
SWIFT_NAME("BridgedForEachStmt.createParsed(_:labelInfo:forLoc:tryLoc:awaitLoc:"
"pattern:inLoc:sequence:whereLoc:whereExpr:body:)")

View File

@@ -1159,36 +1159,29 @@ public:
/// FallthroughStmt - The keyword "fallthrough".
class FallthroughStmt : public Stmt {
SourceLoc Loc;
CaseStmt *FallthroughSource;
CaseStmt *FallthroughDest;
DeclContext *DC;
public:
FallthroughStmt(SourceLoc Loc, std::optional<bool> implicit = std::nullopt)
FallthroughStmt(SourceLoc Loc, DeclContext *DC,
std::optional<bool> implicit = std::nullopt)
: Stmt(StmtKind::Fallthrough, getDefaultImplicitFlag(implicit, Loc)),
Loc(Loc), FallthroughSource(nullptr), FallthroughDest(nullptr) {}
Loc(Loc), DC(DC) {}
public:
static FallthroughStmt *createParsed(SourceLoc Loc, DeclContext *DC);
SourceLoc getLoc() const { return Loc; }
SourceRange getSourceRange() const { return Loc; }
DeclContext *getDeclContext() const { return DC; }
void setDeclContext(DeclContext *newDC) { DC = newDC; }
/// Get the CaseStmt block from which the fallthrough transfers control.
/// Set during Sema. (May stay null if fallthrough is invalid.)
CaseStmt *getFallthroughSource() const { return FallthroughSource; }
void setFallthroughSource(CaseStmt *C) {
assert(!FallthroughSource && "fallthrough source already set?!");
FallthroughSource = C;
}
/// Returns \c nullptr if the fallthrough is invalid.
CaseStmt *getFallthroughSource() const;
/// Get the CaseStmt block to which the fallthrough transfers control.
/// Set during Sema.
CaseStmt *getFallthroughDest() const {
assert(FallthroughDest && "fallthrough dest is not set until Sema");
return FallthroughDest;
}
void setFallthroughDest(CaseStmt *C) {
assert(!FallthroughDest && "fallthrough dest already set?!");
FallthroughDest = C;
}
/// Returns \c nullptr if the fallthrough is invalid.
CaseStmt *getFallthroughDest() const;
static bool classof(const Stmt *S) {
return S->getKind() == StmtKind::Fallthrough;

View File

@@ -4162,6 +4162,29 @@ public:
bool isCached() const { return true; }
};
struct FallthroughSourceAndDest {
CaseStmt *Source;
CaseStmt *Dest;
};
/// Lookup the source and destination of a 'fallthrough'.
class FallthroughSourceAndDestRequest
: public SimpleRequest<FallthroughSourceAndDestRequest,
FallthroughSourceAndDest(const FallthroughStmt *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;
private:
friend SimpleRequest;
FallthroughSourceAndDest evaluate(Evaluator &evaluator,
const FallthroughStmt *FS) const;
public:
bool isCached() const { return true; }
};
/// Precheck a ReturnStmt, which involves some initial validation, as well as
/// applying a conversion to a FailStmt if needed.
class PreCheckReturnStmtRequest

View File

@@ -482,6 +482,9 @@ SWIFT_REQUEST(TypeChecker, BreakTargetRequest,
SWIFT_REQUEST(TypeChecker, ContinueTargetRequest,
LabeledStmt *(const ContinueStmt *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, FallthroughSourceAndDestRequest,
FallthroughSourceAndDest(const FallthroughStmt *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, PreCheckReturnStmtRequest,
Stmt *(ReturnStmt *, DeclContext *),
Cached, NoLocationInfo)