Conditionalizing logic based on the exact output stream is brittle
since e.g the client may be writing to an intermediate buffer before
forwarding onto the output. For the ASTDumper itself, the client
already passes whether or not it expects a fully semantic dump, use
that instead. For `printContext`, the only client relying on this
was some `ResolvedRangeInfo` tests, but these don't actually care
about the computed discriminator, adjust the tests to not care.
`SemaAnnotator` walks the tree in source order with respect to the source ranges *excluding* attributes, but `RangeResolver` considers attributes part of their declaration. Thus they disagree on what “walking in source order means”. `SemaAnnotator` will visit the attributes *before* the decl they are on, while `RangeResolver` as currently implemented expects them *as part of* the decl they are on.
Thus, for the purpose of `RangeResolver`, we need to assume that nodes are visited in arbitrary order and we might encounter enclosing nodes after their children.
Thus, when we find a new node, remove all nodes that it encloses from `ContainedASTNodes`.
Fixes rdar://64140713 [SR-12958]
* [RangeInfo] Perform complete walk on the last node in a given range to avoid missing information due to early abort.
* [RangeInfo] For declared decls in a given range, report whether they are referenced outside of the range.
* [RangeInfo] Report the contained (topmost) ASTNodes inside a selected range.