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