@@ -35,32 +35,55 @@ using namespace ast_scope;
35
35
36
36
static SourceLoc getStartOfFirstParam (ClosureExpr *closure);
37
37
38
- SourceRange ASTScopeImpl::getSourceRange (bool forDebugging ) const {
39
- if (forDebugging && !cachedSourceRange)
38
+ SourceRange ASTScopeImpl::getSourceRange (const bool omitAssertions ) const {
39
+ if (omitAssertions && !cachedSourceRange)
40
40
return SourceRange ();
41
41
assert (cachedSourceRange && " should have been cached after last expandMe" );
42
42
return *cachedSourceRange;
43
43
}
44
44
45
- SourceRange ASTScopeImpl::getUncachedSourceRange (bool forDebugging) const {
46
- auto childlessRange = getChildlessSourceRange ();
45
+ SourceRange
46
+ ASTScopeImpl::getUncachedSourceRange (const bool omitAssertions) const {
47
+ const auto childlessRange = getChildlessSourceRange ();
48
+ const auto rangeIncludingIgnoredNodes =
49
+ widenSourceRangeForIgnoredASTNodes (childlessRange);
50
+ return widenSourceRangeForChildren (rangeIncludingIgnoredNodes,
51
+ omitAssertions);
52
+ }
53
+
54
+ SourceRange ASTScopeImpl::widenSourceRangeForIgnoredASTNodes (
55
+ const SourceRange range) const {
56
+ if (range.isInvalid ())
57
+ return sourceRangeOfIgnoredASTNodes;
58
+ auto r = range;
47
59
if (sourceRangeOfIgnoredASTNodes.isValid ())
48
- childlessRange.widen (sourceRangeOfIgnoredASTNodes);
60
+ r.widen (sourceRangeOfIgnoredASTNodes);
61
+ return r;
62
+ }
63
+
64
+ SourceRange
65
+ ASTScopeImpl::widenSourceRangeForChildren (const SourceRange range,
66
+ bool omitAssertions) const {
49
67
if (getChildren ().empty ()) {
50
- assert (childlessRange .Start .isValid ());
51
- return childlessRange ;
68
+ assert (omitAssertions || range .Start .isValid ());
69
+ return range ;
52
70
}
71
+ // If we change the caching to compute the source range lazily,
72
+ // the only children required here would be the first and last.
53
73
for (auto *c: getChildren ())
54
74
c->cacheSourceRange ();
75
+
55
76
const auto childStart =
56
- getChildren ().front ()->getSourceRange (forDebugging ).Start ;
57
- assert (forDebugging || childStart. isValid ());
58
- const auto childEnd = getChildren ().back ()->getSourceRange (forDebugging ).End ;
77
+ getChildren ().front ()->getSourceRange (omitAssertions ).Start ;
78
+ const auto childEnd =
79
+ getChildren ().back ()->getSourceRange (omitAssertions ).End ;
59
80
auto childRange = SourceRange (childStart, childEnd);
60
- if (childlessRange.Start .isInvalid ())
81
+ assert (omitAssertions || childRange.isValid ());
82
+
83
+ if (range.isInvalid ())
61
84
return childRange;
62
- auto r = childRange ;
63
- r.widen (childlessRange );
85
+ auto r = range ;
86
+ r.widen (childRange );
64
87
return r;
65
88
}
66
89
0 commit comments