mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
libSyntax nodes don't maintain absolute source location on each individual node. Instead, the absolute locations are calculated on demand with a given root by accumulating the length of all the other nodes before the target node. This bridging is important for issuing diagnostics from libSyntax entities. With the observation that our current implementation of the source location calculation has multiple bugs, this patch re-implemented this bridging by using the newly-added syntax visitor. Also, we moved the function from RawSyntax to Syntax for better visibility. To test this source location calculation, we added a new action in swift-syntax-test. This action parses a given file as a SourceFileSyntax, calculates the absolute location of the EOF token in the SourceFileSyntax, and dump the buffer from the start of the input file to the absolute location of the EOF. Finally, we compare the dump with the original input to ensure they are identical.
10 KiB
10 KiB