32#ifndef LLVM_CLANG_SERIALIZATION_SOURCELOCATIONENCODING_H
33#define LLVM_CLANG_SERIALIZATION_SOURCELOCATIONENCODING_H
36class SourceLocationSequence;
44 constexpr static unsigned UIntBits =
CHAR_BIT *
sizeof(UIntTy);
46 static UIntTy encodeRaw(UIntTy Raw) {
47 return (Raw << 1) | (Raw >> (UIntBits - 1));
49 static UIntTy decodeRaw(UIntTy Raw) {
50 return (Raw >> 1) | (Raw << (UIntBits - 1));
89 using EncodedTy = uint64_t;
90 constexpr static auto UIntBits = SourceLocationEncoding::UIntBits;
91 static_assert(
sizeof(EncodedTy) >
sizeof(UIntTy),
"Need one extra bit!");
98 static UIntTy zigZag(UIntTy
V) {
99 UIntTy Sign = (
V & (1 << (UIntBits - 1))) ? UIntTy(-1) : UIntTy(0);
100 return Sign ^ (
V << 1);
102 static UIntTy zagZig(UIntTy
V) {
return (
V >> 1) ^ -(
V & 1); }
106 EncodedTy encodeRaw(UIntTy Raw) {
109 UIntTy Rotated = SourceLocationEncoding::encodeRaw(Raw);
111 return Prev = Rotated;
112 UIntTy Delta = Rotated - Prev;
116 return 1 + EncodedTy{zigZag(Delta)};
118 UIntTy decodeRaw(EncodedTy Encoded) {
122 return SourceLocationEncoding::decodeRaw(Prev = Encoded);
123 return SourceLocationEncoding::decodeRaw(Prev += zagZig(Encoded - 1));
158 return Seq ? Seq->
decode(Encoded)
Defines the clang::SourceLocation class and associated facilities.
Serialized encoding of SourceLocations without context.
static SourceLocation decode(uint64_t, SourceLocationSequence *=nullptr)
static uint64_t encode(SourceLocation Loc, SourceLocationSequence *=nullptr)
This object establishes a SourceLocationSequence.
State(SourceLocationSequence *Parent=nullptr)
Serialized encoding of a sequence of SourceLocations.
EncodedTy encode(SourceLocation Loc)
SourceLocation decode(EncodedTy Encoded)
Encodes a location in the source.
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
UIntTy getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it.