struct Location size
Johan
j at j.nl
Tue May 9 17:16:51 UTC 2023
On Tuesday, 9 May 2023 at 09:35:41 UTC, Dennis wrote:
> On Tuesday, 9 May 2023 at 00:24:44 UTC, Walter Bright wrote:
>> So, for great glory, can anyone come up with a clever scheme
>> that uses only 32 bits?
>
> I put mine in the PR already:
> https://github.com/dlang/dmd/pull/15199#issuecomment-1538120181
>
> It's the same idea as Adam's. You really only need a file
> offset, which currently already exists, but only for DMD as a
> lib:
>
> ```D
> version (LocOffset)
> uint fileOffset; /// utf8 code unit index relative to start
> of file, starting from 0
> ```
>
> Line number and column number can be computed when needed, and
> can be accelerated with a binary search in a list of line
> numbers sorted by file offset (because of #line directives
> lines won't be monotonically increasing and need to be stored
> in the list).
FYI, this is indeed what Clang does. 32-bit offset, with a
"SourceManager" to help convert the ID back to file:line.
https://github.com/llvm/llvm-project/blob/ec77d1f3d9fcf7105b6bda25fb4d0e5ed5afd0c5/clang/include/clang/Basic/SourceLocation.h#L71-L86
-Johan
More information about the Digitalmars-d
mailing list