Skip to content

Commit 9c1755c

Browse files
committed
Draft
1 parent e4b130f commit 9c1755c

File tree

10 files changed

+280
-171
lines changed

10 files changed

+280
-171
lines changed

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ using unaligned_decl_id_t =
261261
serialization::DeclID, llvm::endianness::native,
262262
llvm::support::unaligned>;
263263

264+
/// The number of slots needed to record a DeclID in bitstreams.
265+
const unsigned int DeclIDRefSize = 2;
266+
264267
/// The number of predefined preprocessed entity IDs.
265268
const unsigned int NUM_PREDEF_PP_ENTITY_IDS = 1;
266269

clang/include/clang/Serialization/ASTReader.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ class ASTReader
599599

600600
/// An array of lexical contents of a declaration context, as a sequence of
601601
/// Decl::Kind, DeclID pairs.
602-
using LexicalContents = ArrayRef<serialization::unaligned_decl_id_t>;
602+
using LexicalContents = ArrayRef<uint32_t>;
603603

604604
/// Map from a DeclContext to its lexical contents.
605605
llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
@@ -960,7 +960,7 @@ class ASTReader
960960
SmallVector<uint64_t, 8> DelayedDeleteExprs;
961961

962962
// A list of late parsed template function data with their module files.
963-
SmallVector<std::pair<ModuleFile *, SmallVector<uint64_t, 1>>, 4>
963+
SmallVector<std::pair<ModuleFile *, RecordData>, 4>
964964
LateParsedTemplates;
965965

966966
/// The IDs of all decls to be checked for deferred diags.
@@ -1955,12 +1955,12 @@ class ASTReader
19551955
/// given module.
19561956
///
19571957
/// \returns The declaration ID read from the record, adjusted to a global ID.
1958-
GlobalDeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1958+
GlobalDeclID ReadDeclID(ModuleFile &F, const RecordDataImpl &Record,
19591959
unsigned &Idx);
19601960

19611961
/// Reads a declaration from the given position in a record in the
19621962
/// given module.
1963-
Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1963+
Decl *ReadDecl(ModuleFile &F, const RecordDataImpl &R, unsigned &I) {
19641964
return GetDecl(ReadDeclID(F, R, I));
19651965
}
19661966

@@ -1970,7 +1970,7 @@ class ASTReader
19701970
/// \returns The declaration read from this location, casted to the given
19711971
/// result type.
19721972
template<typename T>
1973-
T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1973+
T *ReadDeclAs(ModuleFile &F, const RecordDataImpl &R, unsigned &I) {
19741974
return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
19751975
}
19761976

clang/include/clang/Serialization/ASTRecordReader.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,27 @@ class ASTRecordReader
187187
/// Reads a declaration from the given position in a record in the
188188
/// given module, advancing Idx.
189189
Decl *readDecl() {
190+
#ifndef NDEBUG
191+
unsigned OldIdx = Idx;
192+
Decl *D = Reader->ReadDecl(*F, Record, Idx);
193+
assert(Idx - OldIdx == serialization::DeclIDRefSize);
194+
return D;
195+
#endif
190196
return Reader->ReadDecl(*F, Record, Idx);
191197
}
192198
Decl *readDeclRef() {
193199
return readDecl();
194200
}
195201

202+
template <class DeclKind, class Func>
203+
void readDeclArray(Func &&ConsumeFunc) {
204+
unsigned LengthOfArray = readInt();
205+
unsigned End = Idx + LengthOfArray;
206+
207+
while (Idx < End)
208+
ConsumeFunc(readDeclAs<DeclKind>());
209+
}
210+
196211
/// Reads a declaration from the given position in the record,
197212
/// advancing Idx.
198213
///

clang/include/clang/Serialization/ASTRecordWriter.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,40 @@ class ASTRecordWriter
234234

235235
/// Emit a reference to a declaration.
236236
void AddDeclRef(const Decl *D) {
237+
#ifndef NDEBUG
238+
unsigned OldSize = size();
239+
Writer->AddDeclRef(D, *Record);
240+
assert(size() - OldSize == serialization::DeclIDRefSize);
241+
return;
242+
#endif
237243
return Writer->AddDeclRef(D, *Record);
238244
}
239245
void writeDeclRef(const Decl *D) {
240246
AddDeclRef(D);
241247
}
242248

249+
void writeNullDeclRef() {
250+
#ifndef NDEBUG
251+
unsigned OldSize = size();
252+
#endif
253+
254+
push_back(0);
255+
push_back(0);
256+
257+
#ifndef NDEBUG
258+
assert(size() - OldSize == serialization::DeclIDRefSize);
259+
#endif
260+
}
261+
262+
template <class DeclKind>
263+
void writeDeclArray(ArrayRef<DeclKind *> Array) {
264+
unsigned ElementNum = Array.size();
265+
push_back(ElementNum * serialization::DeclIDRefSize);
266+
267+
for (DeclKind *D : Array)
268+
AddDeclRef(D);
269+
}
270+
243271
/// Emit a declaration name.
244272
void AddDeclarationName(DeclarationName Name) {
245273
writeDeclarationName(Name);

0 commit comments

Comments
 (0)