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