clang: include/clang/Serialization/SourceLocationEncoding.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
34#include "llvm/Support/MathExtras.h"
35#include
36
37#ifndef LLVM_CLANG_SERIALIZATION_SOURCELOCATIONENCODING_H
38#define LLVM_CLANG_SERIALIZATION_SOURCELOCATIONENCODING_H
39
41class SourceLocationSequence;
42
43
44
45
46
49 constexpr static unsigned UIntBits = CHAR_BIT * sizeof(UIntTy);
50
51 static UIntTy encodeRaw(UIntTy Raw) {
52 return (Raw << 1) | (Raw >> (UIntBits - 1));
53 }
54 static UIntTy decodeRaw(UIntTy Raw) {
55 return (Raw >> 1) | (Raw << (UIntBits - 1));
56 }
58
59public:
61
63 unsigned BaseModuleFileIndex,
65 static std::pair<SourceLocation, unsigned>
67};
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
98 using EncodedTy = uint64_t;
99 constexpr static auto UIntBits = SourceLocationEncoding::UIntBits;
100 static_assert(sizeof(EncodedTy) > sizeof(UIntTy), "Need one extra bit!");
101
102
103 UIntTy &Prev;
104
105
106
107 static UIntTy zigZag(UIntTy V) {
108 UIntTy Sign = (V & (1 << (UIntBits - 1))) ? UIntTy(-1) : UIntTy(0);
109 return Sign ^ (V << 1);
110 }
111 static UIntTy zagZig(UIntTy V) { return (V >> 1) ^ -(V & 1); }
112
114
115 EncodedTy encodeRaw(UIntTy Raw) {
116 if (Raw == 0)
117 return 0;
118 UIntTy Rotated = SourceLocationEncoding::encodeRaw(Raw);
119 if (Prev == 0)
120 return Prev = Rotated;
121 UIntTy Delta = Rotated - Prev;
122 Prev = Rotated;
123
124
125 return 1 + EncodedTy{zigZag(Delta)};
126 }
127 UIntTy decodeRaw(EncodedTy Encoded) {
128 if (Encoded == 0)
129 return 0;
130 if (Prev == 0)
131 return SourceLocationEncoding::decodeRaw(Prev = Encoded);
132 return SourceLocationEncoding::decodeRaw(Prev += zagZig(Encoded - 1));
133 }
134
135public:
138 }
140 return encodeRaw(Loc.getRawEncoding());
141 }
142
143 class State;
144};
145
146
148 UIntTy Prev = 0;
150
151public:
152
153
156
157
159};
160
163 unsigned BaseModuleFileIndex,
165
166
167 if (!BaseOffset)
168 return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding());
169
170 if (Loc.isInvalid())
171 return 0;
172
173
174
175
176 assert(Loc.getOffset() >= BaseOffset);
177 Loc = Loc.getLocWithOffset(-BaseOffset);
179
180
181 assert(BaseModuleFileIndex < (1 << 16));
182 Encoded |= (RawLocEncoding)BaseModuleFileIndex << 32;
183 return Encoded;
184}
185inline std::pair<SourceLocation, unsigned>
188 unsigned ModuleFileIndex = Encoded >> 32;
189
190 if (!ModuleFileIndex)
191 return {Seq ? Seq->decode(Encoded)
193 ModuleFileIndex};
194
195 Encoded &= llvm::maskTrailingOnes(32);
197
198 return {Loc, ModuleFileIndex};
199}
200
201}
202#endif
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.