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