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