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