Skip to content

Commit 3ce3d23

Browse files
committed
Standardize the reader methods in ASTReader; NFC.
There are three significant changes here: - Most of the methods to read various embedded structures (`APInt`, `NestedNameSpecifier`, `DeclarationName`, etc.) have been moved from `ASTReader` to `ASTRecordReader`. This cleans up quite a bit of code which was passing around `(F, Record, Idx)` arguments everywhere or doing explicit indexing, and it nicely parallels how it works on the writer side. It also sets us up to then move most of these methods into the `BasicReader`s that I'm introducing as part of abstract serialization. As part of this, several of the top-level reader methods (e.g. `readTypeRecord`) have been converted to use `ASTRecordReader` internally, which is a nice readability improvement. - I've standardized most of these method names on `readFoo` rather than `ReadFoo` (used in some of the helper structures) or `GetFoo` (used for some specific types for no apparent reason). - I've changed a few of these methods to return their result instead of reading into an argument passed by reference. This is partly for general consistency and partly because it will make the metaprogramming easier with abstract serialization.
1 parent 139006c commit 3ce3d23

File tree

5 files changed

+1028
-1260
lines changed

5 files changed

+1028
-1260
lines changed

clang/include/clang/Serialization/ASTReader.h

Lines changed: 49 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,10 +1345,6 @@ class ASTReader
13451345
};
13461346

13471347
QualType readTypeRecord(unsigned Index);
1348-
void readExceptionSpec(ModuleFile &ModuleFile,
1349-
SmallVectorImpl<QualType> &ExceptionStorage,
1350-
FunctionProtoType::ExceptionSpecInfo &ESI,
1351-
const RecordData &Record, unsigned &Index);
13521348
RecordLocation TypeCursorForIndex(unsigned Index);
13531349
void LoadedDecl(unsigned Index, Decl *D);
13541350
Decl *ReadDeclRecord(serialization::DeclID ID);
@@ -1781,29 +1777,6 @@ class ASTReader
17811777
return Result;
17821778
}
17831779

1784-
/// Reads a TemplateArgumentLocInfo appropriate for the
1785-
/// given TemplateArgument kind.
1786-
TemplateArgumentLocInfo
1787-
GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1788-
const RecordData &Record, unsigned &Idx);
1789-
1790-
/// Reads a TemplateArgumentLoc.
1791-
TemplateArgumentLoc
1792-
ReadTemplateArgumentLoc(ModuleFile &F,
1793-
const RecordData &Record, unsigned &Idx);
1794-
1795-
const ASTTemplateArgumentListInfo*
1796-
ReadASTTemplateArgumentListInfo(ModuleFile &F,
1797-
const RecordData &Record, unsigned &Index);
1798-
1799-
/// Reads a declarator info from the given record.
1800-
TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1801-
const RecordData &Record, unsigned &Idx);
1802-
1803-
/// Raad the type locations for the given TInfo.
1804-
void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx,
1805-
TypeLoc TL);
1806-
18071780
/// Resolve a type ID into a type, potentially building a new
18081781
/// type.
18091782
QualType GetType(serialization::TypeID ID);
@@ -2057,8 +2030,8 @@ class ASTReader
20572030

20582031
IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
20592032

2060-
IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
2061-
unsigned &Idx) {
2033+
IdentifierInfo *readIdentifier(ModuleFile &M, const RecordData &Record,
2034+
unsigned &Idx) {
20622035
return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
20632036
}
20642037

@@ -2136,58 +2109,6 @@ class ASTReader
21362109
serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
21372110
unsigned LocalID) const;
21382111

2139-
/// Read a declaration name.
2140-
DeclarationName ReadDeclarationName(ModuleFile &F,
2141-
const RecordData &Record, unsigned &Idx);
2142-
void ReadDeclarationNameLoc(ModuleFile &F,
2143-
DeclarationNameLoc &DNLoc, DeclarationName Name,
2144-
const RecordData &Record, unsigned &Idx);
2145-
void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
2146-
const RecordData &Record, unsigned &Idx);
2147-
2148-
void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
2149-
const RecordData &Record, unsigned &Idx);
2150-
2151-
NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
2152-
const RecordData &Record,
2153-
unsigned &Idx);
2154-
2155-
NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
2156-
const RecordData &Record,
2157-
unsigned &Idx);
2158-
2159-
/// Read a template name.
2160-
TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
2161-
unsigned &Idx);
2162-
2163-
/// Read a template argument.
2164-
TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record,
2165-
unsigned &Idx,
2166-
bool Canonicalize = false);
2167-
2168-
/// Read a template parameter list.
2169-
TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
2170-
const RecordData &Record,
2171-
unsigned &Idx);
2172-
2173-
/// Read a template argument array.
2174-
void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2175-
ModuleFile &F, const RecordData &Record,
2176-
unsigned &Idx, bool Canonicalize = false);
2177-
2178-
/// Read a UnresolvedSet structure.
2179-
void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
2180-
const RecordData &Record, unsigned &Idx);
2181-
2182-
/// Read a C++ base specifier.
2183-
CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
2184-
const RecordData &Record,unsigned &Idx);
2185-
2186-
/// Read a CXXCtorInitializer array.
2187-
CXXCtorInitializer **
2188-
ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
2189-
unsigned &Idx);
2190-
21912112
/// Read the contents of a CXXCtorInitializer array.
21922113
CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
21932114

@@ -2227,19 +2148,6 @@ class ASTReader
22272148
SourceRange ReadSourceRange(ModuleFile &F,
22282149
const RecordData &Record, unsigned &Idx);
22292150

2230-
/// Read an integral value
2231-
llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
2232-
2233-
/// Read a signed integral value
2234-
llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
2235-
2236-
/// Read a floating-point value
2237-
llvm::APFloat ReadAPFloat(const RecordData &Record,
2238-
const llvm::fltSemantics &Sem, unsigned &Idx);
2239-
2240-
/// Read an APValue
2241-
APValue ReadAPValue(const RecordData &Record, unsigned &Idx);
2242-
22432151
// Read a string
22442152
static std::string ReadString(const RecordData &Record, unsigned &Idx);
22452153

@@ -2266,12 +2174,6 @@ class ASTReader
22662174
CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
22672175
unsigned &Idx);
22682176

2269-
/// Reads one attribute from the current stream position.
2270-
Attr *ReadAttr(ModuleFile &M, const RecordData &Record, unsigned &Idx);
2271-
2272-
/// Reads attributes from the current stream position.
2273-
void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs);
2274-
22752177
/// Reads a statement.
22762178
Stmt *ReadStmt(ModuleFile &F);
22772179

@@ -2414,15 +2316,21 @@ class ASTRecordReader {
24142316
/// An arbitrary index in this record.
24152317
const uint64_t &operator[](size_t N) { return Record[N]; }
24162318

2417-
/// The last element in this record.
2418-
const uint64_t &back() const { return Record.back(); }
2319+
/// Returns the last value in this record.
2320+
uint64_t back() { return Record.back(); }
24192321

24202322
/// Returns the current value in this record, and advances to the
24212323
/// next value.
2422-
const uint64_t &readInt() { return Record[Idx++]; }
2324+
uint64_t readInt() { return Record[Idx++]; }
2325+
2326+
ArrayRef<uint64_t> readIntArray(unsigned Len) {
2327+
auto Array = llvm::makeArrayRef(Record).slice(Idx, Len);
2328+
Idx += Len;
2329+
return Array;
2330+
}
24232331

24242332
/// Returns the current value in this record, without advancing.
2425-
const uint64_t &peekInt() { return Record[Idx]; }
2333+
uint64_t peekInt() { return Record[Idx]; }
24262334

24272335
/// Skips the specified number of values.
24282336
void skipInts(unsigned N) { Idx += N; }
@@ -2459,10 +2367,8 @@ class ASTRecordReader {
24592367
static_cast<ExplicitSpecKind>(Kind));
24602368
}
24612369

2462-
void readExceptionSpec(SmallVectorImpl<QualType> &ExceptionStorage,
2463-
FunctionProtoType::ExceptionSpecInfo &ESI) {
2464-
return Reader->readExceptionSpec(*F, ExceptionStorage, ESI, Record, Idx);
2465-
}
2370+
FunctionProtoType::ExceptionSpecInfo
2371+
readExceptionSpecInfo(SmallVectorImpl<QualType> &ExceptionStorage);
24662372

24672373
/// Get the global offset corresponding to a local offset.
24682374
uint64_t getGlobalBitOffset(uint32_t LocalOffset) {
@@ -2492,36 +2398,30 @@ class ASTRecordReader {
24922398
/// Reads a TemplateArgumentLocInfo appropriate for the
24932399
/// given TemplateArgument kind, advancing Idx.
24942400
TemplateArgumentLocInfo
2495-
getTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) {
2496-
return Reader->GetTemplateArgumentLocInfo(*F, Kind, Record, Idx);
2497-
}
2401+
readTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind);
24982402

24992403
/// Reads a TemplateArgumentLoc, advancing Idx.
2500-
TemplateArgumentLoc
2501-
readTemplateArgumentLoc() {
2502-
return Reader->ReadTemplateArgumentLoc(*F, Record, Idx);
2503-
}
2404+
TemplateArgumentLoc readTemplateArgumentLoc();
25042405

25052406
const ASTTemplateArgumentListInfo*
2506-
readASTTemplateArgumentListInfo() {
2507-
return Reader->ReadASTTemplateArgumentListInfo(*F, Record, Idx);
2508-
}
2407+
readASTTemplateArgumentListInfo();
25092408

25102409
/// Reads a declarator info from the given record, advancing Idx.
2511-
TypeSourceInfo *getTypeSourceInfo() {
2512-
return Reader->GetTypeSourceInfo(*F, Record, Idx);
2513-
}
2410+
TypeSourceInfo *readTypeSourceInfo();
25142411

25152412
/// Reads the location information for a type.
2516-
void readTypeLoc(TypeLoc TL) {
2517-
return Reader->ReadTypeLoc(*F, Record, Idx, TL);
2518-
}
2413+
void readTypeLoc(TypeLoc TL);
2414+
25192415

25202416
/// Map a local type ID within a given AST file to a global type ID.
25212417
serialization::TypeID getGlobalTypeID(unsigned LocalID) const {
25222418
return Reader->getGlobalTypeID(*F, LocalID);
25232419
}
25242420

2421+
Qualifiers readQualifiers() {
2422+
return Qualifiers::fromOpaqueValue(readInt());
2423+
}
2424+
25252425
/// Read a type from the current position in the record.
25262426
QualType readType() {
25272427
return Reader->readType(*F, Record, Idx);
@@ -2550,8 +2450,8 @@ class ASTRecordReader {
25502450
return Reader->ReadDeclAs<T>(*F, Record, Idx);
25512451
}
25522452

2553-
IdentifierInfo *getIdentifierInfo() {
2554-
return Reader->GetIdentifierInfo(*F, Record, Idx);
2453+
IdentifierInfo *readIdentifier() {
2454+
return Reader->readIdentifier(*F, Record, Idx);
25552455
}
25562456

25572457
/// Read a selector from the Record, advancing Idx.
@@ -2560,64 +2460,37 @@ class ASTRecordReader {
25602460
}
25612461

25622462
/// Read a declaration name, advancing Idx.
2563-
DeclarationName readDeclarationName() {
2564-
return Reader->ReadDeclarationName(*F, Record, Idx);
2565-
}
2566-
void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) {
2567-
return Reader->ReadDeclarationNameLoc(*F, DNLoc, Name, Record, Idx);
2568-
}
2569-
void readDeclarationNameInfo(DeclarationNameInfo &NameInfo) {
2570-
return Reader->ReadDeclarationNameInfo(*F, NameInfo, Record, Idx);
2571-
}
2463+
DeclarationName readDeclarationName();
2464+
DeclarationNameLoc readDeclarationNameLoc(DeclarationName Name);
2465+
DeclarationNameInfo readDeclarationNameInfo();
25722466

2573-
void readQualifierInfo(QualifierInfo &Info) {
2574-
return Reader->ReadQualifierInfo(*F, Info, Record, Idx);
2575-
}
2467+
void readQualifierInfo(QualifierInfo &Info);
25762468

2577-
NestedNameSpecifier *readNestedNameSpecifier() {
2578-
return Reader->ReadNestedNameSpecifier(*F, Record, Idx);
2579-
}
2469+
NestedNameSpecifier *readNestedNameSpecifier();
25802470

2581-
NestedNameSpecifierLoc readNestedNameSpecifierLoc() {
2582-
return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx);
2583-
}
2471+
NestedNameSpecifierLoc readNestedNameSpecifierLoc();
25842472

25852473
/// Read a template name, advancing Idx.
2586-
TemplateName readTemplateName() {
2587-
return Reader->ReadTemplateName(*F, Record, Idx);
2588-
}
2474+
TemplateName readTemplateName();
25892475

25902476
/// Read a template argument, advancing Idx.
2591-
TemplateArgument readTemplateArgument(bool Canonicalize = false) {
2592-
return Reader->ReadTemplateArgument(*F, Record, Idx, Canonicalize);
2593-
}
2477+
TemplateArgument readTemplateArgument(bool Canonicalize = false);
25942478

25952479
/// Read a template parameter list, advancing Idx.
2596-
TemplateParameterList *readTemplateParameterList() {
2597-
return Reader->ReadTemplateParameterList(*F, Record, Idx);
2598-
}
2480+
TemplateParameterList *readTemplateParameterList();
25992481

26002482
/// Read a template argument array, advancing Idx.
26012483
void readTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2602-
bool Canonicalize = false) {
2603-
return Reader->ReadTemplateArgumentList(TemplArgs, *F, Record, Idx,
2604-
Canonicalize);
2605-
}
2484+
bool Canonicalize = false);
26062485

26072486
/// Read a UnresolvedSet structure, advancing Idx.
2608-
void readUnresolvedSet(LazyASTUnresolvedSet &Set) {
2609-
return Reader->ReadUnresolvedSet(*F, Set, Record, Idx);
2610-
}
2487+
void readUnresolvedSet(LazyASTUnresolvedSet &Set);
26112488

26122489
/// Read a C++ base specifier, advancing Idx.
2613-
CXXBaseSpecifier readCXXBaseSpecifier() {
2614-
return Reader->ReadCXXBaseSpecifier(*F, Record, Idx);
2615-
}
2490+
CXXBaseSpecifier readCXXBaseSpecifier();
26162491

26172492
/// Read a CXXCtorInitializer array, advancing Idx.
2618-
CXXCtorInitializer **readCXXCtorInitializers() {
2619-
return Reader->ReadCXXCtorInitializers(*F, Record, Idx);
2620-
}
2493+
CXXCtorInitializer **readCXXCtorInitializers();
26212494

26222495
CXXTemporary *readCXXTemporary() {
26232496
return Reader->ReadCXXTemporary(*F, Record, Idx);
@@ -2633,22 +2506,20 @@ class ASTRecordReader {
26332506
return Reader->ReadSourceRange(*F, Record, Idx);
26342507
}
26352508

2636-
APValue readAPValue() { return Reader->ReadAPValue(Record, Idx); }
2509+
/// Read an arbitrary constant value, advancing Idx.
2510+
APValue readAPValue();
26372511

26382512
/// Read an integral value, advancing Idx.
2639-
llvm::APInt readAPInt() {
2640-
return Reader->ReadAPInt(Record, Idx);
2641-
}
2513+
llvm::APInt readAPInt();
26422514

26432515
/// Read a signed integral value, advancing Idx.
2644-
llvm::APSInt readAPSInt() {
2645-
return Reader->ReadAPSInt(Record, Idx);
2646-
}
2516+
llvm::APSInt readAPSInt();
26472517

26482518
/// Read a floating-point value, advancing Idx.
2649-
llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem) {
2650-
return Reader->ReadAPFloat(Record, Sem,Idx);
2651-
}
2519+
llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem);
2520+
2521+
/// Read a boolean value, advancing Idx.
2522+
bool readBool() { return readInt() != 0; }
26522523

26532524
/// Read a string, advancing Idx.
26542525
std::string readString() {
@@ -2666,14 +2537,10 @@ class ASTRecordReader {
26662537
}
26672538

26682539
/// Reads one attribute from the current stream position, advancing Idx.
2669-
Attr *readAttr() {
2670-
return Reader->ReadAttr(*F, Record, Idx);
2671-
}
2540+
Attr *readAttr();
26722541

26732542
/// Reads attributes from the current stream position, advancing Idx.
2674-
void readAttributes(AttrVec &Attrs) {
2675-
return Reader->ReadAttributes(*this, Attrs);
2676-
}
2543+
void readAttributes(AttrVec &Attrs);
26772544

26782545
/// Reads a token out of a record, advancing Idx.
26792546
Token readToken() {

0 commit comments

Comments
 (0)