ASTReaderDecl.cpp revision 1711fc91efb36d131f7ba771f73f0154dc1abd1f
1//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the ASTReader::ReadDeclRecord method, which is the
11// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
15#include "ASTCommon.h"
16#include "clang/Serialization/ASTReader.h"
17#include "clang/Sema/SemaDiagnostic.h"
18#include "clang/AST/ASTConsumer.h"
19#include "clang/AST/ASTContext.h"
20#include "clang/AST/DeclVisitor.h"
21#include "clang/AST/DeclGroup.h"
22#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
24#include "clang/AST/Expr.h"
25using namespace clang;
26using namespace clang::serialization;
27
28//===----------------------------------------------------------------------===//
29// Declaration deserialization
30//===----------------------------------------------------------------------===//
31
32namespace clang {
33  class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
34    ASTReader &Reader;
35    Module &F;
36    llvm::BitstreamCursor &Cursor;
37    const DeclID ThisDeclID;
38    typedef ASTReader::RecordData RecordData;
39    const RecordData &Record;
40    unsigned &Idx;
41    TypeID TypeIDForTypeDecl;
42
43    DeclID DeclContextIDForTemplateParmDecl;
44    DeclID LexicalDeclContextIDForTemplateParmDecl;
45
46    uint64_t GetCurrentCursorOffset();
47
48    SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) {
49      return Reader.ReadSourceLocation(F, R, I);
50    }
51
52    SourceRange ReadSourceRange(const RecordData &R, unsigned &I) {
53      return Reader.ReadSourceRange(F, R, I);
54    }
55
56    TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) {
57      return Reader.GetTypeSourceInfo(F, R, I);
58    }
59
60    serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) {
61      return Reader.ReadDeclID(F, R, I);
62    }
63
64    Decl *ReadDecl(const RecordData &R, unsigned &I) {
65      return Reader.ReadDecl(F, R, I);
66    }
67
68    template<typename T>
69    T *ReadDeclAs(const RecordData &R, unsigned &I) {
70      return Reader.ReadDeclAs<T>(F, R, I);
71    }
72
73    void ReadQualifierInfo(QualifierInfo &Info,
74                           const RecordData &R, unsigned &I) {
75      Reader.ReadQualifierInfo(F, Info, R, I);
76    }
77
78    void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name,
79                                const RecordData &R, unsigned &I) {
80      Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I);
81    }
82
83    void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo,
84                                const RecordData &R, unsigned &I) {
85      Reader.ReadDeclarationNameInfo(F, NameInfo, R, I);
86    }
87
88    void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
89                               const RecordData &R, unsigned &I);
90
91    void InitializeCXXDefinitionData(CXXRecordDecl *D,
92                                     CXXRecordDecl *DefinitionDecl,
93                                     const RecordData &Record, unsigned &Idx);
94  public:
95    ASTDeclReader(ASTReader &Reader, Module &F,
96                  llvm::BitstreamCursor &Cursor, DeclID thisDeclID,
97                  const RecordData &Record, unsigned &Idx)
98      : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID),
99        Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
100
101    static void attachPreviousDecl(Decl *D, Decl *previous);
102
103    void Visit(Decl *D);
104
105    void UpdateDecl(Decl *D, Module &Module,
106                    const RecordData &Record);
107
108    static void setNextObjCCategory(ObjCCategoryDecl *Cat,
109                                    ObjCCategoryDecl *Next) {
110      Cat->NextClassCategory = Next;
111    }
112
113    void VisitDecl(Decl *D);
114    void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
115    void VisitNamedDecl(NamedDecl *ND);
116    void VisitLabelDecl(LabelDecl *LD);
117    void VisitNamespaceDecl(NamespaceDecl *D);
118    void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
119    void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
120    void VisitTypeDecl(TypeDecl *TD);
121    void VisitTypedefDecl(TypedefDecl *TD);
122    void VisitTypeAliasDecl(TypeAliasDecl *TD);
123    void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
124    void VisitTagDecl(TagDecl *TD);
125    void VisitEnumDecl(EnumDecl *ED);
126    void VisitRecordDecl(RecordDecl *RD);
127    void VisitCXXRecordDecl(CXXRecordDecl *D);
128    void VisitClassTemplateSpecializationDecl(
129                                            ClassTemplateSpecializationDecl *D);
130    void VisitClassTemplatePartialSpecializationDecl(
131                                     ClassTemplatePartialSpecializationDecl *D);
132    void VisitClassScopeFunctionSpecializationDecl(
133                                       ClassScopeFunctionSpecializationDecl *D);
134    void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
135    void VisitValueDecl(ValueDecl *VD);
136    void VisitEnumConstantDecl(EnumConstantDecl *ECD);
137    void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
138    void VisitDeclaratorDecl(DeclaratorDecl *DD);
139    void VisitFunctionDecl(FunctionDecl *FD);
140    void VisitCXXMethodDecl(CXXMethodDecl *D);
141    void VisitCXXConstructorDecl(CXXConstructorDecl *D);
142    void VisitCXXDestructorDecl(CXXDestructorDecl *D);
143    void VisitCXXConversionDecl(CXXConversionDecl *D);
144    void VisitFieldDecl(FieldDecl *FD);
145    void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
146    void VisitVarDecl(VarDecl *VD);
147    void VisitImplicitParamDecl(ImplicitParamDecl *PD);
148    void VisitParmVarDecl(ParmVarDecl *PD);
149    void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
150    void VisitTemplateDecl(TemplateDecl *D);
151    void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
152    void VisitClassTemplateDecl(ClassTemplateDecl *D);
153    void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
154    void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
155    void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
156    void VisitUsingDecl(UsingDecl *D);
157    void VisitUsingShadowDecl(UsingShadowDecl *D);
158    void VisitLinkageSpecDecl(LinkageSpecDecl *D);
159    void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
160    void VisitAccessSpecDecl(AccessSpecDecl *D);
161    void VisitFriendDecl(FriendDecl *D);
162    void VisitFriendTemplateDecl(FriendTemplateDecl *D);
163    void VisitStaticAssertDecl(StaticAssertDecl *D);
164    void VisitBlockDecl(BlockDecl *BD);
165
166    std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
167    template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
168
169    // FIXME: Reorder according to DeclNodes.td?
170    void VisitObjCMethodDecl(ObjCMethodDecl *D);
171    void VisitObjCContainerDecl(ObjCContainerDecl *D);
172    void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
173    void VisitObjCIvarDecl(ObjCIvarDecl *D);
174    void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
175    void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
176    void VisitObjCClassDecl(ObjCClassDecl *D);
177    void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
178    void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
179    void VisitObjCImplDecl(ObjCImplDecl *D);
180    void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
181    void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
182    void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
183    void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
184    void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
185  };
186}
187
188uint64_t ASTDeclReader::GetCurrentCursorOffset() {
189  return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset;
190}
191
192void ASTDeclReader::Visit(Decl *D) {
193  DeclVisitor<ASTDeclReader, void>::Visit(D);
194
195  if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
196    if (DD->DeclInfo) {
197      DeclaratorDecl::ExtInfo *Info =
198          DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
199      Info->TInfo =
200          GetTypeSourceInfo(Record, Idx);
201    }
202    else {
203      DD->DeclInfo = GetTypeSourceInfo(Record, Idx);
204    }
205  }
206
207  if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
208    // if we have a fully initialized TypeDecl, we can safely read its type now.
209    TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
210  } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
211    // FunctionDecl's body was written last after all other Stmts/Exprs.
212    if (Record[Idx++])
213      FD->setLazyBody(GetCurrentCursorOffset());
214  } else if (D->isTemplateParameter()) {
215    // If we have a fully initialized template parameter, we can now
216    // set its DeclContext.
217    D->setDeclContext(
218          cast_or_null<DeclContext>(
219                            Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
220    D->setLexicalDeclContext(
221          cast_or_null<DeclContext>(
222                      Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
223  }
224}
225
226void ASTDeclReader::VisitDecl(Decl *D) {
227  if (D->isTemplateParameter()) {
228    // We don't want to deserialize the DeclContext of a template
229    // parameter immediately, because the template parameter might be
230    // used in the formulation of its DeclContext. Use the translation
231    // unit DeclContext as a placeholder.
232    DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
233    LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
234    D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
235  } else {
236    D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
237    D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
238  }
239  D->setLocation(ReadSourceLocation(Record, Idx));
240  D->setInvalidDecl(Record[Idx++]);
241  if (Record[Idx++]) { // hasAttrs
242    AttrVec Attrs;
243    Reader.ReadAttributes(F, Attrs, Record, Idx);
244    D->setAttrs(Attrs);
245  }
246  D->setImplicit(Record[Idx++]);
247  D->setUsed(Record[Idx++]);
248  D->setReferenced(Record[Idx++]);
249  D->setAccess((AccessSpecifier)Record[Idx++]);
250  D->FromASTFile = true;
251  D->ModulePrivate = Record[Idx++];
252}
253
254void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
255  llvm_unreachable("Translation units are not serialized");
256}
257
258void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
259  VisitDecl(ND);
260  ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx));
261}
262
263void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
264  VisitNamedDecl(TD);
265  TD->setLocStart(ReadSourceLocation(Record, Idx));
266  // Delay type reading until after we have fully initialized the decl.
267  TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
268}
269
270void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
271  VisitTypeDecl(TD);
272  TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
273}
274
275void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
276  VisitTypeDecl(TD);
277  TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
278}
279
280void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
281  VisitTypeDecl(TD);
282  VisitRedeclarable(TD);
283  TD->IdentifierNamespace = Record[Idx++];
284  TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
285  TD->setDefinition(Record[Idx++]);
286  TD->setEmbeddedInDeclarator(Record[Idx++]);
287  TD->setFreeStanding(Record[Idx++]);
288  TD->setRBraceLoc(ReadSourceLocation(Record, Idx));
289  if (Record[Idx++]) { // hasExtInfo
290    TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
291    ReadQualifierInfo(*Info, Record, Idx);
292    TD->TypedefNameDeclOrQualifier = Info;
293  } else
294    TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx));
295}
296
297void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
298  VisitTagDecl(ED);
299  if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx))
300    ED->setIntegerTypeSourceInfo(TI);
301  else
302    ED->setIntegerType(Reader.readType(F, Record, Idx));
303  ED->setPromotionType(Reader.readType(F, Record, Idx));
304  ED->setNumPositiveBits(Record[Idx++]);
305  ED->setNumNegativeBits(Record[Idx++]);
306  ED->IsScoped = Record[Idx++];
307  ED->IsScopedUsingClassTag = Record[Idx++];
308  ED->IsFixed = Record[Idx++];
309  ED->setInstantiationOfMemberEnum(ReadDeclAs<EnumDecl>(Record, Idx));
310}
311
312void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
313  VisitTagDecl(RD);
314  RD->setHasFlexibleArrayMember(Record[Idx++]);
315  RD->setAnonymousStructOrUnion(Record[Idx++]);
316  RD->setHasObjectMember(Record[Idx++]);
317}
318
319void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
320  VisitNamedDecl(VD);
321  VD->setType(Reader.readType(F, Record, Idx));
322}
323
324void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
325  VisitValueDecl(ECD);
326  if (Record[Idx++])
327    ECD->setInitExpr(Reader.ReadExpr(F));
328  ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
329}
330
331void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
332  VisitValueDecl(DD);
333  DD->setInnerLocStart(ReadSourceLocation(Record, Idx));
334  if (Record[Idx++]) { // hasExtInfo
335    DeclaratorDecl::ExtInfo *Info
336        = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
337    ReadQualifierInfo(*Info, Record, Idx);
338    DD->DeclInfo = Info;
339  }
340}
341
342void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
343  VisitDeclaratorDecl(FD);
344  VisitRedeclarable(FD);
345
346  ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx);
347  FD->IdentifierNamespace = Record[Idx++];
348  switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
349  default: llvm_unreachable("Unhandled TemplatedKind!");
350  case FunctionDecl::TK_NonTemplate:
351    break;
352  case FunctionDecl::TK_FunctionTemplate:
353    FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record,
354                                                                      Idx));
355    break;
356  case FunctionDecl::TK_MemberSpecialization: {
357    FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx);
358    TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
359    SourceLocation POI = ReadSourceLocation(Record, Idx);
360    FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
361    FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
362    break;
363  }
364  case FunctionDecl::TK_FunctionTemplateSpecialization: {
365    FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record,
366                                                                      Idx);
367    TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
368
369    // Template arguments.
370    SmallVector<TemplateArgument, 8> TemplArgs;
371    Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
372
373    // Template args as written.
374    SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
375    SourceLocation LAngleLoc, RAngleLoc;
376    bool HasTemplateArgumentsAsWritten = Record[Idx++];
377    if (HasTemplateArgumentsAsWritten) {
378      unsigned NumTemplateArgLocs = Record[Idx++];
379      TemplArgLocs.reserve(NumTemplateArgLocs);
380      for (unsigned i=0; i != NumTemplateArgLocs; ++i)
381        TemplArgLocs.push_back(
382            Reader.ReadTemplateArgumentLoc(F, Record, Idx));
383
384      LAngleLoc = ReadSourceLocation(Record, Idx);
385      RAngleLoc = ReadSourceLocation(Record, Idx);
386    }
387
388    SourceLocation POI = ReadSourceLocation(Record, Idx);
389
390    ASTContext &C = Reader.getContext();
391    TemplateArgumentList *TemplArgList
392      = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size());
393    TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
394    for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
395      TemplArgsInfo.addArgument(TemplArgLocs[i]);
396    FunctionTemplateSpecializationInfo *FTInfo
397        = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
398                                                     TemplArgList,
399                             HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0,
400                                                     POI);
401    FD->TemplateOrSpecialization = FTInfo;
402
403    if (FD->isCanonicalDecl()) { // if canonical add to template's set.
404      // The template that contains the specializations set. It's not safe to
405      // use getCanonicalDecl on Template since it may still be initializing.
406      FunctionTemplateDecl *CanonTemplate
407        = ReadDeclAs<FunctionTemplateDecl>(Record, Idx);
408      // Get the InsertPos by FindNodeOrInsertPos() instead of calling
409      // InsertNode(FTInfo) directly to avoid the getASTContext() call in
410      // FunctionTemplateSpecializationInfo's Profile().
411      // We avoid getASTContext because a decl in the parent hierarchy may
412      // be initializing.
413      llvm::FoldingSetNodeID ID;
414      FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
415                                                  TemplArgs.size(), C);
416      void *InsertPos = 0;
417      CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
418      assert(InsertPos && "Another specialization already inserted!");
419      CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos);
420    }
421    break;
422  }
423  case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
424    // Templates.
425    UnresolvedSet<8> TemplDecls;
426    unsigned NumTemplates = Record[Idx++];
427    while (NumTemplates--)
428      TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx));
429
430    // Templates args.
431    TemplateArgumentListInfo TemplArgs;
432    unsigned NumArgs = Record[Idx++];
433    while (NumArgs--)
434      TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx));
435    TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx));
436    TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx));
437
438    FD->setDependentTemplateSpecialization(Reader.getContext(),
439                                           TemplDecls, TemplArgs);
440    break;
441  }
442  }
443
444  // FunctionDecl's body is handled last at ASTDeclReader::Visit,
445  // after everything else is read.
446
447  FD->SClass = (StorageClass)Record[Idx++];
448  FD->SClassAsWritten = (StorageClass)Record[Idx++];
449  FD->IsInline = Record[Idx++];
450  FD->IsInlineSpecified = Record[Idx++];
451  FD->IsVirtualAsWritten = Record[Idx++];
452  FD->IsPure = Record[Idx++];
453  FD->HasInheritedPrototype = Record[Idx++];
454  FD->HasWrittenPrototype = Record[Idx++];
455  FD->IsDeleted = Record[Idx++];
456  FD->IsTrivial = Record[Idx++];
457  FD->IsDefaulted = Record[Idx++];
458  FD->IsExplicitlyDefaulted = Record[Idx++];
459  FD->HasImplicitReturnZero = Record[Idx++];
460  FD->IsConstexpr = Record[Idx++];
461  FD->EndRangeLoc = ReadSourceLocation(Record, Idx);
462
463  // Read in the parameters.
464  unsigned NumParams = Record[Idx++];
465  SmallVector<ParmVarDecl *, 16> Params;
466  Params.reserve(NumParams);
467  for (unsigned I = 0; I != NumParams; ++I)
468    Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
469  FD->setParams(Reader.getContext(), Params);
470}
471
472void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
473  VisitNamedDecl(MD);
474  if (Record[Idx++]) {
475    // In practice, this won't be executed (since method definitions
476    // don't occur in header files).
477    MD->setBody(Reader.ReadStmt(F));
478    MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
479    MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
480  }
481  MD->setInstanceMethod(Record[Idx++]);
482  MD->setVariadic(Record[Idx++]);
483  MD->setSynthesized(Record[Idx++]);
484  MD->setDefined(Record[Idx++]);
485  MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
486  MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
487  MD->SetRelatedResultType(Record[Idx++]);
488  MD->setResultType(Reader.readType(F, Record, Idx));
489  MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
490  MD->setEndLoc(ReadSourceLocation(Record, Idx));
491  unsigned NumParams = Record[Idx++];
492  SmallVector<ParmVarDecl *, 16> Params;
493  Params.reserve(NumParams);
494  for (unsigned I = 0; I != NumParams; ++I)
495    Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
496
497  MD->SelLocsKind = Record[Idx++];
498  unsigned NumStoredSelLocs = Record[Idx++];
499  SmallVector<SourceLocation, 16> SelLocs;
500  SelLocs.reserve(NumStoredSelLocs);
501  for (unsigned i = 0; i != NumStoredSelLocs; ++i)
502    SelLocs.push_back(ReadSourceLocation(Record, Idx));
503
504  MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
505}
506
507void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
508  VisitNamedDecl(CD);
509  CD->setAtStartLoc(ReadSourceLocation(Record, Idx));
510  CD->setAtEndRange(ReadSourceRange(Record, Idx));
511}
512
513void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
514  VisitObjCContainerDecl(ID);
515  ID->setTypeForDecl(Reader.readType(F, Record, Idx).getTypePtrOrNull());
516  ID->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
517
518  // Read the directly referenced protocols and their SourceLocations.
519  unsigned NumProtocols = Record[Idx++];
520  SmallVector<ObjCProtocolDecl *, 16> Protocols;
521  Protocols.reserve(NumProtocols);
522  for (unsigned I = 0; I != NumProtocols; ++I)
523    Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
524  SmallVector<SourceLocation, 16> ProtoLocs;
525  ProtoLocs.reserve(NumProtocols);
526  for (unsigned I = 0; I != NumProtocols; ++I)
527    ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
528  ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
529                      Reader.getContext());
530
531  // Read the transitive closure of protocols referenced by this class.
532  NumProtocols = Record[Idx++];
533  Protocols.clear();
534  Protocols.reserve(NumProtocols);
535  for (unsigned I = 0; I != NumProtocols; ++I)
536    Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
537  ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
538                                 Reader.getContext());
539
540  // Read the ivars.
541  unsigned NumIvars = Record[Idx++];
542  SmallVector<ObjCIvarDecl *, 16> IVars;
543  IVars.reserve(NumIvars);
544  for (unsigned I = 0; I != NumIvars; ++I)
545    IVars.push_back(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
546  ID->setCategoryList(ReadDeclAs<ObjCCategoryDecl>(Record, Idx));
547
548  // We will rebuild this list lazily.
549  ID->setIvarList(0);
550  ID->setForwardDecl(Record[Idx++]);
551  ID->setImplicitInterfaceDecl(Record[Idx++]);
552  ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
553  ID->setLocEnd(ReadSourceLocation(Record, Idx));
554}
555
556void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
557  VisitFieldDecl(IVD);
558  IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
559  // This field will be built lazily.
560  IVD->setNextIvar(0);
561  bool synth = Record[Idx++];
562  IVD->setSynthesize(synth);
563}
564
565void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
566  VisitObjCContainerDecl(PD);
567  PD->setForwardDecl(Record[Idx++]);
568  PD->setLocEnd(ReadSourceLocation(Record, Idx));
569  unsigned NumProtoRefs = Record[Idx++];
570  SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
571  ProtoRefs.reserve(NumProtoRefs);
572  for (unsigned I = 0; I != NumProtoRefs; ++I)
573    ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
574  SmallVector<SourceLocation, 16> ProtoLocs;
575  ProtoLocs.reserve(NumProtoRefs);
576  for (unsigned I = 0; I != NumProtoRefs; ++I)
577    ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
578  PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
579                      Reader.getContext());
580}
581
582void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
583  VisitFieldDecl(FD);
584}
585
586void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
587  VisitDecl(CD);
588  ObjCInterfaceDecl *ClassRef = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
589  SourceLocation SLoc = ReadSourceLocation(Record, Idx);
590  CD->setClass(Reader.getContext(), ClassRef, SLoc);
591}
592
593void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
594  VisitDecl(FPD);
595  unsigned NumProtoRefs = Record[Idx++];
596  SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
597  ProtoRefs.reserve(NumProtoRefs);
598  for (unsigned I = 0; I != NumProtoRefs; ++I)
599    ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
600  SmallVector<SourceLocation, 16> ProtoLocs;
601  ProtoLocs.reserve(NumProtoRefs);
602  for (unsigned I = 0; I != NumProtoRefs; ++I)
603    ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
604  FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
605                       Reader.getContext());
606}
607
608void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
609  VisitObjCContainerDecl(CD);
610  CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx);
611  unsigned NumProtoRefs = Record[Idx++];
612  SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
613  ProtoRefs.reserve(NumProtoRefs);
614  for (unsigned I = 0; I != NumProtoRefs; ++I)
615    ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx));
616  SmallVector<SourceLocation, 16> ProtoLocs;
617  ProtoLocs.reserve(NumProtoRefs);
618  for (unsigned I = 0; I != NumProtoRefs; ++I)
619    ProtoLocs.push_back(ReadSourceLocation(Record, Idx));
620  CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
621                      Reader.getContext());
622  CD->NextClassCategory = ReadDeclAs<ObjCCategoryDecl>(Record, Idx);
623  CD->setHasSynthBitfield(Record[Idx++]);
624  CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
625}
626
627void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
628  VisitNamedDecl(CAD);
629  CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
630}
631
632void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
633  VisitNamedDecl(D);
634  D->setAtLoc(ReadSourceLocation(Record, Idx));
635  D->setType(GetTypeSourceInfo(Record, Idx));
636  // FIXME: stable encoding
637  D->setPropertyAttributes(
638                      (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
639  D->setPropertyAttributesAsWritten(
640                      (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
641  // FIXME: stable encoding
642  D->setPropertyImplementation(
643                            (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
644  D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
645  D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector());
646  D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
647  D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx));
648  D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx));
649}
650
651void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
652  VisitObjCContainerDecl(D);
653  D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
654}
655
656void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
657  VisitObjCImplDecl(D);
658  D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx));
659}
660
661void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
662  VisitObjCImplDecl(D);
663  D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
664  llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
665      = Reader.ReadCXXCtorInitializers(F, Record, Idx);
666  D->setHasSynthBitfield(Record[Idx++]);
667}
668
669
670void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
671  VisitDecl(D);
672  D->setAtLoc(ReadSourceLocation(Record, Idx));
673  D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx));
674  D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx);
675  D->IvarLoc = ReadSourceLocation(Record, Idx);
676  D->setGetterCXXConstructor(Reader.ReadExpr(F));
677  D->setSetterCXXAssignment(Reader.ReadExpr(F));
678}
679
680void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
681  VisitDeclaratorDecl(FD);
682  FD->setMutable(Record[Idx++]);
683  int BitWidthOrInitializer = Record[Idx++];
684  if (BitWidthOrInitializer == 1)
685    FD->setBitWidth(Reader.ReadExpr(F));
686  else if (BitWidthOrInitializer == 2)
687    FD->setInClassInitializer(Reader.ReadExpr(F));
688  if (!FD->getDeclName()) {
689    if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx))
690      Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
691  }
692}
693
694void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
695  VisitValueDecl(FD);
696
697  FD->ChainingSize = Record[Idx++];
698  assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
699  FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
700
701  for (unsigned I = 0; I != FD->ChainingSize; ++I)
702    FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx);
703}
704
705void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
706  VisitDeclaratorDecl(VD);
707  VisitRedeclarable(VD);
708  VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
709  VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
710  VD->VarDeclBits.ThreadSpecified = Record[Idx++];
711  VD->VarDeclBits.HasCXXDirectInit = Record[Idx++];
712  VD->VarDeclBits.ExceptionVar = Record[Idx++];
713  VD->VarDeclBits.NRVOVariable = Record[Idx++];
714  VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
715  VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
716  if (Record[Idx++])
717    VD->setInit(Reader.ReadExpr(F));
718
719  if (Record[Idx++]) { // HasMemberSpecializationInfo.
720    VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx);
721    TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
722    SourceLocation POI = ReadSourceLocation(Record, Idx);
723    Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
724  }
725}
726
727void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
728  VisitVarDecl(PD);
729}
730
731void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
732  VisitVarDecl(PD);
733  unsigned isObjCMethodParam = Record[Idx++];
734  unsigned scopeDepth = Record[Idx++];
735  unsigned scopeIndex = Record[Idx++];
736  unsigned declQualifier = Record[Idx++];
737  if (isObjCMethodParam) {
738    assert(scopeDepth == 0);
739    PD->setObjCMethodScopeInfo(scopeIndex);
740    PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
741  } else {
742    PD->setScopeInfo(scopeDepth, scopeIndex);
743  }
744  PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
745  PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
746  if (Record[Idx++]) // hasUninstantiatedDefaultArg.
747    PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F));
748}
749
750void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
751  VisitDecl(AD);
752  AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F)));
753  AD->setRParenLoc(ReadSourceLocation(Record, Idx));
754}
755
756void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
757  VisitDecl(BD);
758  BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F)));
759  BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx));
760  unsigned NumParams = Record[Idx++];
761  SmallVector<ParmVarDecl *, 16> Params;
762  Params.reserve(NumParams);
763  for (unsigned I = 0; I != NumParams; ++I)
764    Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
765  BD->setParams(Params);
766
767  bool capturesCXXThis = Record[Idx++];
768  unsigned numCaptures = Record[Idx++];
769  SmallVector<BlockDecl::Capture, 16> captures;
770  captures.reserve(numCaptures);
771  for (unsigned i = 0; i != numCaptures; ++i) {
772    VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx);
773    unsigned flags = Record[Idx++];
774    bool byRef = (flags & 1);
775    bool nested = (flags & 2);
776    Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0);
777
778    captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
779  }
780  BD->setCaptures(Reader.getContext(), captures.begin(),
781                  captures.end(), capturesCXXThis);
782}
783
784void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
785  VisitDecl(D);
786  D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
787  D->setExternLoc(ReadSourceLocation(Record, Idx));
788  D->setRBraceLoc(ReadSourceLocation(Record, Idx));
789}
790
791void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
792  VisitNamedDecl(D);
793  D->setLocStart(ReadSourceLocation(Record, Idx));
794}
795
796
797void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
798  VisitNamedDecl(D);
799  D->IsInline = Record[Idx++];
800  D->LocStart = ReadSourceLocation(Record, Idx);
801  D->RBraceLoc = ReadSourceLocation(Record, Idx);
802  D->NextNamespace = Record[Idx++];
803
804  bool IsOriginal = Record[Idx++];
805  // FIXME: Modules will likely have trouble with pointing directly at
806  // the original namespace.
807  D->OrigOrAnonNamespace.setInt(IsOriginal);
808  D->OrigOrAnonNamespace.setPointer(ReadDeclAs<NamespaceDecl>(Record, Idx));
809}
810
811void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
812  VisitNamedDecl(D);
813  D->NamespaceLoc = ReadSourceLocation(Record, Idx);
814  D->IdentLoc = ReadSourceLocation(Record, Idx);
815  D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
816  D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx);
817}
818
819void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
820  VisitNamedDecl(D);
821  D->setUsingLocation(ReadSourceLocation(Record, Idx));
822  D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
823  ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
824  D->FirstUsingShadow = ReadDeclAs<UsingShadowDecl>(Record, Idx);
825  D->setTypeName(Record[Idx++]);
826  if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx))
827    Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
828}
829
830void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
831  VisitNamedDecl(D);
832  D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx));
833  D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx);
834  UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx);
835  if (Pattern)
836    Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
837}
838
839void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
840  VisitNamedDecl(D);
841  D->UsingLoc = ReadSourceLocation(Record, Idx);
842  D->NamespaceLoc = ReadSourceLocation(Record, Idx);
843  D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
844  D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx);
845  D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx);
846}
847
848void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
849  VisitValueDecl(D);
850  D->setUsingLoc(ReadSourceLocation(Record, Idx));
851  D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
852  ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
853}
854
855void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
856                                               UnresolvedUsingTypenameDecl *D) {
857  VisitTypeDecl(D);
858  D->TypenameLocation = ReadSourceLocation(Record, Idx);
859  D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
860}
861
862void ASTDeclReader::ReadCXXDefinitionData(
863                                   struct CXXRecordDecl::DefinitionData &Data,
864                                   const RecordData &Record, unsigned &Idx) {
865  Data.UserDeclaredConstructor = Record[Idx++];
866  Data.UserDeclaredCopyConstructor = Record[Idx++];
867  Data.UserDeclaredMoveConstructor = Record[Idx++];
868  Data.UserDeclaredCopyAssignment = Record[Idx++];
869  Data.UserDeclaredMoveAssignment = Record[Idx++];
870  Data.UserDeclaredDestructor = Record[Idx++];
871  Data.Aggregate = Record[Idx++];
872  Data.PlainOldData = Record[Idx++];
873  Data.Empty = Record[Idx++];
874  Data.Polymorphic = Record[Idx++];
875  Data.Abstract = Record[Idx++];
876  Data.IsStandardLayout = Record[Idx++];
877  Data.HasNoNonEmptyBases = Record[Idx++];
878  Data.HasPrivateFields = Record[Idx++];
879  Data.HasProtectedFields = Record[Idx++];
880  Data.HasPublicFields = Record[Idx++];
881  Data.HasMutableFields = Record[Idx++];
882  Data.HasTrivialDefaultConstructor = Record[Idx++];
883  Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
884  Data.HasTrivialCopyConstructor = Record[Idx++];
885  Data.HasTrivialMoveConstructor = Record[Idx++];
886  Data.HasTrivialCopyAssignment = Record[Idx++];
887  Data.HasTrivialMoveAssignment = Record[Idx++];
888  Data.HasTrivialDestructor = Record[Idx++];
889  Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
890  Data.ComputedVisibleConversions = Record[Idx++];
891  Data.UserProvidedDefaultConstructor = Record[Idx++];
892  Data.DeclaredDefaultConstructor = Record[Idx++];
893  Data.DeclaredCopyConstructor = Record[Idx++];
894  Data.DeclaredMoveConstructor = Record[Idx++];
895  Data.DeclaredCopyAssignment = Record[Idx++];
896  Data.DeclaredMoveAssignment = Record[Idx++];
897  Data.DeclaredDestructor = Record[Idx++];
898  Data.FailedImplicitMoveConstructor = Record[Idx++];
899  Data.FailedImplicitMoveAssignment = Record[Idx++];
900
901  Data.NumBases = Record[Idx++];
902  if (Data.NumBases)
903    Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
904  Data.NumVBases = Record[Idx++];
905  if (Data.NumVBases)
906    Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx);
907
908  Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx);
909  Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx);
910  assert(Data.Definition && "Data.Definition should be already set!");
911  Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx);
912}
913
914void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl *D,
915                                                CXXRecordDecl *DefinitionDecl,
916                                                const RecordData &Record,
917                                                unsigned &Idx) {
918  ASTContext &C = Reader.getContext();
919
920  if (D == DefinitionDecl) {
921    D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
922    ReadCXXDefinitionData(*D->DefinitionData, Record, Idx);
923    // We read the definition info. Check if there are pending forward
924    // references that need to point to this DefinitionData pointer.
925    ASTReader::PendingForwardRefsMap::iterator
926        FindI = Reader.PendingForwardRefs.find(D);
927    if (FindI != Reader.PendingForwardRefs.end()) {
928      ASTReader::ForwardRefs &Refs = FindI->second;
929      for (ASTReader::ForwardRefs::iterator
930             I = Refs.begin(), E = Refs.end(); I != E; ++I)
931        (*I)->DefinitionData = D->DefinitionData;
932#ifndef NDEBUG
933      // We later check whether PendingForwardRefs is empty to make sure all
934      // pending references were linked.
935      Reader.PendingForwardRefs.erase(D);
936#endif
937    }
938  } else if (DefinitionDecl) {
939    if (DefinitionDecl->DefinitionData) {
940      D->DefinitionData = DefinitionDecl->DefinitionData;
941    } else {
942      // The definition is still initializing.
943      Reader.PendingForwardRefs[DefinitionDecl].push_back(D);
944    }
945  }
946}
947
948void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
949  VisitRecordDecl(D);
950
951  CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
952  InitializeCXXDefinitionData(D, DefinitionDecl, Record, Idx);
953
954  ASTContext &C = Reader.getContext();
955
956  enum CXXRecKind {
957    CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
958  };
959  switch ((CXXRecKind)Record[Idx++]) {
960  default:
961    llvm_unreachable("Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
962  case CXXRecNotTemplate:
963    break;
964  case CXXRecTemplate:
965    D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx);
966    break;
967  case CXXRecMemberSpecialization: {
968    CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx);
969    TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
970    SourceLocation POI = ReadSourceLocation(Record, Idx);
971    MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
972    MSI->setPointOfInstantiation(POI);
973    D->TemplateOrInstantiation = MSI;
974    break;
975  }
976  }
977
978  // Load the key function to avoid deserializing every method so we can
979  // compute it.
980  if (D->IsDefinition) {
981    if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx))
982      C.KeyFunctions[D] = Key;
983  }
984}
985
986void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
987  VisitFunctionDecl(D);
988  unsigned NumOverridenMethods = Record[Idx++];
989  while (NumOverridenMethods--) {
990    // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
991    // MD may be initializing.
992    if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx))
993      Reader.getContext().addOverriddenMethod(D, MD);
994  }
995}
996
997void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
998  VisitCXXMethodDecl(D);
999
1000  D->IsExplicitSpecified = Record[Idx++];
1001  D->ImplicitlyDefined = Record[Idx++];
1002  llvm::tie(D->CtorInitializers, D->NumCtorInitializers)
1003      = Reader.ReadCXXCtorInitializers(F, Record, Idx);
1004}
1005
1006void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
1007  VisitCXXMethodDecl(D);
1008
1009  D->ImplicitlyDefined = Record[Idx++];
1010  D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx);
1011}
1012
1013void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
1014  VisitCXXMethodDecl(D);
1015  D->IsExplicitSpecified = Record[Idx++];
1016}
1017
1018void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
1019  VisitDecl(D);
1020  D->setColonLoc(ReadSourceLocation(Record, Idx));
1021}
1022
1023void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
1024  VisitDecl(D);
1025  if (Record[Idx++])
1026    D->Friend = GetTypeSourceInfo(Record, Idx);
1027  else
1028    D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
1029  D->NextFriend = Record[Idx++];
1030  D->UnsupportedFriend = (Record[Idx++] != 0);
1031  D->FriendLoc = ReadSourceLocation(Record, Idx);
1032}
1033
1034void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
1035  VisitDecl(D);
1036  unsigned NumParams = Record[Idx++];
1037  D->NumParams = NumParams;
1038  D->Params = new TemplateParameterList*[NumParams];
1039  for (unsigned i = 0; i != NumParams; ++i)
1040    D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx);
1041  if (Record[Idx++]) // HasFriendDecl
1042    D->Friend = ReadDeclAs<NamedDecl>(Record, Idx);
1043  else
1044    D->Friend = GetTypeSourceInfo(Record, Idx);
1045  D->FriendLoc = ReadSourceLocation(Record, Idx);
1046}
1047
1048void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
1049  VisitNamedDecl(D);
1050
1051  NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx);
1052  TemplateParameterList* TemplateParams
1053      = Reader.ReadTemplateParameterList(F, Record, Idx);
1054  D->init(TemplatedDecl, TemplateParams);
1055}
1056
1057void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
1058  // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
1059  // can be used while this is still initializing.
1060
1061  assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
1062  DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1063  DeclID FirstDeclID =  PreviousDeclID ? ReadDeclID(Record, Idx) : 0;
1064  // We delay loading of the redeclaration chain to avoid deeply nested calls.
1065  // We temporarily set the first (canonical) declaration as the previous one
1066  // which is the one that matters and mark the real previous DeclID to be
1067  // loaded & attached later on.
1068  RedeclarableTemplateDecl *FirstDecl =
1069      cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID));
1070  assert((FirstDecl == 0 || FirstDecl->getKind() == D->getKind()) &&
1071         "FirstDecl kind mismatch");
1072  if (FirstDecl) {
1073    D->CommonOrPrev = FirstDecl;
1074    // Mark the real previous DeclID to be loaded & attached later on.
1075    if (PreviousDeclID != FirstDeclID)
1076      Reader.PendingPreviousDecls.push_back(std::make_pair(D, PreviousDeclID));
1077  } else {
1078    D->CommonOrPrev = D->newCommon(Reader.getContext());
1079    if (RedeclarableTemplateDecl *RTD
1080          = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) {
1081      assert(RTD->getKind() == D->getKind() &&
1082             "InstantiatedFromMemberTemplate kind mismatch");
1083      D->setInstantiatedFromMemberTemplateImpl(RTD);
1084      if (Record[Idx++])
1085        D->setMemberSpecialization();
1086    }
1087
1088    RedeclarableTemplateDecl *LatestDecl
1089      = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx);
1090
1091    // This decl is a first one and the latest declaration that it points to is
1092    // in the same AST file. However, if this actually needs to point to a
1093    // redeclaration in another AST file, we need to update it by checking
1094    // the FirstLatestDeclIDs map which tracks this kind of decls.
1095    assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
1096    ASTReader::FirstLatestDeclIDMap::iterator I
1097        = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1098    if (I != Reader.FirstLatestDeclIDs.end()) {
1099      if (Decl *NewLatest = Reader.GetDecl(I->second))
1100        LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
1101    }
1102
1103    assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
1104    D->getCommonPtr()->Latest = LatestDecl;
1105  }
1106
1107  VisitTemplateDecl(D);
1108  D->IdentifierNamespace = Record[Idx++];
1109}
1110
1111void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1112  VisitRedeclarableTemplateDecl(D);
1113
1114  if (D->getPreviousDeclaration() == 0) {
1115    // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1116    // the specializations.
1117    SmallVector<serialization::DeclID, 2> SpecIDs;
1118    SpecIDs.push_back(0);
1119
1120    // Specializations.
1121    unsigned Size = Record[Idx++];
1122    SpecIDs[0] += Size;
1123    for (unsigned I = 0; I != Size; ++I)
1124      SpecIDs.push_back(ReadDeclID(Record, Idx));
1125
1126    // Partial specializations.
1127    Size = Record[Idx++];
1128    SpecIDs[0] += Size;
1129    for (unsigned I = 0; I != Size; ++I)
1130      SpecIDs.push_back(ReadDeclID(Record, Idx));
1131
1132    if (SpecIDs[0]) {
1133      typedef serialization::DeclID DeclID;
1134
1135      ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr();
1136      CommonPtr->LazySpecializations
1137        = new (Reader.getContext()) DeclID [SpecIDs.size()];
1138      memcpy(CommonPtr->LazySpecializations, SpecIDs.data(),
1139             SpecIDs.size() * sizeof(DeclID));
1140    }
1141
1142    // InjectedClassNameType is computed.
1143  }
1144}
1145
1146void ASTDeclReader::VisitClassTemplateSpecializationDecl(
1147                                           ClassTemplateSpecializationDecl *D) {
1148  VisitCXXRecordDecl(D);
1149
1150  ASTContext &C = Reader.getContext();
1151  if (Decl *InstD = ReadDecl(Record, Idx)) {
1152    if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
1153      D->SpecializedTemplate = CTD;
1154    } else {
1155      SmallVector<TemplateArgument, 8> TemplArgs;
1156      Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
1157      TemplateArgumentList *ArgList
1158        = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1159                                           TemplArgs.size());
1160      ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1161          = new (C) ClassTemplateSpecializationDecl::
1162                                             SpecializedPartialSpecialization();
1163      PS->PartialSpecialization
1164          = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1165      PS->TemplateArgs = ArgList;
1166      D->SpecializedTemplate = PS;
1167    }
1168  }
1169
1170  // Explicit info.
1171  if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) {
1172    ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
1173        = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
1174    ExplicitInfo->TypeAsWritten = TyInfo;
1175    ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx);
1176    ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx);
1177    D->ExplicitInfo = ExplicitInfo;
1178  }
1179
1180  SmallVector<TemplateArgument, 8> TemplArgs;
1181  Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx);
1182  D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(),
1183                                                     TemplArgs.size());
1184  D->PointOfInstantiation = ReadSourceLocation(Record, Idx);
1185  D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
1186
1187  if (D->isCanonicalDecl()) { // It's kept in the folding set.
1188    ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx);
1189    if (ClassTemplatePartialSpecializationDecl *Partial
1190                       = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
1191      CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial);
1192    } else {
1193      CanonPattern->getCommonPtr()->Specializations.InsertNode(D);
1194    }
1195  }
1196}
1197
1198void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
1199                                    ClassTemplatePartialSpecializationDecl *D) {
1200  VisitClassTemplateSpecializationDecl(D);
1201
1202  ASTContext &C = Reader.getContext();
1203  D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx);
1204
1205  unsigned NumArgs = Record[Idx++];
1206  if (NumArgs) {
1207    D->NumArgsAsWritten = NumArgs;
1208    D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs];
1209    for (unsigned i=0; i != NumArgs; ++i)
1210      D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
1211  }
1212
1213  D->SequenceNumber = Record[Idx++];
1214
1215  // These are read/set from/to the first declaration.
1216  if (D->getPreviousDeclaration() == 0) {
1217    D->InstantiatedFromMember.setPointer(
1218      ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx));
1219    D->InstantiatedFromMember.setInt(Record[Idx++]);
1220  }
1221}
1222
1223void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
1224                                    ClassScopeFunctionSpecializationDecl *D) {
1225  VisitDecl(D);
1226  D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx);
1227}
1228
1229void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1230  VisitRedeclarableTemplateDecl(D);
1231
1232  if (D->getPreviousDeclaration() == 0) {
1233    // This FunctionTemplateDecl owns a CommonPtr; read it.
1234
1235    // Read the function specialization declarations.
1236    // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
1237    // when reading the specialized FunctionDecl.
1238    unsigned NumSpecs = Record[Idx++];
1239    while (NumSpecs--)
1240      (void)ReadDecl(Record, Idx);
1241  }
1242}
1243
1244void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
1245  VisitTypeDecl(D);
1246
1247  D->setDeclaredWithTypename(Record[Idx++]);
1248
1249  bool Inherited = Record[Idx++];
1250  TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx);
1251  D->setDefaultArgument(DefArg, Inherited);
1252}
1253
1254void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
1255  VisitDeclaratorDecl(D);
1256  // TemplateParmPosition.
1257  D->setDepth(Record[Idx++]);
1258  D->setPosition(Record[Idx++]);
1259  if (D->isExpandedParameterPack()) {
1260    void **Data = reinterpret_cast<void **>(D + 1);
1261    for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1262      Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr();
1263      Data[2*I + 1] = GetTypeSourceInfo(Record, Idx);
1264    }
1265  } else {
1266    // Rest of NonTypeTemplateParmDecl.
1267    D->ParameterPack = Record[Idx++];
1268    if (Record[Idx++]) {
1269      Expr *DefArg = Reader.ReadExpr(F);
1270      bool Inherited = Record[Idx++];
1271      D->setDefaultArgument(DefArg, Inherited);
1272   }
1273  }
1274}
1275
1276void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
1277  VisitTemplateDecl(D);
1278  // TemplateParmPosition.
1279  D->setDepth(Record[Idx++]);
1280  D->setPosition(Record[Idx++]);
1281  // Rest of TemplateTemplateParmDecl.
1282  TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx);
1283  bool IsInherited = Record[Idx++];
1284  D->setDefaultArgument(Arg, IsInherited);
1285  D->ParameterPack = Record[Idx++];
1286}
1287
1288void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1289  VisitRedeclarableTemplateDecl(D);
1290}
1291
1292void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
1293  VisitDecl(D);
1294  D->AssertExpr = Reader.ReadExpr(F);
1295  D->Message = cast<StringLiteral>(Reader.ReadExpr(F));
1296  D->RParenLoc = ReadSourceLocation(Record, Idx);
1297}
1298
1299std::pair<uint64_t, uint64_t>
1300ASTDeclReader::VisitDeclContext(DeclContext *DC) {
1301  uint64_t LexicalOffset = Record[Idx++];
1302  uint64_t VisibleOffset = Record[Idx++];
1303  return std::make_pair(LexicalOffset, VisibleOffset);
1304}
1305
1306template <typename T>
1307void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
1308  enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1309  RedeclKind Kind = (RedeclKind)Record[Idx++];
1310  switch (Kind) {
1311  default:
1312    llvm_unreachable("Out of sync with ASTDeclWriter::VisitRedeclarable or"
1313                     " messed up reading");
1314  case NoRedeclaration:
1315    break;
1316  case PointsToPrevious: {
1317    DeclID PreviousDeclID = ReadDeclID(Record, Idx);
1318    DeclID FirstDeclID = ReadDeclID(Record, Idx);
1319    // We delay loading of the redeclaration chain to avoid deeply nested calls.
1320    // We temporarily set the first (canonical) declaration as the previous one
1321    // which is the one that matters and mark the real previous DeclID to be
1322    // loaded & attached later on.
1323    D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
1324                                cast_or_null<T>(Reader.GetDecl(FirstDeclID)));
1325    if (PreviousDeclID != FirstDeclID)
1326      Reader.PendingPreviousDecls.push_back(std::make_pair(static_cast<T*>(D),
1327                                                           PreviousDeclID));
1328    break;
1329  }
1330  case PointsToLatest:
1331    D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1332                                                   ReadDeclAs<T>(Record, Idx));
1333    break;
1334  }
1335
1336  assert(!(Kind == PointsToPrevious &&
1337           Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1338               Reader.FirstLatestDeclIDs.end()) &&
1339         "This decl is not first, it should not be in the map");
1340  if (Kind == PointsToPrevious)
1341    return;
1342
1343  // This decl is a first one and the latest declaration that it points to is in
1344  // the same AST file. However, if this actually needs to point to a
1345  // redeclaration in another AST file, we need to update it by checking the
1346  // FirstLatestDeclIDs map which tracks this kind of decls.
1347  assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1348         "Invalid ThisDeclID ?");
1349  ASTReader::FirstLatestDeclIDMap::iterator I
1350      = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1351  if (I != Reader.FirstLatestDeclIDs.end()) {
1352    Decl *NewLatest = Reader.GetDecl(I->second);
1353    D->RedeclLink
1354        = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1355  }
1356}
1357
1358//===----------------------------------------------------------------------===//
1359// Attribute Reading
1360//===----------------------------------------------------------------------===//
1361
1362/// \brief Reads attributes from the current stream position.
1363void ASTReader::ReadAttributes(Module &F, AttrVec &Attrs,
1364                               const RecordData &Record, unsigned &Idx) {
1365  for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
1366    Attr *New = 0;
1367    attr::Kind Kind = (attr::Kind)Record[Idx++];
1368    SourceRange Range = ReadSourceRange(F, Record, Idx);
1369
1370#include "clang/Serialization/AttrPCHRead.inc"
1371
1372    assert(New && "Unable to decode attribute?");
1373    Attrs.push_back(New);
1374  }
1375}
1376
1377//===----------------------------------------------------------------------===//
1378// ASTReader Implementation
1379//===----------------------------------------------------------------------===//
1380
1381/// \brief Note that we have loaded the declaration with the given
1382/// Index.
1383///
1384/// This routine notes that this declaration has already been loaded,
1385/// so that future GetDecl calls will return this declaration rather
1386/// than trying to load a new declaration.
1387inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
1388  assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1389  DeclsLoaded[Index] = D;
1390}
1391
1392
1393/// \brief Determine whether the consumer will be interested in seeing
1394/// this declaration (via HandleTopLevelDecl).
1395///
1396/// This routine should return true for anything that might affect
1397/// code generation, e.g., inline function definitions, Objective-C
1398/// declarations with metadata, etc.
1399static bool isConsumerInterestedIn(Decl *D) {
1400  // An ObjCMethodDecl is never considered as "interesting" because its
1401  // implementation container always is.
1402
1403  if (isa<FileScopeAsmDecl>(D) ||
1404      isa<ObjCProtocolDecl>(D) ||
1405      isa<ObjCImplDecl>(D))
1406    return true;
1407  if (VarDecl *Var = dyn_cast<VarDecl>(D))
1408    return Var->isFileVarDecl() &&
1409           Var->isThisDeclarationADefinition() == VarDecl::Definition;
1410  if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1411    return Func->doesThisDeclarationHaveABody();
1412
1413  return false;
1414}
1415
1416/// \brief Get the correct cursor and offset for loading a declaration.
1417ASTReader::RecordLocation
1418ASTReader::DeclCursorForID(DeclID ID) {
1419  // See if there's an override.
1420  DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1421  if (It != ReplacedDecls.end())
1422    return RecordLocation(It->second.first, It->second.second);
1423
1424  GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
1425  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
1426  Module *M = I->second;
1427  return RecordLocation(M,
1428           M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]);
1429}
1430
1431ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
1432  ContinuousRangeMap<uint64_t, Module*, 4>::iterator I
1433    = GlobalBitOffsetsMap.find(GlobalOffset);
1434
1435  assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
1436  return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
1437}
1438
1439uint64_t ASTReader::getGlobalBitOffset(Module &M, uint32_t LocalOffset) {
1440  return LocalOffset + M.GlobalBitOffset;
1441}
1442
1443void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
1444  assert(D && previous);
1445  if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
1446    TD->RedeclLink.setPointer(cast<TagDecl>(previous));
1447  } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1448    FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
1449  } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
1450    VD->RedeclLink.setPointer(cast<VarDecl>(previous));
1451  } else {
1452    RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
1453    TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous);
1454  }
1455}
1456
1457void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
1458  Decl *previous = GetDecl(ID);
1459  ASTDeclReader::attachPreviousDecl(D, previous);
1460}
1461
1462/// \brief Read the declaration at the given offset from the AST file.
1463Decl *ASTReader::ReadDeclRecord(DeclID ID) {
1464  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
1465  RecordLocation Loc = DeclCursorForID(ID);
1466  llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
1467  // Keep track of where we are in the stream, then jump back there
1468  // after reading this declaration.
1469  SavedStreamPosition SavedPosition(DeclsCursor);
1470
1471  ReadingKindTracker ReadingKind(Read_Decl, *this);
1472
1473  // Note that we are loading a declaration record.
1474  Deserializing ADecl(this);
1475
1476  DeclsCursor.JumpToBit(Loc.Offset);
1477  RecordData Record;
1478  unsigned Code = DeclsCursor.ReadCode();
1479  unsigned Idx = 0;
1480  ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, Record, Idx);
1481
1482  Decl *D = 0;
1483  switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
1484  case DECL_CONTEXT_LEXICAL:
1485  case DECL_CONTEXT_VISIBLE:
1486    llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
1487  case DECL_TYPEDEF:
1488    D = TypedefDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
1489                            0, 0);
1490    break;
1491  case DECL_TYPEALIAS:
1492    D = TypeAliasDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
1493                              0, 0);
1494    break;
1495  case DECL_ENUM:
1496    D = EnumDecl::Create(Context, Decl::EmptyShell());
1497    break;
1498  case DECL_RECORD:
1499    D = RecordDecl::Create(Context, Decl::EmptyShell());
1500    break;
1501  case DECL_ENUM_CONSTANT:
1502    D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
1503                                 0, llvm::APSInt());
1504    break;
1505  case DECL_FUNCTION:
1506    D = FunctionDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
1507                             DeclarationName(), QualType(), 0);
1508    break;
1509  case DECL_LINKAGE_SPEC:
1510    D = LinkageSpecDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
1511                                (LinkageSpecDecl::LanguageIDs)0,
1512                                SourceLocation());
1513    break;
1514  case DECL_LABEL:
1515    D = LabelDecl::Create(Context, 0, SourceLocation(), 0);
1516    break;
1517  case DECL_NAMESPACE:
1518    D = NamespaceDecl::Create(Context, 0, SourceLocation(),
1519                              SourceLocation(), 0);
1520    break;
1521  case DECL_NAMESPACE_ALIAS:
1522    D = NamespaceAliasDecl::Create(Context, 0, SourceLocation(),
1523                                   SourceLocation(), 0,
1524                                   NestedNameSpecifierLoc(),
1525                                   SourceLocation(), 0);
1526    break;
1527  case DECL_USING:
1528    D = UsingDecl::Create(Context, 0, SourceLocation(),
1529                          NestedNameSpecifierLoc(), DeclarationNameInfo(),
1530                          false);
1531    break;
1532  case DECL_USING_SHADOW:
1533    D = UsingShadowDecl::Create(Context, 0, SourceLocation(), 0, 0);
1534    break;
1535  case DECL_USING_DIRECTIVE:
1536    D = UsingDirectiveDecl::Create(Context, 0, SourceLocation(),
1537                                   SourceLocation(), NestedNameSpecifierLoc(),
1538                                   SourceLocation(), 0, 0);
1539    break;
1540  case DECL_UNRESOLVED_USING_VALUE:
1541    D = UnresolvedUsingValueDecl::Create(Context, 0, SourceLocation(),
1542                                         NestedNameSpecifierLoc(),
1543                                         DeclarationNameInfo());
1544    break;
1545  case DECL_UNRESOLVED_USING_TYPENAME:
1546    D = UnresolvedUsingTypenameDecl::Create(Context, 0, SourceLocation(),
1547                                            SourceLocation(),
1548                                            NestedNameSpecifierLoc(),
1549                                            SourceLocation(),
1550                                            DeclarationName());
1551    break;
1552  case DECL_CXX_RECORD:
1553    D = CXXRecordDecl::Create(Context, Decl::EmptyShell());
1554    break;
1555  case DECL_CXX_METHOD:
1556    D = CXXMethodDecl::Create(Context, 0, SourceLocation(),
1557                              DeclarationNameInfo(), QualType(), 0,
1558                              false, SC_None, false, false, SourceLocation());
1559    break;
1560  case DECL_CXX_CONSTRUCTOR:
1561    D = CXXConstructorDecl::Create(Context, Decl::EmptyShell());
1562    break;
1563  case DECL_CXX_DESTRUCTOR:
1564    D = CXXDestructorDecl::Create(Context, Decl::EmptyShell());
1565    break;
1566  case DECL_CXX_CONVERSION:
1567    D = CXXConversionDecl::Create(Context, Decl::EmptyShell());
1568    break;
1569  case DECL_ACCESS_SPEC:
1570    D = AccessSpecDecl::Create(Context, Decl::EmptyShell());
1571    break;
1572  case DECL_FRIEND:
1573    D = FriendDecl::Create(Context, Decl::EmptyShell());
1574    break;
1575  case DECL_FRIEND_TEMPLATE:
1576    D = FriendTemplateDecl::Create(Context, Decl::EmptyShell());
1577    break;
1578  case DECL_CLASS_TEMPLATE:
1579    D = ClassTemplateDecl::Create(Context, Decl::EmptyShell());
1580    break;
1581  case DECL_CLASS_TEMPLATE_SPECIALIZATION:
1582    D = ClassTemplateSpecializationDecl::Create(Context, Decl::EmptyShell());
1583    break;
1584  case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
1585    D = ClassTemplatePartialSpecializationDecl::Create(Context,
1586                                                       Decl::EmptyShell());
1587    break;
1588  case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
1589    D = ClassScopeFunctionSpecializationDecl::Create(Context,
1590                                                     Decl::EmptyShell());
1591    break;
1592  case DECL_FUNCTION_TEMPLATE:
1593      D = FunctionTemplateDecl::Create(Context, Decl::EmptyShell());
1594    break;
1595  case DECL_TEMPLATE_TYPE_PARM:
1596    D = TemplateTypeParmDecl::Create(Context, Decl::EmptyShell());
1597    break;
1598  case DECL_NON_TYPE_TEMPLATE_PARM:
1599    D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
1600                                        SourceLocation(), 0, 0, 0, QualType(),
1601                                        false, 0);
1602    break;
1603  case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
1604    D = NonTypeTemplateParmDecl::Create(Context, 0, SourceLocation(),
1605                                        SourceLocation(), 0, 0, 0, QualType(),
1606                                        0, 0, Record[Idx++], 0);
1607    break;
1608  case DECL_TEMPLATE_TEMPLATE_PARM:
1609    D = TemplateTemplateParmDecl::Create(Context, 0, SourceLocation(), 0, 0,
1610                                         false, 0, 0);
1611    break;
1612  case DECL_TYPE_ALIAS_TEMPLATE:
1613    D = TypeAliasTemplateDecl::Create(Context, Decl::EmptyShell());
1614    break;
1615  case DECL_STATIC_ASSERT:
1616    D = StaticAssertDecl::Create(Context, 0, SourceLocation(), 0, 0,
1617                                 SourceLocation());
1618    break;
1619
1620  case DECL_OBJC_METHOD:
1621    D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
1622                               Selector(), QualType(), 0, 0);
1623    break;
1624  case DECL_OBJC_INTERFACE:
1625    D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
1626    break;
1627  case DECL_OBJC_IVAR:
1628    D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), SourceLocation(),
1629                             0, QualType(), 0, ObjCIvarDecl::None);
1630    break;
1631  case DECL_OBJC_PROTOCOL:
1632    D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
1633                                 SourceLocation());
1634    break;
1635  case DECL_OBJC_AT_DEFS_FIELD:
1636    D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
1637                                    SourceLocation(), 0, QualType(), 0);
1638    break;
1639  case DECL_OBJC_CLASS:
1640    D = ObjCClassDecl::Create(Context, 0, SourceLocation());
1641    break;
1642  case DECL_OBJC_FORWARD_PROTOCOL:
1643    D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
1644    break;
1645  case DECL_OBJC_CATEGORY:
1646    D = ObjCCategoryDecl::Create(Context, Decl::EmptyShell());
1647    break;
1648  case DECL_OBJC_CATEGORY_IMPL:
1649    D = ObjCCategoryImplDecl::Create(Context, 0, 0, 0, SourceLocation(),
1650                                     SourceLocation());
1651    break;
1652  case DECL_OBJC_IMPLEMENTATION:
1653    D = ObjCImplementationDecl::Create(Context, 0, 0, 0, SourceLocation(),
1654                                       SourceLocation());
1655    break;
1656  case DECL_OBJC_COMPATIBLE_ALIAS:
1657    D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
1658    break;
1659  case DECL_OBJC_PROPERTY:
1660    D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, SourceLocation(),
1661                                 0);
1662    break;
1663  case DECL_OBJC_PROPERTY_IMPL:
1664    D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
1665                                     SourceLocation(), 0,
1666                                     ObjCPropertyImplDecl::Dynamic, 0,
1667                                     SourceLocation());
1668    break;
1669  case DECL_FIELD:
1670    D = FieldDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
1671                          QualType(), 0, 0, false, false);
1672    break;
1673  case DECL_INDIRECTFIELD:
1674    D = IndirectFieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
1675                                  0, 0);
1676    break;
1677  case DECL_VAR:
1678    D = VarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
1679                        QualType(), 0, SC_None, SC_None);
1680    break;
1681
1682  case DECL_IMPLICIT_PARAM:
1683    D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
1684    break;
1685
1686  case DECL_PARM_VAR:
1687    D = ParmVarDecl::Create(Context, 0, SourceLocation(), SourceLocation(), 0,
1688                            QualType(), 0, SC_None, SC_None, 0);
1689    break;
1690  case DECL_FILE_SCOPE_ASM:
1691    D = FileScopeAsmDecl::Create(Context, 0, 0, SourceLocation(),
1692                                 SourceLocation());
1693    break;
1694  case DECL_BLOCK:
1695    D = BlockDecl::Create(Context, 0, SourceLocation());
1696    break;
1697  case DECL_CXX_BASE_SPECIFIERS:
1698    Error("attempt to read a C++ base-specifier record as a declaration");
1699    return 0;
1700  }
1701
1702  assert(D && "Unknown declaration reading AST file");
1703  LoadedDecl(Index, D);
1704  Reader.Visit(D);
1705
1706  // If this declaration is also a declaration context, get the
1707  // offsets for its tables of lexical and visible declarations.
1708  if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1709    std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1710    if (Offsets.first || Offsets.second) {
1711      if (Offsets.first != 0)
1712        DC->setHasExternalLexicalStorage(true);
1713      if (Offsets.second != 0)
1714        DC->setHasExternalVisibleStorage(true);
1715      if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets,
1716                                 Loc.F->DeclContextInfos[DC]))
1717        return 0;
1718    }
1719
1720    // Now add the pending visible updates for this decl context, if it has any.
1721    DeclContextVisibleUpdatesPending::iterator I =
1722        PendingVisibleUpdates.find(ID);
1723    if (I != PendingVisibleUpdates.end()) {
1724      // There are updates. This means the context has external visible
1725      // storage, even if the original stored version didn't.
1726      DC->setHasExternalVisibleStorage(true);
1727      DeclContextVisibleUpdates &U = I->second;
1728      for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1729           UI != UE; ++UI) {
1730        UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
1731      }
1732      PendingVisibleUpdates.erase(I);
1733    }
1734  }
1735  assert(Idx == Record.size());
1736
1737  // Load any relevant update records.
1738  loadDeclUpdateRecords(ID, D);
1739
1740  if (ObjCChainedCategoriesInterfaces.count(ID))
1741    loadObjCChainedCategories(ID, cast<ObjCInterfaceDecl>(D));
1742
1743  // If we have deserialized a declaration that has a definition the
1744  // AST consumer might need to know about, queue it.
1745  // We don't pass it to the consumer immediately because we may be in recursive
1746  // loading, and some declarations may still be initializing.
1747  if (isConsumerInterestedIn(D))
1748      InterestingDecls.push_back(D);
1749
1750  return D;
1751}
1752
1753void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
1754  // The declaration may have been modified by files later in the chain.
1755  // If this is the case, read the record containing the updates from each file
1756  // and pass it to ASTDeclReader to make the modifications.
1757  DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
1758  if (UpdI != DeclUpdateOffsets.end()) {
1759    FileOffsetsTy &UpdateOffsets = UpdI->second;
1760    for (FileOffsetsTy::iterator
1761         I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) {
1762      Module *F = I->first;
1763      uint64_t Offset = I->second;
1764      llvm::BitstreamCursor &Cursor = F->DeclsCursor;
1765      SavedStreamPosition SavedPosition(Cursor);
1766      Cursor.JumpToBit(Offset);
1767      RecordData Record;
1768      unsigned Code = Cursor.ReadCode();
1769      unsigned RecCode = Cursor.ReadRecord(Code, Record);
1770      (void)RecCode;
1771      assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
1772
1773      unsigned Idx = 0;
1774      ASTDeclReader Reader(*this, *F, Cursor, ID, Record, Idx);
1775      Reader.UpdateDecl(D, *F, Record);
1776    }
1777  }
1778}
1779
1780namespace {
1781  /// \brief Given an ObjC interface, goes through the modules and links to the
1782  /// interface all the categories for it.
1783  class ObjCChainedCategoriesVisitor {
1784    ASTReader &Reader;
1785    serialization::GlobalDeclID InterfaceID;
1786    ObjCInterfaceDecl *Interface;
1787    ObjCCategoryDecl *GlobHeadCat, *GlobTailCat;
1788    llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
1789
1790  public:
1791    ObjCChainedCategoriesVisitor(ASTReader &Reader,
1792                                 serialization::GlobalDeclID InterfaceID,
1793                                 ObjCInterfaceDecl *Interface)
1794      : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface),
1795        GlobHeadCat(0), GlobTailCat(0) { }
1796
1797    static bool visit(Module &M, void *UserData) {
1798      return static_cast<ObjCChainedCategoriesVisitor *>(UserData)->visit(M);
1799    }
1800
1801    bool visit(Module &M) {
1802      if (Reader.isDeclIDFromModule(InterfaceID, M))
1803        return true; // We reached the module where the interface originated
1804                    // from. Stop traversing the imported modules.
1805
1806      Module::ChainedObjCCategoriesMap::iterator
1807        I = M.ChainedObjCCategories.find(InterfaceID);
1808      if (I == M.ChainedObjCCategories.end())
1809        return false;
1810
1811      ObjCCategoryDecl *
1812        HeadCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.first);
1813      ObjCCategoryDecl *
1814        TailCat = Reader.GetLocalDeclAs<ObjCCategoryDecl>(M, I->second.second);
1815
1816      addCategories(HeadCat, TailCat);
1817      return false;
1818    }
1819
1820    void addCategories(ObjCCategoryDecl *HeadCat,
1821                       ObjCCategoryDecl *TailCat = 0) {
1822      if (!HeadCat) {
1823        assert(!TailCat);
1824        return;
1825      }
1826
1827      if (!TailCat) {
1828        TailCat = HeadCat;
1829        while (TailCat->getNextClassCategory())
1830          TailCat = TailCat->getNextClassCategory();
1831      }
1832
1833      if (!GlobHeadCat) {
1834        GlobHeadCat = HeadCat;
1835        GlobTailCat = TailCat;
1836      } else {
1837        ASTDeclReader::setNextObjCCategory(GlobTailCat, HeadCat);
1838        GlobTailCat = TailCat;
1839      }
1840
1841      llvm::DenseSet<DeclarationName> Checked;
1842      for (ObjCCategoryDecl *Cat = HeadCat,
1843                            *CatEnd = TailCat->getNextClassCategory();
1844             Cat != CatEnd; Cat = Cat->getNextClassCategory()) {
1845        if (Checked.count(Cat->getDeclName()))
1846          continue;
1847        Checked.insert(Cat->getDeclName());
1848        checkForDuplicate(Cat);
1849      }
1850    }
1851
1852    /// \brief Warns for duplicate categories that come from different modules.
1853    void checkForDuplicate(ObjCCategoryDecl *Cat) {
1854      DeclarationName Name = Cat->getDeclName();
1855      // Find the top category with the same name. We do not want to warn for
1856      // duplicates along the established chain because there were already
1857      // warnings for them when the module was created. We only want to warn for
1858      // duplicates between non-dependent modules:
1859      //
1860      //   MT     //
1861      //  /  \    //
1862      // ML  MR   //
1863      //
1864      // We want to warn for duplicates between ML and MR,not between ML and MT.
1865      //
1866      // FIXME: We should not warn for duplicates in diamond:
1867      //
1868      //   MT     //
1869      //  /  \    //
1870      // ML  MR   //
1871      //  \  /    //
1872      //   MB     //
1873      //
1874      // If there are duplicates in ML/MR, there will be warning when creating
1875      // MB *and* when importing MB. We should not warn when importing.
1876      for (ObjCCategoryDecl *Next = Cat->getNextClassCategory(); Next;
1877             Next = Next->getNextClassCategory()) {
1878        if (Next->getDeclName() == Name)
1879          Cat = Next;
1880      }
1881
1882      ObjCCategoryDecl *&PrevCat = NameCategoryMap[Name];
1883      if (!PrevCat)
1884        PrevCat = Cat;
1885
1886      if (PrevCat != Cat) {
1887        Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
1888          << Interface->getDeclName() << Name;
1889        Reader.Diag(PrevCat->getLocation(), diag::note_previous_definition);
1890      }
1891    }
1892
1893    ObjCCategoryDecl *getHeadCategory() const { return GlobHeadCat; }
1894  };
1895}
1896
1897void ASTReader::loadObjCChainedCategories(serialization::GlobalDeclID ID,
1898                                          ObjCInterfaceDecl *D) {
1899  ObjCChainedCategoriesVisitor Visitor(*this, ID, D);
1900  ModuleMgr.visit(ObjCChainedCategoriesVisitor::visit, &Visitor);
1901  // Also add the categories that the interface already links to.
1902  Visitor.addCategories(D->getCategoryList());
1903  D->setCategoryList(Visitor.getHeadCategory());
1904}
1905
1906void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
1907                               const RecordData &Record) {
1908  unsigned Idx = 0;
1909  while (Idx < Record.size()) {
1910    switch ((DeclUpdateKind)Record[Idx++]) {
1911    case UPD_CXX_SET_DEFINITIONDATA: {
1912      CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
1913      CXXRecordDecl *DefinitionDecl
1914        = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
1915      assert(!RD->DefinitionData && "DefinitionData is already set!");
1916      InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
1917      break;
1918    }
1919
1920    case UPD_CXX_ADDED_IMPLICIT_MEMBER:
1921      cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
1922      break;
1923
1924    case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
1925      // It will be added to the template's specializations set when loaded.
1926      (void)Reader.ReadDecl(Module, Record, Idx);
1927      break;
1928
1929    case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
1930      NamespaceDecl *Anon
1931        = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
1932      // Guard against these being loaded out of original order. Don't use
1933      // getNextNamespace(), since it tries to access the context and can't in
1934      // the middle of deserialization.
1935      if (!Anon->NextNamespace) {
1936        if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
1937          TU->setAnonymousNamespace(Anon);
1938        else
1939          cast<NamespaceDecl>(D)->OrigOrAnonNamespace.setPointer(Anon);
1940      }
1941      break;
1942    }
1943
1944    case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
1945      cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
1946          Reader.ReadSourceLocation(Module, Record, Idx));
1947      break;
1948    }
1949  }
1950}
1951