Skip to content

Commit 3161a77

Browse files
authored
Merge pull request #5686 from nkcsgexi/range-info-assertion
2 parents 74e73b3 + 0e7b13a commit 3161a77

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,12 @@ struct RangeResolver::Implementation {
217217
public:
218218
Implementation(SourceFile &File, SourceLoc Start, SourceLoc End) :
219219
File(File), Start(Start), End(End), Content(getContent()) {}
220-
~Implementation() { assert(ContextStack.empty()); }
221220
bool hasResult() { return Result.hasValue(); }
222221
void enter(ASTNode Node) { ContextStack.emplace_back(Node); }
223-
void leave() { ContextStack.pop_back(); }
222+
void leave(ASTNode Node) {
223+
assert(ContextStack.back().Parent.getOpaqueValue() == Node.getOpaqueValue());
224+
ContextStack.pop_back();
225+
}
224226

225227
void analyze(ASTNode Node) {
226228
auto &DCInfo = getCurrentDC();
@@ -245,6 +247,8 @@ struct RangeResolver::Implementation {
245247

246248
bool shouldEnter(ASTNode Node) {
247249
SourceManager &SM = File.getASTContext().SourceMgr;
250+
if (hasResult())
251+
return false;
248252
if (SM.isBeforeInBuffer(End, Node.getSourceRange().Start))
249253
return false;
250254
if (SM.isBeforeInBuffer(Node.getSourceRange().End, Start))
@@ -288,44 +292,43 @@ bool RangeResolver::walkToExprPre(Expr *E) {
288292
return false;
289293
Impl.analyze(E);
290294
Impl.enter(E);
291-
return !Impl.hasResult();
295+
return true;
292296
}
293297

294298
bool RangeResolver::walkToStmtPre(Stmt *S) {
295299
if (!Impl.shouldEnter(S))
296300
return false;
297301
Impl.analyze(S);
298302
Impl.enter(S);
299-
return !Impl.hasResult();
303+
return true;
300304
};
301305

302306
bool RangeResolver::walkToDeclPre(Decl *D, CharSourceRange Range) {
303307
if (!Impl.shouldEnter(D))
304308
return false;
305309
Impl.analyze(D);
306310
Impl.enter(D);
307-
return !Impl.hasResult();
311+
return true;
308312
}
309313

310314
bool RangeResolver::walkToExprPost(Expr *E) {
311-
Impl.leave();
315+
Impl.leave(E);
312316
return !Impl.hasResult();
313317
}
314318

315319
bool RangeResolver::walkToStmtPost(Stmt *S) {
316-
Impl.leave();
320+
Impl.leave(S);
317321
return !Impl.hasResult();
318322
};
319323

320324
bool RangeResolver::walkToDeclPost(Decl *D) {
321-
Impl.leave();
325+
Impl.leave(D);
322326
return !Impl.hasResult();
323327
}
324328

325329
ResolvedRangeInfo RangeResolver::resolve() {
326330
Impl.enter(ASTNode());
327331
walk(Impl.File);
328-
Impl.leave();
329332
return Impl.getResult();
330333
}
331334

0 commit comments

Comments
 (0)