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