34#include "llvm/Support/MathExtras.h"
37#ifndef LLVM_CLANG_SERIALIZATION_SOURCELOCATIONENCODING_H
38#define LLVM_CLANG_SERIALIZATION_SOURCELOCATIONENCODING_H
41class SourceLocationSequence;
49 constexpr static unsigned UIntBits =
CHAR_BIT *
sizeof(UIntTy);
51 static UIntTy encodeRaw(UIntTy Raw) {
52 return (Raw << 1) | (Raw >> (UIntBits - 1));
54 static UIntTy decodeRaw(UIntTy Raw) {
55 return (Raw >> 1) | (Raw << (UIntBits - 1));
63 unsigned BaseModuleFileIndex,
65 static std::pair<SourceLocation, unsigned>
98 using EncodedTy = uint64_t;
99 constexpr static auto UIntBits = SourceLocationEncoding::UIntBits;
100 static_assert(
sizeof(EncodedTy) >
sizeof(UIntTy),
"Need one extra bit!");
107 static UIntTy zigZag(UIntTy
V) {
108 UIntTy Sign = (
V & (1 << (UIntBits - 1))) ? UIntTy(-1) : UIntTy(0);
109 return Sign ^ (
V << 1);
111 static UIntTy zagZig(UIntTy
V) {
return (
V >> 1) ^ -(
V & 1); }
115 EncodedTy encodeRaw(UIntTy Raw) {
118 UIntTy Rotated = SourceLocationEncoding::encodeRaw(Raw);
120 return Prev = Rotated;
121 UIntTy Delta = Rotated - Prev;
125 return 1 + EncodedTy{zigZag(Delta)};
127 UIntTy decodeRaw(EncodedTy Encoded) {
131 return SourceLocationEncoding::decodeRaw(Prev = Encoded);
132 return SourceLocationEncoding::decodeRaw(Prev += zagZig(Encoded - 1));
140 return encodeRaw(
Loc.getRawEncoding());
163 unsigned BaseModuleFileIndex,
168 return Seq ?
Seq->encode(
Loc) : encodeRaw(
Loc.getRawEncoding());
176 assert(
Loc.getOffset() >= BaseOffset);
177 Loc =
Loc.getLocWithOffset(-BaseOffset);
181 assert(BaseModuleFileIndex < (1 << 16));
185inline std::pair<SourceLocation, unsigned>
188 unsigned ModuleFileIndex = Encoded >> 32;
190 if (!ModuleFileIndex)
191 return {
Seq ?
Seq->decode(Encoded)
195 Encoded &= llvm::maskTrailingOnes<RawLocEncoding>(32);
198 return {
Loc, ModuleFileIndex};
Defines the clang::SourceLocation class and associated facilities.
Serialized encoding of SourceLocations without context.
static RawLocEncoding encode(SourceLocation Loc, UIntTy BaseOffset, unsigned BaseModuleFileIndex, SourceLocationSequence *=nullptr)
static std::pair< SourceLocation, unsigned > decode(RawLocEncoding, 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.
The JSON file list parser is used to communicate input to InstallAPI.
@ Seq
'seq' clause, allowed on 'loop' and 'routine' directives.