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