Skip to content

Commit 54ff860

Browse files
committedNov 12, 2019
Use TypeCheckerOptions to make TypeCheckSwitchStmt a utility
1 parent 48805b1 commit 54ff860

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed
 

‎lib/Sema/TypeCheckSwitchStmt.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -885,16 +885,14 @@ namespace {
885885
};
886886

887887
ASTContext &Context;
888-
unsigned CheckingThreshold;
889888
const SwitchStmt *Switch;
890889
const DeclContext *DC;
891890
APIntMap<Expr *> IntLiteralCache;
892891
llvm::DenseMap<APFloat, Expr *, ::DenseMapAPFloatKeyInfo> FloatLiteralCache;
893892
llvm::DenseMap<StringRef, Expr *> StringLiteralCache;
894893

895-
SpaceEngine(ASTContext &C, unsigned Threashold,
896-
const SwitchStmt *SS, const DeclContext *DC)
897-
: Context(C), CheckingThreshold(Threashold), Switch(SS), DC(DC) {}
894+
SpaceEngine(ASTContext &C, const SwitchStmt *SS, const DeclContext *DC)
895+
: Context(C), Switch(SS), DC(DC) {}
898896

899897
bool checkRedundantLiteral(const Pattern *Pat, Expr *&PrevPattern) {
900898
if (Pat->getKind() != PatternKind::Expr) {
@@ -1010,7 +1008,8 @@ namespace {
10101008
Space totalSpace = Space::forType(subjectType, Identifier());
10111009
Space coveredSpace = Space::forDisjunct(spaces);
10121010

1013-
unsigned minusCount = CheckingThreshold;
1011+
unsigned minusCount
1012+
= Context.TypeCheckerOpts.SwitchCheckingInvocationThreshold;
10141013
auto diff = totalSpace.minus(coveredSpace, DC, &minusCount);
10151014
if (!diff) {
10161015
diagnoseMissingCases(RequiresDefault::SpaceTooLarge, Space(),
@@ -1519,8 +1518,7 @@ namespace {
15191518
void TypeChecker::checkSwitchExhaustiveness(const SwitchStmt *stmt,
15201519
const DeclContext *DC,
15211520
bool limited) {
1522-
SpaceEngine(Context, getSwitchCheckingInvocationThreshold(), stmt, DC)
1523-
.checkExhaustiveness(limited);
1521+
SpaceEngine(DC->getASTContext(), stmt, DC).checkExhaustiveness(limited);
15241522
}
15251523

15261524
void SpaceEngine::Space::dump() const {

‎lib/Sema/TypeChecker.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1059,8 +1059,9 @@ class TypeChecker final {
10591059
/// \param limitChecking The checking process relies on the switch statement
10601060
/// being well-formed. If it is not, pass true to this flag to run a limited
10611061
/// form of analysis.
1062-
void checkSwitchExhaustiveness(const SwitchStmt *stmt, const DeclContext *DC,
1063-
bool limitChecking);
1062+
static void checkSwitchExhaustiveness(const SwitchStmt *stmt,
1063+
const DeclContext *DC,
1064+
bool limitChecking);
10641065

10651066
/// Type check the given expression as a condition, which converts
10661067
/// it to a logic value.

0 commit comments

Comments
 (0)