@@ -217,10 +217,12 @@ struct RangeResolver::Implementation {
217
217
public:
218
218
Implementation (SourceFile &File, SourceLoc Start, SourceLoc End) :
219
219
File (File), Start(Start), End(End), Content(getContent()) {}
220
- ~Implementation () { assert (ContextStack.empty ()); }
221
220
bool hasResult () { return Result.hasValue (); }
222
221
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
+ }
224
226
225
227
void analyze (ASTNode Node) {
226
228
auto &DCInfo = getCurrentDC ();
@@ -245,6 +247,8 @@ struct RangeResolver::Implementation {
245
247
246
248
bool shouldEnter (ASTNode Node) {
247
249
SourceManager &SM = File.getASTContext ().SourceMgr ;
250
+ if (hasResult ())
251
+ return false ;
248
252
if (SM.isBeforeInBuffer (End, Node.getSourceRange ().Start ))
249
253
return false ;
250
254
if (SM.isBeforeInBuffer (Node.getSourceRange ().End , Start))
@@ -288,44 +292,43 @@ bool RangeResolver::walkToExprPre(Expr *E) {
288
292
return false ;
289
293
Impl.analyze (E);
290
294
Impl.enter (E);
291
- return !Impl. hasResult () ;
295
+ return true ;
292
296
}
293
297
294
298
bool RangeResolver::walkToStmtPre (Stmt *S) {
295
299
if (!Impl.shouldEnter (S))
296
300
return false ;
297
301
Impl.analyze (S);
298
302
Impl.enter (S);
299
- return !Impl. hasResult () ;
303
+ return true ;
300
304
};
301
305
302
306
bool RangeResolver::walkToDeclPre (Decl *D, CharSourceRange Range) {
303
307
if (!Impl.shouldEnter (D))
304
308
return false ;
305
309
Impl.analyze (D);
306
310
Impl.enter (D);
307
- return !Impl. hasResult () ;
311
+ return true ;
308
312
}
309
313
310
314
bool RangeResolver::walkToExprPost (Expr *E) {
311
- Impl.leave ();
315
+ Impl.leave (E );
312
316
return !Impl.hasResult ();
313
317
}
314
318
315
319
bool RangeResolver::walkToStmtPost (Stmt *S) {
316
- Impl.leave ();
320
+ Impl.leave (S );
317
321
return !Impl.hasResult ();
318
322
};
319
323
320
324
bool RangeResolver::walkToDeclPost (Decl *D) {
321
- Impl.leave ();
325
+ Impl.leave (D );
322
326
return !Impl.hasResult ();
323
327
}
324
328
325
329
ResolvedRangeInfo RangeResolver::resolve () {
326
330
Impl.enter (ASTNode ());
327
331
walk (Impl.File );
328
- Impl.leave ();
329
332
return Impl.getResult ();
330
333
}
331
334
0 commit comments