@@ -356,14 +356,15 @@ class ASTReader
356
356
// / \brief The AST file has errors.
357
357
HadErrors
358
358
};
359
-
359
+
360
360
// / \brief Types of AST files.
361
361
friend class PCHValidator ;
362
362
friend class ASTDeclReader ;
363
363
friend class ASTStmtReader ;
364
364
friend class ASTIdentifierIterator ;
365
365
friend class serialization ::reader::ASTIdentifierLookupTrait;
366
366
friend class TypeLocReader ;
367
+ friend class ASTRecordReader ;
367
368
friend class ASTWriter ;
368
369
friend class ASTUnit ; // ASTUnit needs to remap source locations.
369
370
friend class serialization ::ReadMethodPoolVisitor;
@@ -1939,7 +1940,7 @@ class ASTReader
1939
1940
// / number.
1940
1941
serialization::SubmoduleID
1941
1942
getGlobalSubmoduleID (ModuleFile &M, unsigned LocalID);
1942
-
1943
+
1943
1944
// / \brief Retrieve the submodule that corresponds to a global submodule ID.
1944
1945
// /
1945
1946
Module *getSubmodule (serialization::SubmoduleID GlobalID);
@@ -2183,6 +2184,280 @@ class ASTReader
2183
2184
bool isProcessingUpdateRecords () { return ProcessingUpdateRecords; }
2184
2185
};
2185
2186
2187
+ // / \brief An object for streaming information from a record.
2188
+ class ASTRecordReader {
2189
+ typedef serialization::ModuleFile ModuleFile;
2190
+
2191
+ ASTReader *Reader;
2192
+ const ASTReader::RecordData *Record;
2193
+ ModuleFile *F;
2194
+
2195
+ typedef ASTReader::RecordData RecordData;
2196
+ typedef ASTReader::RecordDataImpl RecordDataImpl;
2197
+
2198
+ public:
2199
+ // / Construct an ASTRecordReader that uses the default encoding scheme.
2200
+ ASTRecordReader (ASTReader &Reader, const ASTReader::RecordData &Record,
2201
+ ModuleFile& F)
2202
+ : Reader(&Reader), Record(&Record), F(&F) {}
2203
+
2204
+ // / Construct an ASTRecordReader that uses the same encoding scheme as another
2205
+ // / ASTRecordReader.
2206
+ ASTRecordReader (ASTRecordReader &Parent)
2207
+ : Reader(Parent.Reader), Record(Parent.Record), F(Parent.F) {}
2208
+
2209
+ // / \brief The length of this record.
2210
+ size_t size () const { return Record->size (); }
2211
+ // / \brief An arbitrary index in this record.
2212
+ const uint64_t &operator [](size_t N) { return (*Record)[N]; }
2213
+ // / \brief The last element in this record.
2214
+ const uint64_t &back () const { return Record->back (); }
2215
+
2216
+ // / \brief Is this a module file for a module (rather than a PCH or similar).
2217
+ bool isModule () const { return F->isModule (); }
2218
+
2219
+ // / \brief Retrieve the AST context that this AST reader supplements.
2220
+ ASTContext &getContext () { return Reader->getContext (); }
2221
+
2222
+ // / \brief Retrieve the global submodule ID its local ID number.
2223
+ serialization::SubmoduleID
2224
+ getGlobalSubmoduleID (unsigned LocalID) {
2225
+ return Reader->getGlobalSubmoduleID (*F, LocalID);
2226
+ }
2227
+
2228
+ // / \brief Retrieve the submodule that corresponds to a global submodule ID.
2229
+ Module *getSubmodule (serialization::SubmoduleID GlobalID) {
2230
+ return Reader->getSubmodule (GlobalID);
2231
+ }
2232
+
2233
+ // / \brief Read the record that describes the lexical contents of a DC.
2234
+ bool ReadLexicalDeclContextStorage (uint64_t Offset, DeclContext *DC) {
2235
+ return Reader->ReadLexicalDeclContextStorage (*F, F->DeclsCursor , Offset,
2236
+ DC);
2237
+ }
2238
+
2239
+ // / \brief Read the record that describes the visible contents of a DC.
2240
+ bool ReadVisibleDeclContextStorage (uint64_t Offset,
2241
+ serialization::DeclID ID) {
2242
+ return Reader->ReadVisibleDeclContextStorage (*F, F->DeclsCursor , Offset,
2243
+ ID);
2244
+ }
2245
+
2246
+ void readExceptionSpec (SmallVectorImpl<QualType> &ExceptionStorage,
2247
+ FunctionProtoType::ExceptionSpecInfo &ESI,
2248
+ unsigned &Index) {
2249
+ return Reader->readExceptionSpec (*F, ExceptionStorage, ESI, *Record, Index);
2250
+ }
2251
+
2252
+ // / \brief Get the global offset corresponding to a local offset.
2253
+ uint64_t getGlobalBitOffset (uint32_t LocalOffset) {
2254
+ return Reader->getGlobalBitOffset (*F, LocalOffset);
2255
+ }
2256
+
2257
+ // / \brief Reads a statement.
2258
+ Stmt *ReadStmt () { return Reader->ReadStmt (*F); }
2259
+
2260
+ // / \brief Reads an expression.
2261
+ Expr *ReadExpr () { return Reader->ReadExpr (*F); }
2262
+
2263
+ // / \brief Reads a sub-statement operand during statement reading.
2264
+ Stmt *ReadSubStmt () { return Reader->ReadSubStmt (); }
2265
+
2266
+ // / \brief Reads a sub-expression operand during statement reading.
2267
+ Expr *ReadSubExpr () { return Reader->ReadSubExpr (); }
2268
+
2269
+ // / \brief Reads a TemplateArgumentLocInfo appropriate for the
2270
+ // / given TemplateArgument kind, advancing Idx.
2271
+ TemplateArgumentLocInfo
2272
+ GetTemplateArgumentLocInfo (TemplateArgument::ArgKind Kind, unsigned &Idx) {
2273
+ return Reader->GetTemplateArgumentLocInfo (*F, Kind, *Record, Idx);
2274
+ }
2275
+
2276
+ // / \brief Reads a TemplateArgumentLoc, advancing Idx.
2277
+ TemplateArgumentLoc
2278
+ ReadTemplateArgumentLoc (unsigned &Idx) {
2279
+ return Reader->ReadTemplateArgumentLoc (*F, *Record, Idx);
2280
+ }
2281
+
2282
+ const ASTTemplateArgumentListInfo*
2283
+ ReadASTTemplateArgumentListInfo (unsigned &Idx) {
2284
+ return Reader->ReadASTTemplateArgumentListInfo (*F, *Record, Idx);
2285
+ }
2286
+
2287
+ // / \brief Reads a declarator info from the given record, advancing Idx.
2288
+ TypeSourceInfo *GetTypeSourceInfo (unsigned &Idx) {
2289
+ return Reader->GetTypeSourceInfo (*F, *Record, Idx);
2290
+ }
2291
+
2292
+ // / \brief Map a local type ID within a given AST file to a global type ID.
2293
+ serialization::TypeID getGlobalTypeID (unsigned LocalID) const {
2294
+ return Reader->getGlobalTypeID (*F, LocalID);
2295
+ }
2296
+
2297
+ // / \brief Read a type from the current position in the record.
2298
+ QualType readType (unsigned &Idx) {
2299
+ return Reader->readType (*F, *Record, Idx);
2300
+ }
2301
+
2302
+ // / \brief Reads a declaration ID from the given position in this record.
2303
+ // /
2304
+ // / \returns The declaration ID read from the record, adjusted to a global ID.
2305
+ serialization::DeclID ReadDeclID (unsigned &Idx) {
2306
+ return Reader->ReadDeclID (*F, *Record, Idx);
2307
+ }
2308
+
2309
+ // / \brief Reads a declaration from the given position in a record in the
2310
+ // / given module, advancing Idx.
2311
+ Decl *ReadDecl (unsigned &Idx) {
2312
+ return Reader->ReadDecl (*F, *Record, Idx);
2313
+ }
2314
+
2315
+ // / \brief Reads a declaration from the given position in the record,
2316
+ // / advancing Idx.
2317
+ // /
2318
+ // / \returns The declaration read from this location, casted to the given
2319
+ // / result type.
2320
+ template <typename T>
2321
+ T *ReadDeclAs (unsigned &Idx) {
2322
+ return Reader->ReadDeclAs <T>(*F, *Record, Idx);
2323
+ }
2324
+
2325
+ IdentifierInfo *GetIdentifierInfo (unsigned &Idx) {
2326
+ return Reader->GetIdentifierInfo (*F, *Record, Idx);
2327
+ }
2328
+
2329
+ // / \brief Read a selector from the Record, advancing Idx.
2330
+ Selector ReadSelector (unsigned &Idx) {
2331
+ return Reader->ReadSelector (*F, *Record, Idx);
2332
+ }
2333
+
2334
+ // / \brief Read a declaration name, advancing Idx.
2335
+ DeclarationName ReadDeclarationName (unsigned &Idx) {
2336
+ return Reader->ReadDeclarationName (*F, *Record, Idx);
2337
+ }
2338
+ void ReadDeclarationNameLoc (DeclarationNameLoc &DNLoc, DeclarationName Name,
2339
+ unsigned &Idx) {
2340
+ return Reader->ReadDeclarationNameLoc (*F, DNLoc, Name, *Record, Idx);
2341
+ }
2342
+ void ReadDeclarationNameInfo (DeclarationNameInfo &NameInfo, unsigned &Idx) {
2343
+ return Reader->ReadDeclarationNameInfo (*F, NameInfo, *Record, Idx);
2344
+ }
2345
+
2346
+ void ReadQualifierInfo (QualifierInfo &Info, unsigned &Idx) {
2347
+ return Reader->ReadQualifierInfo (*F, Info, *Record, Idx);
2348
+ }
2349
+
2350
+ NestedNameSpecifier *ReadNestedNameSpecifier (unsigned &Idx) {
2351
+ return Reader->ReadNestedNameSpecifier (*F, *Record, Idx);
2352
+ }
2353
+
2354
+ NestedNameSpecifierLoc ReadNestedNameSpecifierLoc (unsigned &Idx) {
2355
+ return Reader->ReadNestedNameSpecifierLoc (*F, *Record, Idx);
2356
+ }
2357
+
2358
+ // / \brief Read a template name, advancing Idx.
2359
+ TemplateName ReadTemplateName (unsigned &Idx) {
2360
+ return Reader->ReadTemplateName (*F, *Record, Idx);
2361
+ }
2362
+
2363
+ // / \brief Read a template argument, advancing Idx.
2364
+ TemplateArgument ReadTemplateArgument (unsigned &Idx,
2365
+ bool Canonicalize = false ) {
2366
+ return Reader->ReadTemplateArgument (*F, *Record, Idx, Canonicalize);
2367
+ }
2368
+
2369
+ // / \brief Read a template parameter list, advancing Idx.
2370
+ TemplateParameterList *ReadTemplateParameterList (unsigned &Idx) {
2371
+ return Reader->ReadTemplateParameterList (*F, *Record, Idx);
2372
+ }
2373
+
2374
+ // / \brief Read a template argument array, advancing Idx.
2375
+ void ReadTemplateArgumentList (SmallVectorImpl<TemplateArgument> &TemplArgs,
2376
+ unsigned &Idx, bool Canonicalize = false ) {
2377
+ return Reader->ReadTemplateArgumentList (TemplArgs, *F, *Record, Idx,
2378
+ Canonicalize);
2379
+ }
2380
+
2381
+ // / \brief Read a UnresolvedSet structure, advancing Idx.
2382
+ void ReadUnresolvedSet (LazyASTUnresolvedSet &Set, unsigned &Idx) {
2383
+ return Reader->ReadUnresolvedSet (*F, Set, *Record, Idx);
2384
+ }
2385
+
2386
+ // / \brief Read a C++ base specifier, advancing Idx.
2387
+ CXXBaseSpecifier ReadCXXBaseSpecifier (unsigned &Idx) {
2388
+ return Reader->ReadCXXBaseSpecifier (*F, *Record, Idx);
2389
+ }
2390
+
2391
+ // / \brief Read a CXXCtorInitializer array, advancing Idx.
2392
+ CXXCtorInitializer **ReadCXXCtorInitializers (unsigned &Idx) {
2393
+ return Reader->ReadCXXCtorInitializers (*F, *Record, Idx);
2394
+ }
2395
+
2396
+ CXXTemporary *ReadCXXTemporary (unsigned &Idx) {
2397
+ return Reader->ReadCXXTemporary (*F, *Record, Idx);
2398
+ }
2399
+
2400
+ // / \brief Read a source location, advancing Idx.
2401
+ SourceLocation ReadSourceLocation (unsigned &Idx) {
2402
+ return Reader->ReadSourceLocation (*F, *Record, Idx);
2403
+ }
2404
+
2405
+ // / \brief Read a source range, advancing Idx.
2406
+ SourceRange ReadSourceRange (unsigned &Idx) {
2407
+ return Reader->ReadSourceRange (*F, *Record, Idx);
2408
+ }
2409
+
2410
+ // / \brief Read an integral value, advancing Idx.
2411
+ llvm::APInt ReadAPInt (unsigned &Idx) {
2412
+ return Reader->ReadAPInt (*Record, Idx);
2413
+ }
2414
+
2415
+ // / \brief Read a signed integral value, advancing Idx.
2416
+ llvm::APSInt ReadAPSInt (unsigned &Idx) {
2417
+ return Reader->ReadAPSInt (*Record, Idx);
2418
+ }
2419
+
2420
+ // / \brief Read a floating-point value, advancing Idx.
2421
+ llvm::APFloat ReadAPFloat (const llvm::fltSemantics &Sem, unsigned &Idx) {
2422
+ return Reader->ReadAPFloat (*Record, Sem,Idx);
2423
+ }
2424
+
2425
+ // / \brief Read a string, advancing Idx.
2426
+ std::string ReadString (unsigned &Idx) {
2427
+ return Reader->ReadString (*Record, Idx);
2428
+ }
2429
+
2430
+ // / \brief Read a path, advancing Idx.
2431
+ std::string ReadPath (unsigned &Idx) {
2432
+ return Reader->ReadPath (*F, *Record, Idx);
2433
+ }
2434
+
2435
+ // / \brief Read a version tuple, advancing Idx.
2436
+ VersionTuple ReadVersionTuple (unsigned &Idx) {
2437
+ return ASTReader::ReadVersionTuple (*Record, Idx);
2438
+ }
2439
+
2440
+ // / \brief Reads attributes from the current stream position, advancing Idx.
2441
+ void ReadAttributes (AttrVec &Attrs, unsigned &Idx) {
2442
+ return Reader->ReadAttributes (*F, Attrs, *Record, Idx);
2443
+ }
2444
+
2445
+ // / \brief Reads a token out of a record, advancing Idx.
2446
+ Token ReadToken (unsigned &Idx) {
2447
+ return Reader->ReadToken (*F, *Record, Idx);
2448
+ }
2449
+
2450
+ void RecordSwitchCaseID (SwitchCase *SC, unsigned ID) {
2451
+ Reader->RecordSwitchCaseID (SC, ID);
2452
+ }
2453
+
2454
+ // / \brief Retrieve the switch-case statement with the given ID.
2455
+ SwitchCase *getSwitchCaseWithID (unsigned ID) {
2456
+ return Reader->getSwitchCaseWithID (ID);
2457
+ }
2458
+
2459
+ };
2460
+
2186
2461
// / \brief Helper class that saves the current stream position and
2187
2462
// / then restores it when destroyed.
2188
2463
struct SavedStreamPosition {
0 commit comments