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