31#ifndef LLVM_CLANG_SERIALIZATION_SOURCELOCATIONENCODING_H
32#define LLVM_CLANG_SERIALIZATION_SOURCELOCATIONENCODING_H
35#include "llvm/Support/MathExtras.h"
46 constexpr static unsigned UIntBits =
CHAR_BIT *
sizeof(UIntTy);
48 static UIntTy encodeRaw(UIntTy Raw) {
49 return (Raw << 1) | (Raw >> (UIntBits - 1));
51 static UIntTy decodeRaw(UIntTy Raw) {
52 return (Raw >> 1) | (Raw << (UIntBits - 1));
59 unsigned BaseModuleFileIndex);
116 static UIntTy zigZag(UIntTy
V) {
117 return (
V << 1) ^ (UIntTy(0) - (
V >> (UIntBits - 1)));
121 static UIntTy zagZig(UIntTy
V) {
return (
V >> 1) ^ (UIntTy(0) - (
V & 1)); }
124 UIntTy hole()
const {
return zigZag(UIntTy(0) - Prev); }
127 explicit Chain(UIntTy AnchorOffset) : Prev(encodeRaw(AnchorOffset)) {
132 assert(AnchorOffset != 0 &&
"Chain anchor should be non-zero");
145 UIntTy SL =
static_cast<UIntTy
>(
V);
146 UIntTy E = zigZag(SL - Prev);
148 assert(E != H &&
"Non-zero location cannot be mapped to the hole");
150 return E < H ? static_cast<RawLocEncoding>(E) + 1 : E;
164 UIntTy D =
static_cast<UIntTy
>(
V);
165 Prev += zagZig(D <= H ? D - 1 : D);
173 unsigned BaseModuleFileIndex) {
184 assert(Loc.getOffset() >= BaseOffset);
189 assert(BaseModuleFileIndex < (1 << 16));
193inline std::pair<SourceLocation, unsigned>
195 unsigned ModuleFileIndex = Encoded >> 32;
197 if (!ModuleFileIndex)
201 Encoded &= llvm::maskTrailingOnes<RawLocEncoding>(32);
204 return {Loc, ModuleFileIndex};
Defines the clang::SourceLocation class and associated facilities.
Chain(UIntTy AnchorOffset)
RawLocEncoding deltaDecode(RawLocEncoding V)
RawLocEncoding deltaEncode(RawLocEncoding V)
Serialized encoding of SourceLocations without context.
static RawLocEncoding encode(SourceLocation Loc, UIntTy BaseOffset, unsigned BaseModuleFileIndex)
static std::pair< SourceLocation, unsigned > decode(RawLocEncoding)
Encodes a location in the source.
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
UIntTy getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it.
Top level wrappers for InstallAPI frontend operations.