Skip to content

Commit e2b3114

Browse files
committed
[Sema] Remove StmtChecker.TargetTypeCheckLoc
The location itself is not used anymore. Use 'TypeCheckSingleASTNode' instead.
1 parent 12762a2 commit e2b3114

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
319319
CaseStmt /*nullable*/ *FallthroughDest = nullptr;
320320
FallthroughStmt /*nullable*/ *PreviousFallthrough = nullptr;
321321

322-
SourceLoc TargetTypeCheckLoc;
323-
324322
/// Used to distinguish the first BraceStmt that starts a TopLevelCodeDecl.
325323
bool IsBraceStmtFromTopLevelDecl;
326324

@@ -511,7 +509,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
511509

512510
TypeCheckExprOptions options = {};
513511

514-
if (TargetTypeCheckLoc.isValid()) {
512+
if (getASTContext().TypeCheckerOpts.TypeCheckSingleASTNode) {
515513
assert(DiagnosticSuppression::isEnabled(getASTContext().Diags) &&
516514
"Diagnosing and AllowUnresolvedTypeVariables don't seem to mix");
517515
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
@@ -1558,7 +1556,7 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) {
15581556
(!ctx.LangOpts.Playground && !ctx.LangOpts.DebuggerSupport);
15591557
if (isDiscarded)
15601558
options |= TypeCheckExprFlags::IsDiscarded;
1561-
if (TargetTypeCheckLoc.isValid())
1559+
if (getASTContext().TypeCheckerOpts.TypeCheckSingleASTNode)
15621560
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
15631561

15641562
auto resultTy =
@@ -1618,29 +1616,17 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
16181616
}
16191617
}
16201618

1621-
const SourceManager &SM = getASTContext().SourceMgr;
1622-
for (auto &elem : BS->getElements()) {
1623-
if (TargetTypeCheckLoc.isValid()) {
1624-
if (SM.isBeforeInBuffer(TargetTypeCheckLoc, elem.getStartLoc()))
1625-
break;
1626-
1627-
// NOTE: We need to check the character loc here because the target loc
1628-
// can be inside the last token of the node. i.e. string interpolation.
1629-
SourceLoc endLoc = Lexer::getLocForEndOfToken(SM, elem.getEndLoc());
1630-
if (endLoc == TargetTypeCheckLoc ||
1631-
SM.isBeforeInBuffer(endLoc, TargetTypeCheckLoc))
1632-
continue;
1633-
}
1634-
1619+
for (auto &elem : BS->getElements())
16351620
typeCheckASTNode(elem);
1636-
}
16371621

16381622
return BS;
16391623
}
16401624

16411625
void TypeChecker::typeCheckASTNode(ASTNode &node, DeclContext *DC) {
16421626
StmtChecker stmtChecker(DC);
1643-
stmtChecker.TargetTypeCheckLoc = node.getStartLoc();
1627+
// FIXME: 'ActiveLabeledStmts', 'SwitchLevel', etc. in StmtChecker are not
1628+
// populated. Since they don't affect "type checking", it's doesn't cause
1629+
// any issue for now. But it should be populated nonetheless.
16441630
stmtChecker.typeCheckASTNode(node);
16451631
}
16461632

@@ -1863,7 +1849,11 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(Evaluator &evaluator,
18631849
DeclContext *DC,
18641850
SourceLoc Loc) const {
18651851
auto &ctx = DC->getASTContext();
1852+
assert(DiagnosticSuppression::isEnabled(ctx.Diags) &&
1853+
"Diagnosing and Single ASTNode type checknig don't mix");
18661854

1855+
// Find innermost ASTNode at Loc from DC. Results the reference to the found
1856+
// ASTNode and the decl context of it.
18671857
class ASTNodeFinder : public ASTWalker {
18681858
SourceManager &SM;
18691859
SourceLoc Loc;

0 commit comments

Comments
 (0)