clang API Documentation
00001 //===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the ASTReader::ReadDeclRecord method, which is the 00011 // entrypoint for loading a decl. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "ASTCommon.h" 00016 #include "ASTReaderInternals.h" 00017 #include "clang/Serialization/ASTReader.h" 00018 #include "clang/Sema/IdentifierResolver.h" 00019 #include "clang/Sema/Sema.h" 00020 #include "clang/Sema/SemaDiagnostic.h" 00021 #include "clang/AST/ASTConsumer.h" 00022 #include "clang/AST/ASTContext.h" 00023 #include "clang/AST/DeclVisitor.h" 00024 #include "clang/AST/DeclGroup.h" 00025 #include "clang/AST/DeclCXX.h" 00026 #include "clang/AST/DeclTemplate.h" 00027 #include "clang/AST/Expr.h" 00028 #include "llvm/Support/SaveAndRestore.h" 00029 using namespace clang; 00030 using namespace clang::serialization; 00031 00032 //===----------------------------------------------------------------------===// 00033 // Declaration deserialization 00034 //===----------------------------------------------------------------------===// 00035 00036 namespace clang { 00037 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { 00038 ASTReader &Reader; 00039 ModuleFile &F; 00040 llvm::BitstreamCursor &Cursor; 00041 const DeclID ThisDeclID; 00042 const unsigned RawLocation; 00043 typedef ASTReader::RecordData RecordData; 00044 const RecordData &Record; 00045 unsigned &Idx; 00046 TypeID TypeIDForTypeDecl; 00047 00048 DeclID DeclContextIDForTemplateParmDecl; 00049 DeclID LexicalDeclContextIDForTemplateParmDecl; 00050 00051 uint64_t GetCurrentCursorOffset(); 00052 00053 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) { 00054 return Reader.ReadSourceLocation(F, R, I); 00055 } 00056 00057 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) { 00058 return Reader.ReadSourceRange(F, R, I); 00059 } 00060 00061 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) { 00062 return Reader.GetTypeSourceInfo(F, R, I); 00063 } 00064 00065 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) { 00066 return Reader.ReadDeclID(F, R, I); 00067 } 00068 00069 Decl *ReadDecl(const RecordData &R, unsigned &I) { 00070 return Reader.ReadDecl(F, R, I); 00071 } 00072 00073 template<typename T> 00074 T *ReadDeclAs(const RecordData &R, unsigned &I) { 00075 return Reader.ReadDeclAs<T>(F, R, I); 00076 } 00077 00078 void ReadQualifierInfo(QualifierInfo &Info, 00079 const RecordData &R, unsigned &I) { 00080 Reader.ReadQualifierInfo(F, Info, R, I); 00081 } 00082 00083 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name, 00084 const RecordData &R, unsigned &I) { 00085 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I); 00086 } 00087 00088 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo, 00089 const RecordData &R, unsigned &I) { 00090 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I); 00091 } 00092 00093 serialization::SubmoduleID readSubmoduleID(const RecordData &R, 00094 unsigned &I) { 00095 if (I >= R.size()) 00096 return 0; 00097 00098 return Reader.getGlobalSubmoduleID(F, R[I++]); 00099 } 00100 00101 Module *readModule(const RecordData &R, unsigned &I) { 00102 return Reader.getSubmodule(readSubmoduleID(R, I)); 00103 } 00104 00105 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, 00106 const RecordData &R, unsigned &I); 00107 00108 /// \brief RAII class used to capture the first ID within a redeclaration 00109 /// chain and to introduce it into the list of pending redeclaration chains 00110 /// on destruction. 00111 /// 00112 /// The caller can choose not to introduce this ID into the redeclaration 00113 /// chain by calling \c suppress(). 00114 class RedeclarableResult { 00115 ASTReader &Reader; 00116 GlobalDeclID FirstID; 00117 mutable bool Owning; 00118 00119 RedeclarableResult &operator=(RedeclarableResult&); // DO NOT IMPLEMENT 00120 00121 public: 00122 RedeclarableResult(ASTReader &Reader, GlobalDeclID FirstID) 00123 : Reader(Reader), FirstID(FirstID), Owning(true) { } 00124 00125 RedeclarableResult(const RedeclarableResult &Other) 00126 : Reader(Other.Reader), FirstID(Other.FirstID), Owning(Other.Owning) 00127 { 00128 Other.Owning = false; 00129 } 00130 00131 ~RedeclarableResult() { 00132 // FIXME: We want to suppress this when the declaration is local to 00133 // a function, since there's no reason to search other AST files 00134 // for redeclarations (they can't exist). However, this is hard to 00135 // do locally because the declaration hasn't necessarily loaded its 00136 // declaration context yet. Also, local externs still have the function 00137 // as their (semantic) declaration context, which is wrong and would 00138 // break this optimize. 00139 00140 if (FirstID && Owning && Reader.PendingDeclChainsKnown.insert(FirstID)) 00141 Reader.PendingDeclChains.push_back(FirstID); 00142 } 00143 00144 /// \brief Retrieve the first ID. 00145 GlobalDeclID getFirstID() const { return FirstID; } 00146 00147 /// \brief Do not introduce this declaration ID into the set of pending 00148 /// declaration chains. 00149 void suppress() { 00150 Owning = false; 00151 } 00152 }; 00153 00154 /// \brief Class used to capture the result of searching for an existing 00155 /// declaration of a specific kind and name, along with the ability 00156 /// to update the place where this result was found (the declaration 00157 /// chain hanging off an identifier or the DeclContext we searched in) 00158 /// if requested. 00159 class FindExistingResult { 00160 ASTReader &Reader; 00161 NamedDecl *New; 00162 NamedDecl *Existing; 00163 mutable bool AddResult; 00164 00165 FindExistingResult &operator=(FindExistingResult&); // DO NOT IMPLEMENT 00166 00167 public: 00168 FindExistingResult(ASTReader &Reader) 00169 : Reader(Reader), New(0), Existing(0), AddResult(false) { } 00170 00171 FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing) 00172 : Reader(Reader), New(New), Existing(Existing), AddResult(true) { } 00173 00174 FindExistingResult(const FindExistingResult &Other) 00175 : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), 00176 AddResult(Other.AddResult) 00177 { 00178 Other.AddResult = false; 00179 } 00180 00181 ~FindExistingResult(); 00182 00183 /// \brief Suppress the addition of this result into the known set of 00184 /// names. 00185 void suppress() { AddResult = false; } 00186 00187 operator NamedDecl*() const { return Existing; } 00188 00189 template<typename T> 00190 operator T*() const { return dyn_cast_or_null<T>(Existing); } 00191 }; 00192 00193 FindExistingResult findExisting(NamedDecl *D); 00194 00195 public: 00196 ASTDeclReader(ASTReader &Reader, ModuleFile &F, 00197 llvm::BitstreamCursor &Cursor, DeclID thisDeclID, 00198 unsigned RawLocation, 00199 const RecordData &Record, unsigned &Idx) 00200 : Reader(Reader), F(F), Cursor(Cursor), ThisDeclID(thisDeclID), 00201 RawLocation(RawLocation), Record(Record), Idx(Idx), 00202 TypeIDForTypeDecl(0) { } 00203 00204 static void attachPreviousDecl(Decl *D, Decl *previous); 00205 static void attachLatestDecl(Decl *D, Decl *latest); 00206 00207 void Visit(Decl *D); 00208 00209 void UpdateDecl(Decl *D, ModuleFile &ModuleFile, 00210 const RecordData &Record); 00211 00212 static void setNextObjCCategory(ObjCCategoryDecl *Cat, 00213 ObjCCategoryDecl *Next) { 00214 Cat->NextClassCategory = Next; 00215 } 00216 00217 void VisitDecl(Decl *D); 00218 void VisitTranslationUnitDecl(TranslationUnitDecl *TU); 00219 void VisitNamedDecl(NamedDecl *ND); 00220 void VisitLabelDecl(LabelDecl *LD); 00221 void VisitNamespaceDecl(NamespaceDecl *D); 00222 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); 00223 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); 00224 void VisitTypeDecl(TypeDecl *TD); 00225 void VisitTypedefNameDecl(TypedefNameDecl *TD); 00226 void VisitTypedefDecl(TypedefDecl *TD); 00227 void VisitTypeAliasDecl(TypeAliasDecl *TD); 00228 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); 00229 void VisitTagDecl(TagDecl *TD); 00230 void VisitEnumDecl(EnumDecl *ED); 00231 void VisitRecordDecl(RecordDecl *RD); 00232 void VisitCXXRecordDecl(CXXRecordDecl *D); 00233 void VisitClassTemplateSpecializationDecl( 00234 ClassTemplateSpecializationDecl *D); 00235 void VisitClassTemplatePartialSpecializationDecl( 00236 ClassTemplatePartialSpecializationDecl *D); 00237 void VisitClassScopeFunctionSpecializationDecl( 00238 ClassScopeFunctionSpecializationDecl *D); 00239 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); 00240 void VisitValueDecl(ValueDecl *VD); 00241 void VisitEnumConstantDecl(EnumConstantDecl *ECD); 00242 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); 00243 void VisitDeclaratorDecl(DeclaratorDecl *DD); 00244 void VisitFunctionDecl(FunctionDecl *FD); 00245 void VisitCXXMethodDecl(CXXMethodDecl *D); 00246 void VisitCXXConstructorDecl(CXXConstructorDecl *D); 00247 void VisitCXXDestructorDecl(CXXDestructorDecl *D); 00248 void VisitCXXConversionDecl(CXXConversionDecl *D); 00249 void VisitFieldDecl(FieldDecl *FD); 00250 void VisitIndirectFieldDecl(IndirectFieldDecl *FD); 00251 void VisitVarDecl(VarDecl *VD); 00252 void VisitImplicitParamDecl(ImplicitParamDecl *PD); 00253 void VisitParmVarDecl(ParmVarDecl *PD); 00254 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); 00255 void VisitTemplateDecl(TemplateDecl *D); 00256 RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); 00257 void VisitClassTemplateDecl(ClassTemplateDecl *D); 00258 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); 00259 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); 00260 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); 00261 void VisitUsingDecl(UsingDecl *D); 00262 void VisitUsingShadowDecl(UsingShadowDecl *D); 00263 void VisitLinkageSpecDecl(LinkageSpecDecl *D); 00264 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); 00265 void VisitImportDecl(ImportDecl *D); 00266 void VisitAccessSpecDecl(AccessSpecDecl *D); 00267 void VisitFriendDecl(FriendDecl *D); 00268 void VisitFriendTemplateDecl(FriendTemplateDecl *D); 00269 void VisitStaticAssertDecl(StaticAssertDecl *D); 00270 void VisitBlockDecl(BlockDecl *BD); 00271 00272 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); 00273 00274 template<typename T> 00275 RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); 00276 00277 template<typename T> 00278 void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl); 00279 00280 // FIXME: Reorder according to DeclNodes.td? 00281 void VisitObjCMethodDecl(ObjCMethodDecl *D); 00282 void VisitObjCContainerDecl(ObjCContainerDecl *D); 00283 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); 00284 void VisitObjCIvarDecl(ObjCIvarDecl *D); 00285 void VisitObjCProtocolDecl(ObjCProtocolDecl *D); 00286 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); 00287 void VisitObjCCategoryDecl(ObjCCategoryDecl *D); 00288 void VisitObjCImplDecl(ObjCImplDecl *D); 00289 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); 00290 void VisitObjCImplementationDecl(ObjCImplementationDecl *D); 00291 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); 00292 void VisitObjCPropertyDecl(ObjCPropertyDecl *D); 00293 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); 00294 }; 00295 } 00296 00297 uint64_t ASTDeclReader::GetCurrentCursorOffset() { 00298 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset; 00299 } 00300 00301 void ASTDeclReader::Visit(Decl *D) { 00302 DeclVisitor<ASTDeclReader, void>::Visit(D); 00303 00304 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) { 00305 if (DD->DeclInfo) { 00306 DeclaratorDecl::ExtInfo *Info = 00307 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>(); 00308 Info->TInfo = 00309 GetTypeSourceInfo(Record, Idx); 00310 } 00311 else { 00312 DD->DeclInfo = GetTypeSourceInfo(Record, Idx); 00313 } 00314 } 00315 00316 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) { 00317 // if we have a fully initialized TypeDecl, we can safely read its type now. 00318 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull()); 00319 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { 00320 // if we have a fully initialized TypeDecl, we can safely read its type now. 00321 ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull(); 00322 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 00323 // FunctionDecl's body was written last after all other Stmts/Exprs. 00324 if (Record[Idx++]) 00325 FD->setLazyBody(GetCurrentCursorOffset()); 00326 } else if (D->isTemplateParameter()) { 00327 // If we have a fully initialized template parameter, we can now 00328 // set its DeclContext. 00329 DeclContext *SemaDC = cast<DeclContext>( 00330 Reader.GetDecl(DeclContextIDForTemplateParmDecl)); 00331 DeclContext *LexicalDC = cast<DeclContext>( 00332 Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)); 00333 D->setDeclContextsImpl(SemaDC, LexicalDC, Reader.getContext()); 00334 } 00335 } 00336 00337 void ASTDeclReader::VisitDecl(Decl *D) { 00338 if (D->isTemplateParameter()) { 00339 // We don't want to deserialize the DeclContext of a template 00340 // parameter immediately, because the template parameter might be 00341 // used in the formulation of its DeclContext. Use the translation 00342 // unit DeclContext as a placeholder. 00343 DeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx); 00344 LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx); 00345 D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); 00346 } else { 00347 DeclContext *SemaDC = ReadDeclAs<DeclContext>(Record, Idx); 00348 DeclContext *LexicalDC = ReadDeclAs<DeclContext>(Record, Idx); 00349 // Avoid calling setLexicalDeclContext() directly because it uses 00350 // Decl::getASTContext() internally which is unsafe during derialization. 00351 D->setDeclContextsImpl(SemaDC, LexicalDC, Reader.getContext()); 00352 } 00353 D->setLocation(Reader.ReadSourceLocation(F, RawLocation)); 00354 D->setInvalidDecl(Record[Idx++]); 00355 if (Record[Idx++]) { // hasAttrs 00356 AttrVec Attrs; 00357 Reader.ReadAttributes(F, Attrs, Record, Idx); 00358 // Avoid calling setAttrs() directly because it uses Decl::getASTContext() 00359 // internally which is unsafe during derialization. 00360 D->setAttrsImpl(Attrs, Reader.getContext()); 00361 } 00362 D->setImplicit(Record[Idx++]); 00363 D->setUsed(Record[Idx++]); 00364 D->setReferenced(Record[Idx++]); 00365 D->setTopLevelDeclInObjCContainer(Record[Idx++]); 00366 D->setAccess((AccessSpecifier)Record[Idx++]); 00367 D->FromASTFile = true; 00368 D->setModulePrivate(Record[Idx++]); 00369 D->Hidden = D->isModulePrivate(); 00370 00371 // Determine whether this declaration is part of a (sub)module. If so, it 00372 // may not yet be visible. 00373 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) { 00374 // Store the owning submodule ID in the declaration. 00375 D->setOwningModuleID(SubmoduleID); 00376 00377 // Module-private declarations are never visible, so there is no work to do. 00378 if (!D->isModulePrivate()) { 00379 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { 00380 if (Owner->NameVisibility != Module::AllVisible) { 00381 // The owning module is not visible. Mark this declaration as hidden. 00382 D->Hidden = true; 00383 00384 // Note that this declaration was hidden because its owning module is 00385 // not yet visible. 00386 Reader.HiddenNamesMap[Owner].push_back(D); 00387 } 00388 } 00389 } 00390 } 00391 } 00392 00393 void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { 00394 llvm_unreachable("Translation units are not serialized"); 00395 } 00396 00397 void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { 00398 VisitDecl(ND); 00399 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx)); 00400 } 00401 00402 void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { 00403 VisitNamedDecl(TD); 00404 TD->setLocStart(ReadSourceLocation(Record, Idx)); 00405 // Delay type reading until after we have fully initialized the decl. 00406 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]); 00407 } 00408 00409 void ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { 00410 RedeclarableResult Redecl = VisitRedeclarable(TD); 00411 VisitTypeDecl(TD); 00412 00413 TD->setTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 00414 mergeRedeclarable(TD, Redecl); 00415 } 00416 00417 void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { 00418 VisitTypedefNameDecl(TD); 00419 } 00420 00421 void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { 00422 VisitTypedefNameDecl(TD); 00423 } 00424 00425 void ASTDeclReader::VisitTagDecl(TagDecl *TD) { 00426 RedeclarableResult Redecl = VisitRedeclarable(TD); 00427 VisitTypeDecl(TD); 00428 00429 TD->IdentifierNamespace = Record[Idx++]; 00430 TD->setTagKind((TagDecl::TagKind)Record[Idx++]); 00431 TD->setCompleteDefinition(Record[Idx++]); 00432 TD->setEmbeddedInDeclarator(Record[Idx++]); 00433 TD->setFreeStanding(Record[Idx++]); 00434 TD->setRBraceLoc(ReadSourceLocation(Record, Idx)); 00435 00436 if (Record[Idx++]) { // hasExtInfo 00437 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo(); 00438 ReadQualifierInfo(*Info, Record, Idx); 00439 TD->TypedefNameDeclOrQualifier = Info; 00440 } else 00441 TD->setTypedefNameForAnonDecl(ReadDeclAs<TypedefNameDecl>(Record, Idx)); 00442 00443 mergeRedeclarable(TD, Redecl); 00444 } 00445 00446 void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { 00447 VisitTagDecl(ED); 00448 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx)) 00449 ED->setIntegerTypeSourceInfo(TI); 00450 else 00451 ED->setIntegerType(Reader.readType(F, Record, Idx)); 00452 ED->setPromotionType(Reader.readType(F, Record, Idx)); 00453 ED->setNumPositiveBits(Record[Idx++]); 00454 ED->setNumNegativeBits(Record[Idx++]); 00455 ED->IsScoped = Record[Idx++]; 00456 ED->IsScopedUsingClassTag = Record[Idx++]; 00457 ED->IsFixed = Record[Idx++]; 00458 00459 if (EnumDecl *InstED = ReadDeclAs<EnumDecl>(Record, Idx)) { 00460 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 00461 SourceLocation POI = ReadSourceLocation(Record, Idx); 00462 ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); 00463 ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); 00464 } 00465 } 00466 00467 void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) { 00468 VisitTagDecl(RD); 00469 RD->setHasFlexibleArrayMember(Record[Idx++]); 00470 RD->setAnonymousStructOrUnion(Record[Idx++]); 00471 RD->setHasObjectMember(Record[Idx++]); 00472 } 00473 00474 void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { 00475 VisitNamedDecl(VD); 00476 VD->setType(Reader.readType(F, Record, Idx)); 00477 } 00478 00479 void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { 00480 VisitValueDecl(ECD); 00481 if (Record[Idx++]) 00482 ECD->setInitExpr(Reader.ReadExpr(F)); 00483 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); 00484 } 00485 00486 void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { 00487 VisitValueDecl(DD); 00488 DD->setInnerLocStart(ReadSourceLocation(Record, Idx)); 00489 if (Record[Idx++]) { // hasExtInfo 00490 DeclaratorDecl::ExtInfo *Info 00491 = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); 00492 ReadQualifierInfo(*Info, Record, Idx); 00493 DD->DeclInfo = Info; 00494 } 00495 } 00496 00497 void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { 00498 RedeclarableResult Redecl = VisitRedeclarable(FD); 00499 VisitDeclaratorDecl(FD); 00500 00501 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx); 00502 FD->IdentifierNamespace = Record[Idx++]; 00503 00504 // FunctionDecl's body is handled last at ASTDeclReader::Visit, 00505 // after everything else is read. 00506 00507 FD->SClass = (StorageClass)Record[Idx++]; 00508 FD->SClassAsWritten = (StorageClass)Record[Idx++]; 00509 FD->IsInline = Record[Idx++]; 00510 FD->IsInlineSpecified = Record[Idx++]; 00511 FD->IsVirtualAsWritten = Record[Idx++]; 00512 FD->IsPure = Record[Idx++]; 00513 FD->HasInheritedPrototype = Record[Idx++]; 00514 FD->HasWrittenPrototype = Record[Idx++]; 00515 FD->IsDeleted = Record[Idx++]; 00516 FD->IsTrivial = Record[Idx++]; 00517 FD->IsDefaulted = Record[Idx++]; 00518 FD->IsExplicitlyDefaulted = Record[Idx++]; 00519 FD->HasImplicitReturnZero = Record[Idx++]; 00520 FD->IsConstexpr = Record[Idx++]; 00521 FD->EndRangeLoc = ReadSourceLocation(Record, Idx); 00522 00523 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) { 00524 case FunctionDecl::TK_NonTemplate: 00525 mergeRedeclarable(FD, Redecl); 00526 break; 00527 case FunctionDecl::TK_FunctionTemplate: 00528 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record, 00529 Idx)); 00530 break; 00531 case FunctionDecl::TK_MemberSpecialization: { 00532 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx); 00533 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 00534 SourceLocation POI = ReadSourceLocation(Record, Idx); 00535 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); 00536 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); 00537 break; 00538 } 00539 case FunctionDecl::TK_FunctionTemplateSpecialization: { 00540 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record, 00541 Idx); 00542 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 00543 00544 // Template arguments. 00545 SmallVector<TemplateArgument, 8> TemplArgs; 00546 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); 00547 00548 // Template args as written. 00549 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; 00550 SourceLocation LAngleLoc, RAngleLoc; 00551 bool HasTemplateArgumentsAsWritten = Record[Idx++]; 00552 if (HasTemplateArgumentsAsWritten) { 00553 unsigned NumTemplateArgLocs = Record[Idx++]; 00554 TemplArgLocs.reserve(NumTemplateArgLocs); 00555 for (unsigned i=0; i != NumTemplateArgLocs; ++i) 00556 TemplArgLocs.push_back( 00557 Reader.ReadTemplateArgumentLoc(F, Record, Idx)); 00558 00559 LAngleLoc = ReadSourceLocation(Record, Idx); 00560 RAngleLoc = ReadSourceLocation(Record, Idx); 00561 } 00562 00563 SourceLocation POI = ReadSourceLocation(Record, Idx); 00564 00565 ASTContext &C = Reader.getContext(); 00566 TemplateArgumentList *TemplArgList 00567 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size()); 00568 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); 00569 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i) 00570 TemplArgsInfo.addArgument(TemplArgLocs[i]); 00571 FunctionTemplateSpecializationInfo *FTInfo 00572 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK, 00573 TemplArgList, 00574 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0, 00575 POI); 00576 FD->TemplateOrSpecialization = FTInfo; 00577 00578 if (FD->isCanonicalDecl()) { // if canonical add to template's set. 00579 // The template that contains the specializations set. It's not safe to 00580 // use getCanonicalDecl on Template since it may still be initializing. 00581 FunctionTemplateDecl *CanonTemplate 00582 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx); 00583 // Get the InsertPos by FindNodeOrInsertPos() instead of calling 00584 // InsertNode(FTInfo) directly to avoid the getASTContext() call in 00585 // FunctionTemplateSpecializationInfo's Profile(). 00586 // We avoid getASTContext because a decl in the parent hierarchy may 00587 // be initializing. 00588 llvm::FoldingSetNodeID ID; 00589 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(), 00590 TemplArgs.size(), C); 00591 void *InsertPos = 0; 00592 CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos); 00593 assert(InsertPos && "Another specialization already inserted!"); 00594 CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos); 00595 } 00596 break; 00597 } 00598 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { 00599 // Templates. 00600 UnresolvedSet<8> TemplDecls; 00601 unsigned NumTemplates = Record[Idx++]; 00602 while (NumTemplates--) 00603 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx)); 00604 00605 // Templates args. 00606 TemplateArgumentListInfo TemplArgs; 00607 unsigned NumArgs = Record[Idx++]; 00608 while (NumArgs--) 00609 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx)); 00610 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx)); 00611 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx)); 00612 00613 FD->setDependentTemplateSpecialization(Reader.getContext(), 00614 TemplDecls, TemplArgs); 00615 break; 00616 } 00617 } 00618 00619 // Read in the parameters. 00620 unsigned NumParams = Record[Idx++]; 00621 SmallVector<ParmVarDecl *, 16> Params; 00622 Params.reserve(NumParams); 00623 for (unsigned I = 0; I != NumParams; ++I) 00624 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx)); 00625 FD->setParams(Reader.getContext(), Params); 00626 } 00627 00628 void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { 00629 VisitNamedDecl(MD); 00630 if (Record[Idx++]) { 00631 // In practice, this won't be executed (since method definitions 00632 // don't occur in header files). 00633 // Switch case IDs for this method body. 00634 ASTReader::SwitchCaseMapTy SwitchCaseStmtsForObjCMethod; 00635 SaveAndRestore<ASTReader::SwitchCaseMapTy *> 00636 SCFOM(Reader.CurrSwitchCaseStmts, &SwitchCaseStmtsForObjCMethod); 00637 MD->setBody(Reader.ReadStmt(F)); 00638 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx)); 00639 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx)); 00640 } 00641 MD->setInstanceMethod(Record[Idx++]); 00642 MD->setVariadic(Record[Idx++]); 00643 MD->setSynthesized(Record[Idx++]); 00644 MD->setDefined(Record[Idx++]); 00645 MD->IsOverriding = Record[Idx++]; 00646 00647 MD->IsRedeclaration = Record[Idx++]; 00648 MD->HasRedeclaration = Record[Idx++]; 00649 if (MD->HasRedeclaration) 00650 Reader.getContext().setObjCMethodRedeclaration(MD, 00651 ReadDeclAs<ObjCMethodDecl>(Record, Idx)); 00652 00653 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); 00654 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); 00655 MD->SetRelatedResultType(Record[Idx++]); 00656 MD->setResultType(Reader.readType(F, Record, Idx)); 00657 MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 00658 MD->setEndLoc(ReadSourceLocation(Record, Idx)); 00659 unsigned NumParams = Record[Idx++]; 00660 SmallVector<ParmVarDecl *, 16> Params; 00661 Params.reserve(NumParams); 00662 for (unsigned I = 0; I != NumParams; ++I) 00663 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx)); 00664 00665 MD->SelLocsKind = Record[Idx++]; 00666 unsigned NumStoredSelLocs = Record[Idx++]; 00667 SmallVector<SourceLocation, 16> SelLocs; 00668 SelLocs.reserve(NumStoredSelLocs); 00669 for (unsigned i = 0; i != NumStoredSelLocs; ++i) 00670 SelLocs.push_back(ReadSourceLocation(Record, Idx)); 00671 00672 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); 00673 } 00674 00675 void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { 00676 VisitNamedDecl(CD); 00677 CD->setAtStartLoc(ReadSourceLocation(Record, Idx)); 00678 CD->setAtEndRange(ReadSourceRange(Record, Idx)); 00679 } 00680 00681 void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { 00682 RedeclarableResult Redecl = VisitRedeclarable(ID); 00683 VisitObjCContainerDecl(ID); 00684 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]); 00685 mergeRedeclarable(ID, Redecl); 00686 00687 if (Record[Idx++]) { 00688 // Read the definition. 00689 ID->allocateDefinitionData(); 00690 00691 // Set the definition data of the canonical declaration, so other 00692 // redeclarations will see it. 00693 ID->getCanonicalDecl()->Data = ID->Data; 00694 00695 ObjCInterfaceDecl::DefinitionData &Data = ID->data(); 00696 00697 // Read the superclass. 00698 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx); 00699 Data.SuperClassLoc = ReadSourceLocation(Record, Idx); 00700 00701 Data.EndLoc = ReadSourceLocation(Record, Idx); 00702 00703 // Read the directly referenced protocols and their SourceLocations. 00704 unsigned NumProtocols = Record[Idx++]; 00705 SmallVector<ObjCProtocolDecl *, 16> Protocols; 00706 Protocols.reserve(NumProtocols); 00707 for (unsigned I = 0; I != NumProtocols; ++I) 00708 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 00709 SmallVector<SourceLocation, 16> ProtoLocs; 00710 ProtoLocs.reserve(NumProtocols); 00711 for (unsigned I = 0; I != NumProtocols; ++I) 00712 ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); 00713 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(), 00714 Reader.getContext()); 00715 00716 // Read the transitive closure of protocols referenced by this class. 00717 NumProtocols = Record[Idx++]; 00718 Protocols.clear(); 00719 Protocols.reserve(NumProtocols); 00720 for (unsigned I = 0; I != NumProtocols; ++I) 00721 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 00722 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols, 00723 Reader.getContext()); 00724 00725 // We will rebuild this list lazily. 00726 ID->setIvarList(0); 00727 00728 // Note that we have deserialized a definition. 00729 Reader.PendingDefinitions.insert(ID); 00730 00731 // Note that we've loaded this Objective-C class. 00732 Reader.ObjCClassesLoaded.push_back(ID); 00733 } else { 00734 ID->Data = ID->getCanonicalDecl()->Data; 00735 } 00736 } 00737 00738 void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { 00739 VisitFieldDecl(IVD); 00740 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); 00741 // This field will be built lazily. 00742 IVD->setNextIvar(0); 00743 bool synth = Record[Idx++]; 00744 IVD->setSynthesize(synth); 00745 } 00746 00747 void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { 00748 RedeclarableResult Redecl = VisitRedeclarable(PD); 00749 VisitObjCContainerDecl(PD); 00750 mergeRedeclarable(PD, Redecl); 00751 00752 if (Record[Idx++]) { 00753 // Read the definition. 00754 PD->allocateDefinitionData(); 00755 00756 // Set the definition data of the canonical declaration, so other 00757 // redeclarations will see it. 00758 PD->getCanonicalDecl()->Data = PD->Data; 00759 00760 unsigned NumProtoRefs = Record[Idx++]; 00761 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; 00762 ProtoRefs.reserve(NumProtoRefs); 00763 for (unsigned I = 0; I != NumProtoRefs; ++I) 00764 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 00765 SmallVector<SourceLocation, 16> ProtoLocs; 00766 ProtoLocs.reserve(NumProtoRefs); 00767 for (unsigned I = 0; I != NumProtoRefs; ++I) 00768 ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); 00769 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), 00770 Reader.getContext()); 00771 00772 // Note that we have deserialized a definition. 00773 Reader.PendingDefinitions.insert(PD); 00774 } else { 00775 PD->Data = PD->getCanonicalDecl()->Data; 00776 } 00777 } 00778 00779 void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { 00780 VisitFieldDecl(FD); 00781 } 00782 00783 void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { 00784 VisitObjCContainerDecl(CD); 00785 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx)); 00786 CD->setIvarLBraceLoc(ReadSourceLocation(Record, Idx)); 00787 CD->setIvarRBraceLoc(ReadSourceLocation(Record, Idx)); 00788 00789 // Note that this category has been deserialized. We do this before 00790 // deserializing the interface declaration, so that it will consider this 00791 /// category. 00792 Reader.CategoriesDeserialized.insert(CD); 00793 00794 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx); 00795 unsigned NumProtoRefs = Record[Idx++]; 00796 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; 00797 ProtoRefs.reserve(NumProtoRefs); 00798 for (unsigned I = 0; I != NumProtoRefs; ++I) 00799 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 00800 SmallVector<SourceLocation, 16> ProtoLocs; 00801 ProtoLocs.reserve(NumProtoRefs); 00802 for (unsigned I = 0; I != NumProtoRefs; ++I) 00803 ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); 00804 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), 00805 Reader.getContext()); 00806 CD->setHasSynthBitfield(Record[Idx++]); 00807 } 00808 00809 void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { 00810 VisitNamedDecl(CAD); 00811 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx)); 00812 } 00813 00814 void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { 00815 VisitNamedDecl(D); 00816 D->setAtLoc(ReadSourceLocation(Record, Idx)); 00817 D->setLParenLoc(ReadSourceLocation(Record, Idx)); 00818 D->setType(GetTypeSourceInfo(Record, Idx)); 00819 // FIXME: stable encoding 00820 D->setPropertyAttributes( 00821 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); 00822 D->setPropertyAttributesAsWritten( 00823 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); 00824 // FIXME: stable encoding 00825 D->setPropertyImplementation( 00826 (ObjCPropertyDecl::PropertyControl)Record[Idx++]); 00827 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector()); 00828 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector()); 00829 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx)); 00830 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx)); 00831 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx)); 00832 } 00833 00834 void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { 00835 VisitObjCContainerDecl(D); 00836 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx)); 00837 } 00838 00839 void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { 00840 VisitObjCImplDecl(D); 00841 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx)); 00842 D->CategoryNameLoc = ReadSourceLocation(Record, Idx); 00843 } 00844 00845 void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { 00846 VisitObjCImplDecl(D); 00847 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx)); 00848 D->setIvarLBraceLoc(ReadSourceLocation(Record, Idx)); 00849 D->setIvarRBraceLoc(ReadSourceLocation(Record, Idx)); 00850 llvm::tie(D->IvarInitializers, D->NumIvarInitializers) 00851 = Reader.ReadCXXCtorInitializers(F, Record, Idx); 00852 D->setHasSynthBitfield(Record[Idx++]); 00853 } 00854 00855 00856 void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { 00857 VisitDecl(D); 00858 D->setAtLoc(ReadSourceLocation(Record, Idx)); 00859 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx)); 00860 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx); 00861 D->IvarLoc = ReadSourceLocation(Record, Idx); 00862 D->setGetterCXXConstructor(Reader.ReadExpr(F)); 00863 D->setSetterCXXAssignment(Reader.ReadExpr(F)); 00864 } 00865 00866 void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { 00867 VisitDeclaratorDecl(FD); 00868 FD->setMutable(Record[Idx++]); 00869 int BitWidthOrInitializer = Record[Idx++]; 00870 if (BitWidthOrInitializer == 1) 00871 FD->setBitWidth(Reader.ReadExpr(F)); 00872 else if (BitWidthOrInitializer == 2) 00873 FD->setInClassInitializer(Reader.ReadExpr(F)); 00874 if (!FD->getDeclName()) { 00875 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx)) 00876 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); 00877 } 00878 } 00879 00880 void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { 00881 VisitValueDecl(FD); 00882 00883 FD->ChainingSize = Record[Idx++]; 00884 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2"); 00885 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; 00886 00887 for (unsigned I = 0; I != FD->ChainingSize; ++I) 00888 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx); 00889 } 00890 00891 void ASTDeclReader::VisitVarDecl(VarDecl *VD) { 00892 RedeclarableResult Redecl = VisitRedeclarable(VD); 00893 VisitDeclaratorDecl(VD); 00894 00895 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++]; 00896 VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++]; 00897 VD->VarDeclBits.ThreadSpecified = Record[Idx++]; 00898 VD->VarDeclBits.InitStyle = Record[Idx++]; 00899 VD->VarDeclBits.ExceptionVar = Record[Idx++]; 00900 VD->VarDeclBits.NRVOVariable = Record[Idx++]; 00901 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++]; 00902 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++]; 00903 00904 // Only true variables (not parameters or implicit parameters) can be merged. 00905 if (VD->getKind() == Decl::Var) 00906 mergeRedeclarable(VD, Redecl); 00907 00908 if (uint64_t Val = Record[Idx++]) { 00909 VD->setInit(Reader.ReadExpr(F)); 00910 if (Val > 1) { 00911 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); 00912 Eval->CheckedICE = true; 00913 Eval->IsICE = Val == 3; 00914 } 00915 } 00916 00917 if (Record[Idx++]) { // HasMemberSpecializationInfo. 00918 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx); 00919 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 00920 SourceLocation POI = ReadSourceLocation(Record, Idx); 00921 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); 00922 } 00923 } 00924 00925 void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { 00926 VisitVarDecl(PD); 00927 } 00928 00929 void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { 00930 VisitVarDecl(PD); 00931 unsigned isObjCMethodParam = Record[Idx++]; 00932 unsigned scopeDepth = Record[Idx++]; 00933 unsigned scopeIndex = Record[Idx++]; 00934 unsigned declQualifier = Record[Idx++]; 00935 if (isObjCMethodParam) { 00936 assert(scopeDepth == 0); 00937 PD->setObjCMethodScopeInfo(scopeIndex); 00938 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; 00939 } else { 00940 PD->setScopeInfo(scopeDepth, scopeIndex); 00941 } 00942 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++]; 00943 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++]; 00944 if (Record[Idx++]) // hasUninstantiatedDefaultArg. 00945 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F)); 00946 } 00947 00948 void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { 00949 VisitDecl(AD); 00950 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F))); 00951 AD->setRParenLoc(ReadSourceLocation(Record, Idx)); 00952 } 00953 00954 void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { 00955 VisitDecl(BD); 00956 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F))); 00957 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx)); 00958 unsigned NumParams = Record[Idx++]; 00959 SmallVector<ParmVarDecl *, 16> Params; 00960 Params.reserve(NumParams); 00961 for (unsigned I = 0; I != NumParams; ++I) 00962 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx)); 00963 BD->setParams(Params); 00964 00965 BD->setIsVariadic(Record[Idx++]); 00966 BD->setBlockMissingReturnType(Record[Idx++]); 00967 BD->setIsConversionFromLambda(Record[Idx++]); 00968 00969 bool capturesCXXThis = Record[Idx++]; 00970 unsigned numCaptures = Record[Idx++]; 00971 SmallVector<BlockDecl::Capture, 16> captures; 00972 captures.reserve(numCaptures); 00973 for (unsigned i = 0; i != numCaptures; ++i) { 00974 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx); 00975 unsigned flags = Record[Idx++]; 00976 bool byRef = (flags & 1); 00977 bool nested = (flags & 2); 00978 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0); 00979 00980 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); 00981 } 00982 BD->setCaptures(Reader.getContext(), captures.begin(), 00983 captures.end(), capturesCXXThis); 00984 } 00985 00986 void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { 00987 VisitDecl(D); 00988 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]); 00989 D->setExternLoc(ReadSourceLocation(Record, Idx)); 00990 D->setRBraceLoc(ReadSourceLocation(Record, Idx)); 00991 } 00992 00993 void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { 00994 VisitNamedDecl(D); 00995 D->setLocStart(ReadSourceLocation(Record, Idx)); 00996 } 00997 00998 00999 void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { 01000 RedeclarableResult Redecl = VisitRedeclarable(D); 01001 VisitNamedDecl(D); 01002 D->setInline(Record[Idx++]); 01003 D->LocStart = ReadSourceLocation(Record, Idx); 01004 D->RBraceLoc = ReadSourceLocation(Record, Idx); 01005 mergeRedeclarable(D, Redecl); 01006 01007 if (Redecl.getFirstID() == ThisDeclID) { 01008 // Each module has its own anonymous namespace, which is disjoint from 01009 // any other module's anonymous namespaces, so don't attach the anonymous 01010 // namespace at all. 01011 NamespaceDecl *Anon = ReadDeclAs<NamespaceDecl>(Record, Idx); 01012 if (F.Kind != MK_Module) 01013 D->setAnonymousNamespace(Anon); 01014 } else { 01015 // Link this namespace back to the first declaration, which has already 01016 // been deserialized. 01017 D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDeclaration()); 01018 } 01019 } 01020 01021 void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { 01022 VisitNamedDecl(D); 01023 D->NamespaceLoc = ReadSourceLocation(Record, Idx); 01024 D->IdentLoc = ReadSourceLocation(Record, Idx); 01025 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 01026 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx); 01027 } 01028 01029 void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { 01030 VisitNamedDecl(D); 01031 D->setUsingLocation(ReadSourceLocation(Record, Idx)); 01032 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 01033 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx); 01034 D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>(Record, Idx)); 01035 D->setTypeName(Record[Idx++]); 01036 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx)) 01037 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); 01038 } 01039 01040 void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { 01041 VisitNamedDecl(D); 01042 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx)); 01043 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx); 01044 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx); 01045 if (Pattern) 01046 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); 01047 } 01048 01049 void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { 01050 VisitNamedDecl(D); 01051 D->UsingLoc = ReadSourceLocation(Record, Idx); 01052 D->NamespaceLoc = ReadSourceLocation(Record, Idx); 01053 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 01054 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx); 01055 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx); 01056 } 01057 01058 void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { 01059 VisitValueDecl(D); 01060 D->setUsingLoc(ReadSourceLocation(Record, Idx)); 01061 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 01062 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx); 01063 } 01064 01065 void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( 01066 UnresolvedUsingTypenameDecl *D) { 01067 VisitTypeDecl(D); 01068 D->TypenameLocation = ReadSourceLocation(Record, Idx); 01069 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 01070 } 01071 01072 void ASTDeclReader::ReadCXXDefinitionData( 01073 struct CXXRecordDecl::DefinitionData &Data, 01074 const RecordData &Record, unsigned &Idx) { 01075 // Note: the caller has deserialized the IsLambda bit already. 01076 Data.UserDeclaredConstructor = Record[Idx++]; 01077 Data.UserDeclaredCopyConstructor = Record[Idx++]; 01078 Data.UserDeclaredMoveConstructor = Record[Idx++]; 01079 Data.UserDeclaredCopyAssignment = Record[Idx++]; 01080 Data.UserDeclaredMoveAssignment = Record[Idx++]; 01081 Data.UserDeclaredDestructor = Record[Idx++]; 01082 Data.Aggregate = Record[Idx++]; 01083 Data.PlainOldData = Record[Idx++]; 01084 Data.Empty = Record[Idx++]; 01085 Data.Polymorphic = Record[Idx++]; 01086 Data.Abstract = Record[Idx++]; 01087 Data.IsStandardLayout = Record[Idx++]; 01088 Data.HasNoNonEmptyBases = Record[Idx++]; 01089 Data.HasPrivateFields = Record[Idx++]; 01090 Data.HasProtectedFields = Record[Idx++]; 01091 Data.HasPublicFields = Record[Idx++]; 01092 Data.HasMutableFields = Record[Idx++]; 01093 Data.HasOnlyCMembers = Record[Idx++]; 01094 Data.HasInClassInitializer = Record[Idx++]; 01095 Data.HasTrivialDefaultConstructor = Record[Idx++]; 01096 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++]; 01097 Data.DefaultedDefaultConstructorIsConstexpr = Record[Idx++]; 01098 Data.DefaultedCopyConstructorIsConstexpr = Record[Idx++]; 01099 Data.DefaultedMoveConstructorIsConstexpr = Record[Idx++]; 01100 Data.HasConstexprDefaultConstructor = Record[Idx++]; 01101 Data.HasConstexprCopyConstructor = Record[Idx++]; 01102 Data.HasConstexprMoveConstructor = Record[Idx++]; 01103 Data.HasTrivialCopyConstructor = Record[Idx++]; 01104 Data.HasTrivialMoveConstructor = Record[Idx++]; 01105 Data.HasTrivialCopyAssignment = Record[Idx++]; 01106 Data.HasTrivialMoveAssignment = Record[Idx++]; 01107 Data.HasTrivialDestructor = Record[Idx++]; 01108 Data.HasIrrelevantDestructor = Record[Idx++]; 01109 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++]; 01110 Data.ComputedVisibleConversions = Record[Idx++]; 01111 Data.UserProvidedDefaultConstructor = Record[Idx++]; 01112 Data.DeclaredDefaultConstructor = Record[Idx++]; 01113 Data.DeclaredCopyConstructor = Record[Idx++]; 01114 Data.DeclaredMoveConstructor = Record[Idx++]; 01115 Data.DeclaredCopyAssignment = Record[Idx++]; 01116 Data.DeclaredMoveAssignment = Record[Idx++]; 01117 Data.DeclaredDestructor = Record[Idx++]; 01118 Data.FailedImplicitMoveConstructor = Record[Idx++]; 01119 Data.FailedImplicitMoveAssignment = Record[Idx++]; 01120 01121 Data.NumBases = Record[Idx++]; 01122 if (Data.NumBases) 01123 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx); 01124 Data.NumVBases = Record[Idx++]; 01125 if (Data.NumVBases) 01126 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx); 01127 01128 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx); 01129 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx); 01130 assert(Data.Definition && "Data.Definition should be already set!"); 01131 Data.FirstFriend = ReadDeclAs<FriendDecl>(Record, Idx); 01132 01133 if (Data.IsLambda) { 01134 typedef LambdaExpr::Capture Capture; 01135 CXXRecordDecl::LambdaDefinitionData &Lambda 01136 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); 01137 Lambda.Dependent = Record[Idx++]; 01138 Lambda.NumCaptures = Record[Idx++]; 01139 Lambda.NumExplicitCaptures = Record[Idx++]; 01140 Lambda.ManglingNumber = Record[Idx++]; 01141 Lambda.ContextDecl = ReadDecl(Record, Idx); 01142 Lambda.Captures 01143 = (Capture*)Reader.Context.Allocate(sizeof(Capture)*Lambda.NumCaptures); 01144 Capture *ToCapture = Lambda.Captures; 01145 for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { 01146 SourceLocation Loc = ReadSourceLocation(Record, Idx); 01147 bool IsImplicit = Record[Idx++]; 01148 LambdaCaptureKind Kind = static_cast<LambdaCaptureKind>(Record[Idx++]); 01149 VarDecl *Var = ReadDeclAs<VarDecl>(Record, Idx); 01150 SourceLocation EllipsisLoc = ReadSourceLocation(Record, Idx); 01151 *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); 01152 } 01153 } 01154 } 01155 01156 void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { 01157 VisitRecordDecl(D); 01158 01159 ASTContext &C = Reader.getContext(); 01160 if (Record[Idx++]) { 01161 // Determine whether this is a lambda closure type, so that we can 01162 // allocate the appropriate DefinitionData structure. 01163 bool IsLambda = Record[Idx++]; 01164 if (IsLambda) 01165 D->DefinitionData = new (C) CXXRecordDecl::LambdaDefinitionData(D, false); 01166 else 01167 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D); 01168 01169 // Propagate the DefinitionData pointer to the canonical declaration, so 01170 // that all other deserialized declarations will see it. 01171 // FIXME: Complain if there already is a DefinitionData! 01172 D->getCanonicalDecl()->DefinitionData = D->DefinitionData; 01173 01174 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx); 01175 01176 // Note that we have deserialized a definition. Any declarations 01177 // deserialized before this one will be be given the DefinitionData pointer 01178 // at the end. 01179 Reader.PendingDefinitions.insert(D); 01180 } else { 01181 // Propagate DefinitionData pointer from the canonical declaration. 01182 D->DefinitionData = D->getCanonicalDecl()->DefinitionData; 01183 } 01184 01185 enum CXXRecKind { 01186 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization 01187 }; 01188 switch ((CXXRecKind)Record[Idx++]) { 01189 case CXXRecNotTemplate: 01190 break; 01191 case CXXRecTemplate: 01192 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx); 01193 break; 01194 case CXXRecMemberSpecialization: { 01195 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx); 01196 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 01197 SourceLocation POI = ReadSourceLocation(Record, Idx); 01198 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); 01199 MSI->setPointOfInstantiation(POI); 01200 D->TemplateOrInstantiation = MSI; 01201 break; 01202 } 01203 } 01204 01205 // Load the key function to avoid deserializing every method so we can 01206 // compute it. 01207 if (D->IsCompleteDefinition) { 01208 if (CXXMethodDecl *Key = ReadDeclAs<CXXMethodDecl>(Record, Idx)) 01209 C.KeyFunctions[D] = Key; 01210 } 01211 } 01212 01213 void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { 01214 VisitFunctionDecl(D); 01215 unsigned NumOverridenMethods = Record[Idx++]; 01216 while (NumOverridenMethods--) { 01217 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, 01218 // MD may be initializing. 01219 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx)) 01220 Reader.getContext().addOverriddenMethod(D, MD); 01221 } 01222 } 01223 01224 void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { 01225 VisitCXXMethodDecl(D); 01226 01227 D->IsExplicitSpecified = Record[Idx++]; 01228 D->ImplicitlyDefined = Record[Idx++]; 01229 llvm::tie(D->CtorInitializers, D->NumCtorInitializers) 01230 = Reader.ReadCXXCtorInitializers(F, Record, Idx); 01231 } 01232 01233 void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { 01234 VisitCXXMethodDecl(D); 01235 01236 D->ImplicitlyDefined = Record[Idx++]; 01237 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx); 01238 } 01239 01240 void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { 01241 VisitCXXMethodDecl(D); 01242 D->IsExplicitSpecified = Record[Idx++]; 01243 } 01244 01245 void ASTDeclReader::VisitImportDecl(ImportDecl *D) { 01246 VisitDecl(D); 01247 D->ImportedAndComplete.setPointer(readModule(Record, Idx)); 01248 D->ImportedAndComplete.setInt(Record[Idx++]); 01249 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1); 01250 for (unsigned I = 0, N = Record.back(); I != N; ++I) 01251 StoredLocs[I] = ReadSourceLocation(Record, Idx); 01252 ++Idx; 01253 } 01254 01255 void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { 01256 VisitDecl(D); 01257 D->setColonLoc(ReadSourceLocation(Record, Idx)); 01258 } 01259 01260 void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { 01261 VisitDecl(D); 01262 if (Record[Idx++]) 01263 D->Friend = GetTypeSourceInfo(Record, Idx); 01264 else 01265 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx); 01266 D->NextFriend = Record[Idx++]; 01267 D->UnsupportedFriend = (Record[Idx++] != 0); 01268 D->FriendLoc = ReadSourceLocation(Record, Idx); 01269 } 01270 01271 void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { 01272 VisitDecl(D); 01273 unsigned NumParams = Record[Idx++]; 01274 D->NumParams = NumParams; 01275 D->Params = new TemplateParameterList*[NumParams]; 01276 for (unsigned i = 0; i != NumParams; ++i) 01277 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx); 01278 if (Record[Idx++]) // HasFriendDecl 01279 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx); 01280 else 01281 D->Friend = GetTypeSourceInfo(Record, Idx); 01282 D->FriendLoc = ReadSourceLocation(Record, Idx); 01283 } 01284 01285 void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { 01286 VisitNamedDecl(D); 01287 01288 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx); 01289 TemplateParameterList* TemplateParams 01290 = Reader.ReadTemplateParameterList(F, Record, Idx); 01291 D->init(TemplatedDecl, TemplateParams); 01292 } 01293 01294 ASTDeclReader::RedeclarableResult 01295 ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { 01296 RedeclarableResult Redecl = VisitRedeclarable(D); 01297 01298 // Make sure we've allocated the Common pointer first. We do this before 01299 // VisitTemplateDecl so that getCommonPtr() can be used during initialization. 01300 RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); 01301 if (!CanonD->Common) { 01302 CanonD->Common = CanonD->newCommon(Reader.getContext()); 01303 Reader.PendingDefinitions.insert(CanonD); 01304 } 01305 D->Common = CanonD->Common; 01306 01307 // If this is the first declaration of the template, fill in the information 01308 // for the 'common' pointer. 01309 if (ThisDeclID == Redecl.getFirstID()) { 01310 if (RedeclarableTemplateDecl *RTD 01311 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) { 01312 assert(RTD->getKind() == D->getKind() && 01313 "InstantiatedFromMemberTemplate kind mismatch"); 01314 D->setInstantiatedFromMemberTemplate(RTD); 01315 if (Record[Idx++]) 01316 D->setMemberSpecialization(); 01317 } 01318 } 01319 01320 VisitTemplateDecl(D); 01321 D->IdentifierNamespace = Record[Idx++]; 01322 01323 return Redecl; 01324 } 01325 01326 void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { 01327 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); 01328 01329 if (ThisDeclID == Redecl.getFirstID()) { 01330 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of 01331 // the specializations. 01332 SmallVector<serialization::DeclID, 2> SpecIDs; 01333 SpecIDs.push_back(0); 01334 01335 // Specializations. 01336 unsigned Size = Record[Idx++]; 01337 SpecIDs[0] += Size; 01338 for (unsigned I = 0; I != Size; ++I) 01339 SpecIDs.push_back(ReadDeclID(Record, Idx)); 01340 01341 // Partial specializations. 01342 Size = Record[Idx++]; 01343 SpecIDs[0] += Size; 01344 for (unsigned I = 0; I != Size; ++I) 01345 SpecIDs.push_back(ReadDeclID(Record, Idx)); 01346 01347 if (SpecIDs[0]) { 01348 typedef serialization::DeclID DeclID; 01349 01350 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr(); 01351 // FIXME: Append specializations! 01352 CommonPtr->LazySpecializations 01353 = new (Reader.getContext()) DeclID [SpecIDs.size()]; 01354 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(), 01355 SpecIDs.size() * sizeof(DeclID)); 01356 } 01357 01358 // InjectedClassNameType is computed. 01359 } 01360 } 01361 01362 void ASTDeclReader::VisitClassTemplateSpecializationDecl( 01363 ClassTemplateSpecializationDecl *D) { 01364 VisitCXXRecordDecl(D); 01365 01366 ASTContext &C = Reader.getContext(); 01367 if (Decl *InstD = ReadDecl(Record, Idx)) { 01368 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { 01369 D->SpecializedTemplate = CTD; 01370 } else { 01371 SmallVector<TemplateArgument, 8> TemplArgs; 01372 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); 01373 TemplateArgumentList *ArgList 01374 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), 01375 TemplArgs.size()); 01376 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS 01377 = new (C) ClassTemplateSpecializationDecl:: 01378 SpecializedPartialSpecialization(); 01379 PS->PartialSpecialization 01380 = cast<ClassTemplatePartialSpecializationDecl>(InstD); 01381 PS->TemplateArgs = ArgList; 01382 D->SpecializedTemplate = PS; 01383 } 01384 } 01385 01386 // Explicit info. 01387 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) { 01388 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo 01389 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; 01390 ExplicitInfo->TypeAsWritten = TyInfo; 01391 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx); 01392 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx); 01393 D->ExplicitInfo = ExplicitInfo; 01394 } 01395 01396 SmallVector<TemplateArgument, 8> TemplArgs; 01397 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); 01398 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), 01399 TemplArgs.size()); 01400 D->PointOfInstantiation = ReadSourceLocation(Record, Idx); 01401 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++]; 01402 01403 if (D->isCanonicalDecl()) { // It's kept in the folding set. 01404 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx); 01405 if (ClassTemplatePartialSpecializationDecl *Partial 01406 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { 01407 CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial); 01408 } else { 01409 CanonPattern->getCommonPtr()->Specializations.InsertNode(D); 01410 } 01411 } 01412 } 01413 01414 void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( 01415 ClassTemplatePartialSpecializationDecl *D) { 01416 VisitClassTemplateSpecializationDecl(D); 01417 01418 ASTContext &C = Reader.getContext(); 01419 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx); 01420 01421 unsigned NumArgs = Record[Idx++]; 01422 if (NumArgs) { 01423 D->NumArgsAsWritten = NumArgs; 01424 D->ArgsAsWritten = new (C) TemplateArgumentLoc[NumArgs]; 01425 for (unsigned i=0; i != NumArgs; ++i) 01426 D->ArgsAsWritten[i] = Reader.ReadTemplateArgumentLoc(F, Record, Idx); 01427 } 01428 01429 D->SequenceNumber = Record[Idx++]; 01430 01431 // These are read/set from/to the first declaration. 01432 if (D->getPreviousDecl() == 0) { 01433 D->InstantiatedFromMember.setPointer( 01434 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx)); 01435 D->InstantiatedFromMember.setInt(Record[Idx++]); 01436 } 01437 } 01438 01439 void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( 01440 ClassScopeFunctionSpecializationDecl *D) { 01441 VisitDecl(D); 01442 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx); 01443 } 01444 01445 void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { 01446 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); 01447 01448 if (ThisDeclID == Redecl.getFirstID()) { 01449 // This FunctionTemplateDecl owns a CommonPtr; read it. 01450 01451 // Read the function specialization declarations. 01452 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled 01453 // when reading the specialized FunctionDecl. 01454 unsigned NumSpecs = Record[Idx++]; 01455 while (NumSpecs--) 01456 (void)ReadDecl(Record, Idx); 01457 } 01458 } 01459 01460 void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { 01461 VisitTypeDecl(D); 01462 01463 D->setDeclaredWithTypename(Record[Idx++]); 01464 01465 bool Inherited = Record[Idx++]; 01466 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx); 01467 D->setDefaultArgument(DefArg, Inherited); 01468 } 01469 01470 void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { 01471 VisitDeclaratorDecl(D); 01472 // TemplateParmPosition. 01473 D->setDepth(Record[Idx++]); 01474 D->setPosition(Record[Idx++]); 01475 if (D->isExpandedParameterPack()) { 01476 void **Data = reinterpret_cast<void **>(D + 1); 01477 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { 01478 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr(); 01479 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx); 01480 } 01481 } else { 01482 // Rest of NonTypeTemplateParmDecl. 01483 D->ParameterPack = Record[Idx++]; 01484 if (Record[Idx++]) { 01485 Expr *DefArg = Reader.ReadExpr(F); 01486 bool Inherited = Record[Idx++]; 01487 D->setDefaultArgument(DefArg, Inherited); 01488 } 01489 } 01490 } 01491 01492 void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { 01493 VisitTemplateDecl(D); 01494 // TemplateParmPosition. 01495 D->setDepth(Record[Idx++]); 01496 D->setPosition(Record[Idx++]); 01497 // Rest of TemplateTemplateParmDecl. 01498 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx); 01499 bool IsInherited = Record[Idx++]; 01500 D->setDefaultArgument(Arg, IsInherited); 01501 D->ParameterPack = Record[Idx++]; 01502 } 01503 01504 void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { 01505 VisitRedeclarableTemplateDecl(D); 01506 } 01507 01508 void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { 01509 VisitDecl(D); 01510 D->AssertExpr = Reader.ReadExpr(F); 01511 D->Message = cast<StringLiteral>(Reader.ReadExpr(F)); 01512 D->RParenLoc = ReadSourceLocation(Record, Idx); 01513 } 01514 01515 std::pair<uint64_t, uint64_t> 01516 ASTDeclReader::VisitDeclContext(DeclContext *DC) { 01517 uint64_t LexicalOffset = Record[Idx++]; 01518 uint64_t VisibleOffset = Record[Idx++]; 01519 return std::make_pair(LexicalOffset, VisibleOffset); 01520 } 01521 01522 template <typename T> 01523 ASTDeclReader::RedeclarableResult 01524 ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { 01525 DeclID FirstDeclID = ReadDeclID(Record, Idx); 01526 01527 // 0 indicates that this declaration was the only declaration of its entity, 01528 // and is used for space optimization. 01529 if (FirstDeclID == 0) 01530 FirstDeclID = ThisDeclID; 01531 01532 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID)); 01533 if (FirstDecl != D) { 01534 // We delay loading of the redeclaration chain to avoid deeply nested calls. 01535 // We temporarily set the first (canonical) declaration as the previous one 01536 // which is the one that matters and mark the real previous DeclID to be 01537 // loaded & attached later on. 01538 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl); 01539 } 01540 01541 // Note that this declaration has been deserialized. 01542 Reader.RedeclsDeserialized.insert(static_cast<T *>(D)); 01543 01544 // The result structure takes care to note that we need to load the 01545 // other declaration chains for this ID. 01546 return RedeclarableResult(Reader, FirstDeclID); 01547 } 01548 01549 /// \brief Attempts to merge the given declaration (D) with another declaration 01550 /// of the same entity. 01551 template<typename T> 01552 void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *D, 01553 RedeclarableResult &Redecl) { 01554 // If modules are not available, there is no reason to perform this merge. 01555 if (!Reader.getContext().getLangOpts().Modules) 01556 return; 01557 01558 if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) { 01559 if (T *Existing = ExistingRes) { 01560 T *ExistingCanon = Existing->getCanonicalDecl(); 01561 T *DCanon = static_cast<T*>(D)->getCanonicalDecl(); 01562 if (ExistingCanon != DCanon) { 01563 // Have our redeclaration link point back at the canonical declaration 01564 // of the existing declaration, so that this declaration has the 01565 // appropriate canonical declaration. 01566 D->RedeclLink 01567 = typename Redeclarable<T>::PreviousDeclLink(ExistingCanon); 01568 01569 // When we merge a namespace, update its pointer to the first namespace. 01570 if (NamespaceDecl *Namespace 01571 = dyn_cast<NamespaceDecl>(static_cast<T*>(D))) { 01572 Namespace->AnonOrFirstNamespaceAndInline.setPointer( 01573 static_cast<NamespaceDecl *>(static_cast<void*>(ExistingCanon))); 01574 } 01575 01576 // Don't introduce DCanon into the set of pending declaration chains. 01577 Redecl.suppress(); 01578 01579 // Introduce ExistingCanon into the set of pending declaration chains, 01580 // if in fact it came from a module file. 01581 if (ExistingCanon->isFromASTFile()) { 01582 GlobalDeclID ExistingCanonID = ExistingCanon->getGlobalID(); 01583 assert(ExistingCanonID && "Unrecorded canonical declaration ID?"); 01584 if (Reader.PendingDeclChainsKnown.insert(ExistingCanonID)) 01585 Reader.PendingDeclChains.push_back(ExistingCanonID); 01586 } 01587 01588 // If this declaration was the canonical declaration, make a note of 01589 // that. We accept the linear algorithm here because the number of 01590 // unique canonical declarations of an entity should always be tiny. 01591 if (DCanon == static_cast<T*>(D)) { 01592 SmallVectorImpl<DeclID> &Merged = Reader.MergedDecls[ExistingCanon]; 01593 if (std::find(Merged.begin(), Merged.end(), Redecl.getFirstID()) 01594 == Merged.end()) 01595 Merged.push_back(Redecl.getFirstID()); 01596 01597 // If ExistingCanon did not come from a module file, introduce the 01598 // first declaration that *does* come from a module file to the 01599 // set of pending declaration chains, so that we merge this 01600 // declaration. 01601 if (!ExistingCanon->isFromASTFile() && 01602 Reader.PendingDeclChainsKnown.insert(Redecl.getFirstID())) 01603 Reader.PendingDeclChains.push_back(Merged[0]); 01604 } 01605 } 01606 } 01607 } 01608 } 01609 01610 //===----------------------------------------------------------------------===// 01611 // Attribute Reading 01612 //===----------------------------------------------------------------------===// 01613 01614 /// \brief Reads attributes from the current stream position. 01615 void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs, 01616 const RecordData &Record, unsigned &Idx) { 01617 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) { 01618 Attr *New = 0; 01619 attr::Kind Kind = (attr::Kind)Record[Idx++]; 01620 SourceRange Range = ReadSourceRange(F, Record, Idx); 01621 01622 #include "clang/Serialization/AttrPCHRead.inc" 01623 01624 assert(New && "Unable to decode attribute?"); 01625 Attrs.push_back(New); 01626 } 01627 } 01628 01629 //===----------------------------------------------------------------------===// 01630 // ASTReader Implementation 01631 //===----------------------------------------------------------------------===// 01632 01633 /// \brief Note that we have loaded the declaration with the given 01634 /// Index. 01635 /// 01636 /// This routine notes that this declaration has already been loaded, 01637 /// so that future GetDecl calls will return this declaration rather 01638 /// than trying to load a new declaration. 01639 inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { 01640 assert(!DeclsLoaded[Index] && "Decl loaded twice?"); 01641 DeclsLoaded[Index] = D; 01642 } 01643 01644 01645 /// \brief Determine whether the consumer will be interested in seeing 01646 /// this declaration (via HandleTopLevelDecl). 01647 /// 01648 /// This routine should return true for anything that might affect 01649 /// code generation, e.g., inline function definitions, Objective-C 01650 /// declarations with metadata, etc. 01651 static bool isConsumerInterestedIn(Decl *D) { 01652 // An ObjCMethodDecl is never considered as "interesting" because its 01653 // implementation container always is. 01654 01655 if (isa<FileScopeAsmDecl>(D) || 01656 isa<ObjCProtocolDecl>(D) || 01657 isa<ObjCImplDecl>(D)) 01658 return true; 01659 if (VarDecl *Var = dyn_cast<VarDecl>(D)) 01660 return Var->isFileVarDecl() && 01661 Var->isThisDeclarationADefinition() == VarDecl::Definition; 01662 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) 01663 return Func->doesThisDeclarationHaveABody(); 01664 01665 return false; 01666 } 01667 01668 /// \brief Get the correct cursor and offset for loading a declaration. 01669 ASTReader::RecordLocation 01670 ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) { 01671 // See if there's an override. 01672 DeclReplacementMap::iterator It = ReplacedDecls.find(ID); 01673 if (It != ReplacedDecls.end()) { 01674 RawLocation = It->second.RawLoc; 01675 return RecordLocation(It->second.Mod, It->second.Offset); 01676 } 01677 01678 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); 01679 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); 01680 ModuleFile *M = I->second; 01681 const DeclOffset & 01682 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]; 01683 RawLocation = DOffs.Loc; 01684 return RecordLocation(M, DOffs.BitOffset); 01685 } 01686 01687 ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { 01688 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I 01689 = GlobalBitOffsetsMap.find(GlobalOffset); 01690 01691 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map"); 01692 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); 01693 } 01694 01695 uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) { 01696 return LocalOffset + M.GlobalBitOffset; 01697 } 01698 01699 /// \brief Determine whether the two declarations refer to the same entity. 01700 static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { 01701 assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!"); 01702 01703 if (X == Y) 01704 return true; 01705 01706 // Must be in the same context. 01707 if (!X->getDeclContext()->getRedeclContext()->Equals( 01708 Y->getDeclContext()->getRedeclContext())) 01709 return false; 01710 01711 // Two typedefs refer to the same entity if they have the same underlying 01712 // type. 01713 if (TypedefNameDecl *TypedefX = dyn_cast<TypedefNameDecl>(X)) 01714 if (TypedefNameDecl *TypedefY = dyn_cast<TypedefNameDecl>(Y)) 01715 return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(), 01716 TypedefY->getUnderlyingType()); 01717 01718 // Must have the same kind. 01719 if (X->getKind() != Y->getKind()) 01720 return false; 01721 01722 // Objective-C classes and protocols with the same name always match. 01723 if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X)) 01724 return true; 01725 01726 // Compatible tags match. 01727 if (TagDecl *TagX = dyn_cast<TagDecl>(X)) { 01728 TagDecl *TagY = cast<TagDecl>(Y); 01729 return (TagX->getTagKind() == TagY->getTagKind()) || 01730 ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class) && 01731 (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class)); 01732 } 01733 01734 // Functions with the same type and linkage match. 01735 // FIXME: This needs to cope with function templates, merging of 01736 //prototyped/non-prototyped functions, etc. 01737 if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) { 01738 FunctionDecl *FuncY = cast<FunctionDecl>(Y); 01739 return (FuncX->getLinkage() == FuncY->getLinkage()) && 01740 FuncX->getASTContext().hasSameType(FuncX->getType(), FuncY->getType()); 01741 } 01742 01743 // Variables with the same type and linkage match. 01744 if (VarDecl *VarX = dyn_cast<VarDecl>(X)) { 01745 VarDecl *VarY = cast<VarDecl>(Y); 01746 return (VarX->getLinkage() == VarY->getLinkage()) && 01747 VarX->getASTContext().hasSameType(VarX->getType(), VarY->getType()); 01748 } 01749 01750 // Namespaces with the same name and inlinedness match. 01751 if (NamespaceDecl *NamespaceX = dyn_cast<NamespaceDecl>(X)) { 01752 NamespaceDecl *NamespaceY = cast<NamespaceDecl>(Y); 01753 return NamespaceX->isInline() == NamespaceY->isInline(); 01754 } 01755 01756 // FIXME: Many other cases to implement. 01757 return false; 01758 } 01759 01760 ASTDeclReader::FindExistingResult::~FindExistingResult() { 01761 if (!AddResult || Existing) 01762 return; 01763 01764 DeclContext *DC = New->getDeclContext()->getRedeclContext(); 01765 if (DC->isTranslationUnit() && Reader.SemaObj) { 01766 Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName()); 01767 } else if (DC->isNamespace()) { 01768 DC->addDecl(New); 01769 } 01770 } 01771 01772 ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { 01773 DeclarationName Name = D->getDeclName(); 01774 if (!Name) { 01775 // Don't bother trying to find unnamed declarations. 01776 FindExistingResult Result(Reader, D, /*Existing=*/0); 01777 Result.suppress(); 01778 return Result; 01779 } 01780 01781 DeclContext *DC = D->getDeclContext()->getRedeclContext(); 01782 if (!DC->isFileContext()) 01783 return FindExistingResult(Reader); 01784 01785 if (DC->isTranslationUnit() && Reader.SemaObj) { 01786 IdentifierResolver &IdResolver = Reader.SemaObj->IdResolver; 01787 for (IdentifierResolver::iterator I = IdResolver.begin(Name), 01788 IEnd = IdResolver.end(); 01789 I != IEnd; ++I) { 01790 if (isSameEntity(*I, D)) 01791 return FindExistingResult(Reader, D, *I); 01792 } 01793 } 01794 01795 if (DC->isNamespace()) { 01796 for (DeclContext::lookup_result R = DC->lookup(Name); 01797 R.first != R.second; ++R.first) { 01798 if (isSameEntity(*R.first, D)) 01799 return FindExistingResult(Reader, D, *R.first); 01800 } 01801 } 01802 01803 return FindExistingResult(Reader, D, /*Existing=*/0); 01804 } 01805 01806 void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) { 01807 assert(D && previous); 01808 if (TagDecl *TD = dyn_cast<TagDecl>(D)) { 01809 TD->RedeclLink.setPointer(cast<TagDecl>(previous)); 01810 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 01811 FD->RedeclLink.setPointer(cast<FunctionDecl>(previous)); 01812 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { 01813 VD->RedeclLink.setPointer(cast<VarDecl>(previous)); 01814 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) { 01815 TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous)); 01816 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { 01817 ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous)); 01818 } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { 01819 PD->RedeclLink.setPointer(cast<ObjCProtocolDecl>(previous)); 01820 } else if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D)) { 01821 ND->RedeclLink.setPointer(cast<NamespaceDecl>(previous)); 01822 } else { 01823 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D); 01824 TD->RedeclLink.setPointer(cast<RedeclarableTemplateDecl>(previous)); 01825 } 01826 } 01827 01828 void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { 01829 assert(D && Latest); 01830 if (TagDecl *TD = dyn_cast<TagDecl>(D)) { 01831 TD->RedeclLink 01832 = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest)); 01833 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 01834 FD->RedeclLink 01835 = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest)); 01836 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { 01837 VD->RedeclLink 01838 = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest)); 01839 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) { 01840 TD->RedeclLink 01841 = Redeclarable<TypedefNameDecl>::LatestDeclLink( 01842 cast<TypedefNameDecl>(Latest)); 01843 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { 01844 ID->RedeclLink 01845 = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink( 01846 cast<ObjCInterfaceDecl>(Latest)); 01847 } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { 01848 PD->RedeclLink 01849 = Redeclarable<ObjCProtocolDecl>::LatestDeclLink( 01850 cast<ObjCProtocolDecl>(Latest)); 01851 } else if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D)) { 01852 ND->RedeclLink 01853 = Redeclarable<NamespaceDecl>::LatestDeclLink( 01854 cast<NamespaceDecl>(Latest)); 01855 } else { 01856 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D); 01857 TD->RedeclLink 01858 = Redeclarable<RedeclarableTemplateDecl>::LatestDeclLink( 01859 cast<RedeclarableTemplateDecl>(Latest)); 01860 } 01861 } 01862 01863 ASTReader::MergedDeclsMap::iterator 01864 ASTReader::combineStoredMergedDecls(Decl *Canon, GlobalDeclID CanonID) { 01865 // If we don't have any stored merged declarations, just look in the 01866 // merged declarations set. 01867 StoredMergedDeclsMap::iterator StoredPos = StoredMergedDecls.find(CanonID); 01868 if (StoredPos == StoredMergedDecls.end()) 01869 return MergedDecls.find(Canon); 01870 01871 // Append the stored merged declarations to the merged declarations set. 01872 MergedDeclsMap::iterator Pos = MergedDecls.find(Canon); 01873 if (Pos == MergedDecls.end()) 01874 Pos = MergedDecls.insert(std::make_pair(Canon, 01875 SmallVector<DeclID, 2>())).first; 01876 Pos->second.append(StoredPos->second.begin(), StoredPos->second.end()); 01877 StoredMergedDecls.erase(StoredPos); 01878 01879 // Sort and uniquify the set of merged declarations. 01880 llvm::array_pod_sort(Pos->second.begin(), Pos->second.end()); 01881 Pos->second.erase(std::unique(Pos->second.begin(), Pos->second.end()), 01882 Pos->second.end()); 01883 return Pos; 01884 } 01885 01886 void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) { 01887 Decl *previous = GetDecl(ID); 01888 ASTDeclReader::attachPreviousDecl(D, previous); 01889 } 01890 01891 /// \brief Read the declaration at the given offset from the AST file. 01892 Decl *ASTReader::ReadDeclRecord(DeclID ID) { 01893 unsigned Index = ID - NUM_PREDEF_DECL_IDS; 01894 unsigned RawLocation = 0; 01895 RecordLocation Loc = DeclCursorForID(ID, RawLocation); 01896 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; 01897 // Keep track of where we are in the stream, then jump back there 01898 // after reading this declaration. 01899 SavedStreamPosition SavedPosition(DeclsCursor); 01900 01901 ReadingKindTracker ReadingKind(Read_Decl, *this); 01902 01903 // Note that we are loading a declaration record. 01904 Deserializing ADecl(this); 01905 01906 DeclsCursor.JumpToBit(Loc.Offset); 01907 RecordData Record; 01908 unsigned Code = DeclsCursor.ReadCode(); 01909 unsigned Idx = 0; 01910 ASTDeclReader Reader(*this, *Loc.F, DeclsCursor, ID, RawLocation, Record,Idx); 01911 01912 Decl *D = 0; 01913 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) { 01914 case DECL_CONTEXT_LEXICAL: 01915 case DECL_CONTEXT_VISIBLE: 01916 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord"); 01917 case DECL_TYPEDEF: 01918 D = TypedefDecl::CreateDeserialized(Context, ID); 01919 break; 01920 case DECL_TYPEALIAS: 01921 D = TypeAliasDecl::CreateDeserialized(Context, ID); 01922 break; 01923 case DECL_ENUM: 01924 D = EnumDecl::CreateDeserialized(Context, ID); 01925 break; 01926 case DECL_RECORD: 01927 D = RecordDecl::CreateDeserialized(Context, ID); 01928 break; 01929 case DECL_ENUM_CONSTANT: 01930 D = EnumConstantDecl::CreateDeserialized(Context, ID); 01931 break; 01932 case DECL_FUNCTION: 01933 D = FunctionDecl::CreateDeserialized(Context, ID); 01934 break; 01935 case DECL_LINKAGE_SPEC: 01936 D = LinkageSpecDecl::CreateDeserialized(Context, ID); 01937 break; 01938 case DECL_LABEL: 01939 D = LabelDecl::CreateDeserialized(Context, ID); 01940 break; 01941 case DECL_NAMESPACE: 01942 D = NamespaceDecl::CreateDeserialized(Context, ID); 01943 break; 01944 case DECL_NAMESPACE_ALIAS: 01945 D = NamespaceAliasDecl::CreateDeserialized(Context, ID); 01946 break; 01947 case DECL_USING: 01948 D = UsingDecl::CreateDeserialized(Context, ID); 01949 break; 01950 case DECL_USING_SHADOW: 01951 D = UsingShadowDecl::CreateDeserialized(Context, ID); 01952 break; 01953 case DECL_USING_DIRECTIVE: 01954 D = UsingDirectiveDecl::CreateDeserialized(Context, ID); 01955 break; 01956 case DECL_UNRESOLVED_USING_VALUE: 01957 D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID); 01958 break; 01959 case DECL_UNRESOLVED_USING_TYPENAME: 01960 D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID); 01961 break; 01962 case DECL_CXX_RECORD: 01963 D = CXXRecordDecl::CreateDeserialized(Context, ID); 01964 break; 01965 case DECL_CXX_METHOD: 01966 D = CXXMethodDecl::CreateDeserialized(Context, ID); 01967 break; 01968 case DECL_CXX_CONSTRUCTOR: 01969 D = CXXConstructorDecl::CreateDeserialized(Context, ID); 01970 break; 01971 case DECL_CXX_DESTRUCTOR: 01972 D = CXXDestructorDecl::CreateDeserialized(Context, ID); 01973 break; 01974 case DECL_CXX_CONVERSION: 01975 D = CXXConversionDecl::CreateDeserialized(Context, ID); 01976 break; 01977 case DECL_ACCESS_SPEC: 01978 D = AccessSpecDecl::CreateDeserialized(Context, ID); 01979 break; 01980 case DECL_FRIEND: 01981 D = FriendDecl::CreateDeserialized(Context, ID); 01982 break; 01983 case DECL_FRIEND_TEMPLATE: 01984 D = FriendTemplateDecl::CreateDeserialized(Context, ID); 01985 break; 01986 case DECL_CLASS_TEMPLATE: 01987 D = ClassTemplateDecl::CreateDeserialized(Context, ID); 01988 break; 01989 case DECL_CLASS_TEMPLATE_SPECIALIZATION: 01990 D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID); 01991 break; 01992 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: 01993 D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); 01994 break; 01995 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION: 01996 D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID); 01997 break; 01998 case DECL_FUNCTION_TEMPLATE: 01999 D = FunctionTemplateDecl::CreateDeserialized(Context, ID); 02000 break; 02001 case DECL_TEMPLATE_TYPE_PARM: 02002 D = TemplateTypeParmDecl::CreateDeserialized(Context, ID); 02003 break; 02004 case DECL_NON_TYPE_TEMPLATE_PARM: 02005 D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID); 02006 break; 02007 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK: 02008 D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, Record[Idx++]); 02009 break; 02010 case DECL_TEMPLATE_TEMPLATE_PARM: 02011 D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID); 02012 break; 02013 case DECL_TYPE_ALIAS_TEMPLATE: 02014 D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID); 02015 break; 02016 case DECL_STATIC_ASSERT: 02017 D = StaticAssertDecl::CreateDeserialized(Context, ID); 02018 break; 02019 case DECL_OBJC_METHOD: 02020 D = ObjCMethodDecl::CreateDeserialized(Context, ID); 02021 break; 02022 case DECL_OBJC_INTERFACE: 02023 D = ObjCInterfaceDecl::CreateDeserialized(Context, ID); 02024 break; 02025 case DECL_OBJC_IVAR: 02026 D = ObjCIvarDecl::CreateDeserialized(Context, ID); 02027 break; 02028 case DECL_OBJC_PROTOCOL: 02029 D = ObjCProtocolDecl::CreateDeserialized(Context, ID); 02030 break; 02031 case DECL_OBJC_AT_DEFS_FIELD: 02032 D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID); 02033 break; 02034 case DECL_OBJC_CATEGORY: 02035 D = ObjCCategoryDecl::CreateDeserialized(Context, ID); 02036 break; 02037 case DECL_OBJC_CATEGORY_IMPL: 02038 D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID); 02039 break; 02040 case DECL_OBJC_IMPLEMENTATION: 02041 D = ObjCImplementationDecl::CreateDeserialized(Context, ID); 02042 break; 02043 case DECL_OBJC_COMPATIBLE_ALIAS: 02044 D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID); 02045 break; 02046 case DECL_OBJC_PROPERTY: 02047 D = ObjCPropertyDecl::CreateDeserialized(Context, ID); 02048 break; 02049 case DECL_OBJC_PROPERTY_IMPL: 02050 D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID); 02051 break; 02052 case DECL_FIELD: 02053 D = FieldDecl::CreateDeserialized(Context, ID); 02054 break; 02055 case DECL_INDIRECTFIELD: 02056 D = IndirectFieldDecl::CreateDeserialized(Context, ID); 02057 break; 02058 case DECL_VAR: 02059 D = VarDecl::CreateDeserialized(Context, ID); 02060 break; 02061 case DECL_IMPLICIT_PARAM: 02062 D = ImplicitParamDecl::CreateDeserialized(Context, ID); 02063 break; 02064 case DECL_PARM_VAR: 02065 D = ParmVarDecl::CreateDeserialized(Context, ID); 02066 break; 02067 case DECL_FILE_SCOPE_ASM: 02068 D = FileScopeAsmDecl::CreateDeserialized(Context, ID); 02069 break; 02070 case DECL_BLOCK: 02071 D = BlockDecl::CreateDeserialized(Context, ID); 02072 break; 02073 case DECL_CXX_BASE_SPECIFIERS: 02074 Error("attempt to read a C++ base-specifier record as a declaration"); 02075 return 0; 02076 case DECL_IMPORT: 02077 // Note: last entry of the ImportDecl record is the number of stored source 02078 // locations. 02079 D = ImportDecl::CreateDeserialized(Context, ID, Record.back()); 02080 break; 02081 } 02082 02083 assert(D && "Unknown declaration reading AST file"); 02084 LoadedDecl(Index, D); 02085 // Set the DeclContext before doing any deserialization, to make sure internal 02086 // calls to Decl::getASTContext() by Decl's methods will find the 02087 // TranslationUnitDecl without crashing. 02088 D->setDeclContext(Context.getTranslationUnitDecl()); 02089 Reader.Visit(D); 02090 02091 // If this declaration is also a declaration context, get the 02092 // offsets for its tables of lexical and visible declarations. 02093 if (DeclContext *DC = dyn_cast<DeclContext>(D)) { 02094 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); 02095 if (Offsets.first || Offsets.second) { 02096 if (Offsets.first != 0) 02097 DC->setHasExternalLexicalStorage(true); 02098 if (Offsets.second != 0) 02099 DC->setHasExternalVisibleStorage(true); 02100 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets, 02101 Loc.F->DeclContextInfos[DC])) 02102 return 0; 02103 } 02104 02105 // Now add the pending visible updates for this decl context, if it has any. 02106 DeclContextVisibleUpdatesPending::iterator I = 02107 PendingVisibleUpdates.find(ID); 02108 if (I != PendingVisibleUpdates.end()) { 02109 // There are updates. This means the context has external visible 02110 // storage, even if the original stored version didn't. 02111 DC->setHasExternalVisibleStorage(true); 02112 DeclContextVisibleUpdates &U = I->second; 02113 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end(); 02114 UI != UE; ++UI) { 02115 DeclContextInfo &Info = UI->second->DeclContextInfos[DC]; 02116 delete Info.NameLookupTableData; 02117 Info.NameLookupTableData = UI->first; 02118 } 02119 PendingVisibleUpdates.erase(I); 02120 } 02121 } 02122 assert(Idx == Record.size()); 02123 02124 // Load any relevant update records. 02125 loadDeclUpdateRecords(ID, D); 02126 02127 // Load the categories after recursive loading is finished. 02128 if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D)) 02129 if (Class->isThisDeclarationADefinition()) 02130 loadObjCCategories(ID, Class); 02131 02132 // If we have deserialized a declaration that has a definition the 02133 // AST consumer might need to know about, queue it. 02134 // We don't pass it to the consumer immediately because we may be in recursive 02135 // loading, and some declarations may still be initializing. 02136 if (isConsumerInterestedIn(D)) 02137 InterestingDecls.push_back(D); 02138 02139 return D; 02140 } 02141 02142 void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) { 02143 // The declaration may have been modified by files later in the chain. 02144 // If this is the case, read the record containing the updates from each file 02145 // and pass it to ASTDeclReader to make the modifications. 02146 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); 02147 if (UpdI != DeclUpdateOffsets.end()) { 02148 FileOffsetsTy &UpdateOffsets = UpdI->second; 02149 for (FileOffsetsTy::iterator 02150 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) { 02151 ModuleFile *F = I->first; 02152 uint64_t Offset = I->second; 02153 llvm::BitstreamCursor &Cursor = F->DeclsCursor; 02154 SavedStreamPosition SavedPosition(Cursor); 02155 Cursor.JumpToBit(Offset); 02156 RecordData Record; 02157 unsigned Code = Cursor.ReadCode(); 02158 unsigned RecCode = Cursor.ReadRecord(Code, Record); 02159 (void)RecCode; 02160 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!"); 02161 02162 unsigned Idx = 0; 02163 ASTDeclReader Reader(*this, *F, Cursor, ID, 0, Record, Idx); 02164 Reader.UpdateDecl(D, *F, Record); 02165 } 02166 } 02167 } 02168 02169 namespace { 02170 struct CompareLocalRedeclarationsInfoToID { 02171 bool operator()(const LocalRedeclarationsInfo &X, DeclID Y) { 02172 return X.FirstID < Y; 02173 } 02174 02175 bool operator()(DeclID X, const LocalRedeclarationsInfo &Y) { 02176 return X < Y.FirstID; 02177 } 02178 02179 bool operator()(const LocalRedeclarationsInfo &X, 02180 const LocalRedeclarationsInfo &Y) { 02181 return X.FirstID < Y.FirstID; 02182 } 02183 bool operator()(DeclID X, DeclID Y) { 02184 return X < Y; 02185 } 02186 }; 02187 02188 /// \brief Module visitor class that finds all of the redeclarations of a 02189 /// 02190 class RedeclChainVisitor { 02191 ASTReader &Reader; 02192 SmallVectorImpl<DeclID> &SearchDecls; 02193 llvm::SmallPtrSet<Decl *, 16> &Deserialized; 02194 GlobalDeclID CanonID; 02195 llvm::SmallVector<Decl *, 4> Chain; 02196 02197 public: 02198 RedeclChainVisitor(ASTReader &Reader, SmallVectorImpl<DeclID> &SearchDecls, 02199 llvm::SmallPtrSet<Decl *, 16> &Deserialized, 02200 GlobalDeclID CanonID) 02201 : Reader(Reader), SearchDecls(SearchDecls), Deserialized(Deserialized), 02202 CanonID(CanonID) { 02203 for (unsigned I = 0, N = SearchDecls.size(); I != N; ++I) 02204 addToChain(Reader.GetDecl(SearchDecls[I])); 02205 } 02206 02207 static bool visit(ModuleFile &M, bool Preorder, void *UserData) { 02208 if (Preorder) 02209 return false; 02210 02211 return static_cast<RedeclChainVisitor *>(UserData)->visit(M); 02212 } 02213 02214 void addToChain(Decl *D) { 02215 if (!D) 02216 return; 02217 02218 if (Deserialized.count(D)) { 02219 Deserialized.erase(D); 02220 Chain.push_back(D); 02221 } 02222 } 02223 02224 void searchForID(ModuleFile &M, GlobalDeclID GlobalID) { 02225 // Map global ID of the first declaration down to the local ID 02226 // used in this module file. 02227 DeclID ID = Reader.mapGlobalIDToModuleFileGlobalID(M, GlobalID); 02228 if (!ID) 02229 return; 02230 02231 // Perform a binary search to find the local redeclarations for this 02232 // declaration (if any). 02233 const LocalRedeclarationsInfo *Result 02234 = std::lower_bound(M.RedeclarationsMap, 02235 M.RedeclarationsMap + M.LocalNumRedeclarationsInMap, 02236 ID, CompareLocalRedeclarationsInfoToID()); 02237 if (Result == M.RedeclarationsMap + M.LocalNumRedeclarationsInMap || 02238 Result->FirstID != ID) { 02239 // If we have a previously-canonical singleton declaration that was 02240 // merged into another redeclaration chain, create a trivial chain 02241 // for this single declaration so that it will get wired into the 02242 // complete redeclaration chain. 02243 if (GlobalID != CanonID && 02244 GlobalID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID && 02245 GlobalID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls) { 02246 addToChain(Reader.GetDecl(GlobalID)); 02247 } 02248 02249 return; 02250 } 02251 02252 // Dig out all of the redeclarations. 02253 unsigned Offset = Result->Offset; 02254 unsigned N = M.RedeclarationChains[Offset]; 02255 M.RedeclarationChains[Offset++] = 0; // Don't try to deserialize again 02256 for (unsigned I = 0; I != N; ++I) 02257 addToChain(Reader.GetLocalDecl(M, M.RedeclarationChains[Offset++])); 02258 } 02259 02260 bool visit(ModuleFile &M) { 02261 // Visit each of the declarations. 02262 for (unsigned I = 0, N = SearchDecls.size(); I != N; ++I) 02263 searchForID(M, SearchDecls[I]); 02264 return false; 02265 } 02266 02267 ArrayRef<Decl *> getChain() const { 02268 return Chain; 02269 } 02270 }; 02271 } 02272 02273 void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) { 02274 Decl *D = GetDecl(ID); 02275 Decl *CanonDecl = D->getCanonicalDecl(); 02276 02277 // Determine the set of declaration IDs we'll be searching for. 02278 llvm::SmallVector<DeclID, 1> SearchDecls; 02279 GlobalDeclID CanonID = 0; 02280 if (D == CanonDecl) { 02281 SearchDecls.push_back(ID); // Always first. 02282 CanonID = ID; 02283 } 02284 MergedDeclsMap::iterator MergedPos = combineStoredMergedDecls(CanonDecl, ID); 02285 if (MergedPos != MergedDecls.end()) 02286 SearchDecls.append(MergedPos->second.begin(), MergedPos->second.end()); 02287 02288 // Build up the list of redeclarations. 02289 RedeclChainVisitor Visitor(*this, SearchDecls, RedeclsDeserialized, CanonID); 02290 ModuleMgr.visitDepthFirst(&RedeclChainVisitor::visit, &Visitor); 02291 02292 // Retrieve the chains. 02293 ArrayRef<Decl *> Chain = Visitor.getChain(); 02294 if (Chain.empty()) 02295 return; 02296 02297 // Hook up the chains. 02298 Decl *MostRecent = CanonDecl->getMostRecentDecl(); 02299 for (unsigned I = 0, N = Chain.size(); I != N; ++I) { 02300 if (Chain[I] == CanonDecl) 02301 continue; 02302 02303 ASTDeclReader::attachPreviousDecl(Chain[I], MostRecent); 02304 MostRecent = Chain[I]; 02305 } 02306 02307 ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent); 02308 } 02309 02310 namespace { 02311 struct CompareObjCCategoriesInfo { 02312 bool operator()(const ObjCCategoriesInfo &X, DeclID Y) { 02313 return X.DefinitionID < Y; 02314 } 02315 02316 bool operator()(DeclID X, const ObjCCategoriesInfo &Y) { 02317 return X < Y.DefinitionID; 02318 } 02319 02320 bool operator()(const ObjCCategoriesInfo &X, 02321 const ObjCCategoriesInfo &Y) { 02322 return X.DefinitionID < Y.DefinitionID; 02323 } 02324 bool operator()(DeclID X, DeclID Y) { 02325 return X < Y; 02326 } 02327 }; 02328 02329 /// \brief Given an ObjC interface, goes through the modules and links to the 02330 /// interface all the categories for it. 02331 class ObjCCategoriesVisitor { 02332 ASTReader &Reader; 02333 serialization::GlobalDeclID InterfaceID; 02334 ObjCInterfaceDecl *Interface; 02335 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> &Deserialized; 02336 unsigned PreviousGeneration; 02337 ObjCCategoryDecl *Tail; 02338 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap; 02339 02340 void add(ObjCCategoryDecl *Cat) { 02341 // Only process each category once. 02342 if (!Deserialized.count(Cat)) 02343 return; 02344 Deserialized.erase(Cat); 02345 02346 // Check for duplicate categories. 02347 if (Cat->getDeclName()) { 02348 ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()]; 02349 if (Existing && 02350 Reader.getOwningModuleFile(Existing) 02351 != Reader.getOwningModuleFile(Cat)) { 02352 // FIXME: We should not warn for duplicates in diamond: 02353 // 02354 // MT // 02355 // / \ // 02356 // ML MR // 02357 // \ / // 02358 // MB // 02359 // 02360 // If there are duplicates in ML/MR, there will be warning when 02361 // creating MB *and* when importing MB. We should not warn when 02362 // importing. 02363 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def) 02364 << Interface->getDeclName() << Cat->getDeclName(); 02365 Reader.Diag(Existing->getLocation(), diag::note_previous_definition); 02366 } else if (!Existing) { 02367 // Record this category. 02368 Existing = Cat; 02369 } 02370 } 02371 02372 // Add this category to the end of the chain. 02373 if (Tail) 02374 ASTDeclReader::setNextObjCCategory(Tail, Cat); 02375 else 02376 Interface->setCategoryList(Cat); 02377 Tail = Cat; 02378 } 02379 02380 public: 02381 ObjCCategoriesVisitor(ASTReader &Reader, 02382 serialization::GlobalDeclID InterfaceID, 02383 ObjCInterfaceDecl *Interface, 02384 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> &Deserialized, 02385 unsigned PreviousGeneration) 02386 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface), 02387 Deserialized(Deserialized), PreviousGeneration(PreviousGeneration), 02388 Tail(0) 02389 { 02390 // Populate the name -> category map with the set of known categories. 02391 for (ObjCCategoryDecl *Cat = Interface->getCategoryList(); Cat; 02392 Cat = Cat->getNextClassCategory()) { 02393 if (Cat->getDeclName()) 02394 NameCategoryMap[Cat->getDeclName()] = Cat; 02395 02396 // Keep track of the tail of the category list. 02397 Tail = Cat; 02398 } 02399 } 02400 02401 static bool visit(ModuleFile &M, void *UserData) { 02402 return static_cast<ObjCCategoriesVisitor *>(UserData)->visit(M); 02403 } 02404 02405 bool visit(ModuleFile &M) { 02406 // If we've loaded all of the category information we care about from 02407 // this module file, we're done. 02408 if (M.Generation <= PreviousGeneration) 02409 return true; 02410 02411 // Map global ID of the definition down to the local ID used in this 02412 // module file. If there is no such mapping, we'll find nothing here 02413 // (or in any module it imports). 02414 DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID); 02415 if (!LocalID) 02416 return true; 02417 02418 // Perform a binary search to find the local redeclarations for this 02419 // declaration (if any). 02420 const ObjCCategoriesInfo *Result 02421 = std::lower_bound(M.ObjCCategoriesMap, 02422 M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, 02423 LocalID, CompareObjCCategoriesInfo()); 02424 if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || 02425 Result->DefinitionID != LocalID) { 02426 // We didn't find anything. If the class definition is in this module 02427 // file, then the module files it depends on cannot have any categories, 02428 // so suppress further lookup. 02429 return Reader.isDeclIDFromModule(InterfaceID, M); 02430 } 02431 02432 // We found something. Dig out all of the categories. 02433 unsigned Offset = Result->Offset; 02434 unsigned N = M.ObjCCategories[Offset]; 02435 M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again 02436 for (unsigned I = 0; I != N; ++I) 02437 add(cast_or_null<ObjCCategoryDecl>( 02438 Reader.GetLocalDecl(M, M.ObjCCategories[Offset++]))); 02439 return true; 02440 } 02441 }; 02442 } 02443 02444 void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, 02445 ObjCInterfaceDecl *D, 02446 unsigned PreviousGeneration) { 02447 ObjCCategoriesVisitor Visitor(*this, ID, D, CategoriesDeserialized, 02448 PreviousGeneration); 02449 ModuleMgr.visit(ObjCCategoriesVisitor::visit, &Visitor); 02450 } 02451 02452 void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile, 02453 const RecordData &Record) { 02454 unsigned Idx = 0; 02455 while (Idx < Record.size()) { 02456 switch ((DeclUpdateKind)Record[Idx++]) { 02457 case UPD_CXX_ADDED_IMPLICIT_MEMBER: 02458 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx)); 02459 break; 02460 02461 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: 02462 // It will be added to the template's specializations set when loaded. 02463 (void)Reader.ReadDecl(ModuleFile, Record, Idx); 02464 break; 02465 02466 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { 02467 NamespaceDecl *Anon 02468 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx); 02469 02470 // Each module has its own anonymous namespace, which is disjoint from 02471 // any other module's anonymous namespaces, so don't attach the anonymous 02472 // namespace at all. 02473 if (ModuleFile.Kind != MK_Module) { 02474 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D)) 02475 TU->setAnonymousNamespace(Anon); 02476 else 02477 cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon); 02478 } 02479 break; 02480 } 02481 02482 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: 02483 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation( 02484 Reader.ReadSourceLocation(ModuleFile, Record, Idx)); 02485 break; 02486 } 02487 } 02488 }