mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Requestify FallthroughStmt source and destination lookup
Follow a similar pattern to BreakTargetRequest and ContinueTargetRequest.
This commit is contained in:
@@ -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:)")
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user