Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===// |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file implements the ASTReader::ReadDeclRecord method, which is the |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 11 | // entrypoint for loading a decl. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 15 | #include "clang/Serialization/ASTReader.h" |
Chris Lattner | 698f925 | 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 | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
| 21 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 22 | #include "clang/AST/Expr.h" |
| 23 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 24 | using namespace clang::serialization; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 25 | |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | // Declaration deserialization |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 30 | namespace clang { |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 31 | class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 32 | ASTReader &Reader; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 33 | llvm::BitstreamCursor &Cursor; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 34 | const DeclID ThisDeclID; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 35 | const ASTReader::RecordData &Record; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 36 | unsigned &Idx; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 37 | TypeID TypeIDForTypeDecl; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 38 | |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 39 | uint64_t GetCurrentCursorOffset(); |
| 40 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 41 | public: |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 42 | ASTDeclReader(ASTReader &Reader, llvm::BitstreamCursor &Cursor, |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 43 | DeclID thisDeclID, const ASTReader::RecordData &Record, |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 44 | unsigned &Idx) |
| 45 | : Reader(Reader), Cursor(Cursor), ThisDeclID(thisDeclID), Record(Record), |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 46 | Idx(Idx), TypeIDForTypeDecl(0) { } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 47 | |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 48 | void Visit(Decl *D); |
| 49 | |
Chris Lattner | 698f925 | 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 | 0cef483 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 53 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 54 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 55 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 56 | void VisitTypeDecl(TypeDecl *TD); |
| 57 | void VisitTypedefDecl(TypedefDecl *TD); |
Argyrios Kyrtzidis | 8f4eae9 | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 58 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Chris Lattner | 698f925 | 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 | 6ad9ac0 | 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 | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 68 | void VisitValueDecl(ValueDecl *VD); |
| 69 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Argyrios Kyrtzidis | 8f4eae9 | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 70 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 71 | void VisitDeclaratorDecl(DeclaratorDecl *DD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 72 | void VisitFunctionDecl(FunctionDecl *FD); |
Chris Lattner | 6ad9ac0 | 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 | 698f925 | 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 | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 81 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 82 | void VisitTemplateDecl(TemplateDecl *D); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 83 | void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 84 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 85 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 86 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Argyrios Kyrtzidis | b01a552 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 87 | void VisitUsingDecl(UsingDecl *D); |
| 88 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 89 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 90 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 91 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 92 | void VisitFriendDecl(FriendDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 93 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 94 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 95 | void VisitBlockDecl(BlockDecl *BD); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 96 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 97 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 98 | template <typename T> void VisitRedeclarable(Redeclarable<T> *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 99 | |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 100 | // FIXME: Reorder according to DeclNodes.td? |
Chris Lattner | 698f925 | 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 | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 119 | uint64_t ASTDeclReader::GetCurrentCursorOffset() { |
Sebastian Redl | 577d479 | 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 | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 122 | ASTReader::PerFileData &F = *Reader.Chain[N - I - 1]; |
Sebastian Redl | 577d479 | 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 | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 132 | void ASTDeclReader::Visit(Decl *D) { |
| 133 | DeclVisitor<ASTDeclReader, void>::Visit(D); |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 134 | |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 135 | if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) { |
Douglas Gregor | deacbdc | 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 | 9146832 | 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 | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 141 | FD->setLazyBody(GetCurrentCursorOffset()); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 142 | } |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 145 | void ASTDeclReader::VisitDecl(Decl *D) { |
Chris Lattner | 698f925 | 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++]); |
Sean Hunt | cf807c4 | 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 | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 156 | D->setImplicit(Record[Idx++]); |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 157 | D->setUsed(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 158 | D->setAccess((AccessSpecifier)Record[Idx++]); |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 159 | D->setPCHLevel(Record[Idx++] + 1); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 162 | void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 163 | VisitDecl(TU); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 164 | TU->setAnonymousNamespace( |
| 165 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 168 | void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 169 | VisitDecl(ND); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | ND->setDeclName(Reader.ReadDeclarationName(Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 173 | void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 174 | VisitNamedDecl(TD); |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 175 | // Delay type reading until after we have fully initialized the decl. |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 176 | TypeIDForTypeDecl = Record[Idx++]; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 179 | void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 180 | VisitTypeDecl(TD); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 181 | TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 184 | void ASTDeclReader::VisitTagDecl(TagDecl *TD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 185 | VisitTypeDecl(TD); |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 186 | TD->IdentifierNamespace = Record[Idx++]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 187 | VisitRedeclarable(TD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 188 | TD->setTagKind((TagDecl::TagKind)Record[Idx++]); |
| 189 | TD->setDefinition(Record[Idx++]); |
Douglas Gregor | b37b648 | 2010-02-12 17:40:34 +0000 | [diff] [blame] | 190 | TD->setEmbeddedInDeclarator(Record[Idx++]); |
Argyrios Kyrtzidis | ad93a74 | 2009-07-14 03:18:02 +0000 | [diff] [blame] | 191 | TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 192 | TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
John McCall | b621766 | 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 | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 198 | void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 199 | VisitTagDecl(ED); |
| 200 | ED->setIntegerType(Reader.GetType(Record[Idx++])); |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 201 | ED->setPromotionType(Reader.GetType(Record[Idx++])); |
John McCall | 1b5a618 | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 202 | ED->setNumPositiveBits(Record[Idx++]); |
| 203 | ED->setNumNegativeBits(Record[Idx++]); |
Argyrios Kyrtzidis | 7422827 | 2010-07-06 15:36:48 +0000 | [diff] [blame] | 204 | ED->setInstantiationOfMemberEnum( |
| 205 | cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 208 | void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 209 | VisitTagDecl(RD); |
| 210 | RD->setHasFlexibleArrayMember(Record[Idx++]); |
| 211 | RD->setAnonymousStructOrUnion(Record[Idx++]); |
Fariborz Jahanian | 643b7df | 2009-07-08 16:37:44 +0000 | [diff] [blame] | 212 | RD->setHasObjectMember(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 215 | void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 216 | VisitNamedDecl(VD); |
| 217 | VD->setType(Reader.GetType(Record[Idx++])); |
| 218 | } |
| 219 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 220 | void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 221 | VisitValueDecl(ECD); |
| 222 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 223 | ECD->setInitExpr(Reader.ReadExpr(Cursor)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 224 | ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); |
| 225 | } |
| 226 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 227 | void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 228 | VisitValueDecl(DD); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 229 | TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 230 | if (TInfo) |
| 231 | DD->setTypeSourceInfo(TInfo); |
John McCall | b621766 | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 232 | // FIXME: read optional qualifier and its range. |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 235 | void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 236 | VisitDeclaratorDecl(FD); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 237 | // FIXME: read DeclarationNameLoc. |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 238 | |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 239 | FD->IdentifierNamespace = Record[Idx++]; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 240 | switch ((FunctionDecl::TemplatedKind)Record[Idx++]) { |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 241 | default: assert(false && "Unhandled TemplatedKind!"); |
| 242 | break; |
Argyrios Kyrtzidis | f511ba6 | 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 | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 263 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 264 | Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 265 | |
| 266 | // Template args as written. |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 267 | llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 268 | SourceLocation LAngleLoc, RAngleLoc; |
Argyrios Kyrtzidis | 5efb06f | 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 | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 273 | TemplArgLocs.push_back( |
| 274 | Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx)); |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 275 | |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 276 | LAngleLoc = Reader.ReadSourceLocation(Record, Idx); |
| 277 | RAngleLoc = Reader.ReadSourceLocation(Record, Idx); |
| 278 | } |
Argyrios Kyrtzidis | 7b081c8 | 2010-07-05 10:37:55 +0000 | [diff] [blame] | 279 | |
| 280 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 281 | |
Argyrios Kyrtzidis | 2c853e4 | 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 | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 288 | break; |
Argyrios Kyrtzidis | f511ba6 | 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 | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 301 | TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx)); |
Argyrios Kyrtzidis | 7b081c8 | 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 | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 304 | |
| 305 | FD->setDependentTemplateSpecialization(*Reader.getContext(), |
| 306 | TemplDecls, TemplArgs); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 307 | break; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 310 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 311 | // FunctionDecl's body is handled last at ASTDeclReader::Visit, |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 312 | // after everything else is read. |
| 313 | |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 314 | VisitRedeclarable(FD); |
Argyrios Kyrtzidis | 5efb06f | 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 | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 328 | // Read in the parameters. |
Chris Lattner | 698f925 | 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 | 838db38 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 334 | FD->setParams(Params.data(), NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 337 | void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
Chris Lattner | 698f925 | 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 | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 342 | MD->setBody(Reader.ReadStmt(Cursor)); |
Chris Lattner | 698f925 | 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 | 3fe1041 | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 349 | MD->setDefined(Record[Idx++]); |
Chris Lattner | 698f925 | 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 | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 352 | MD->setNumSelectorArgs(unsigned(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 353 | MD->setResultType(Reader.GetType(Record[Idx++])); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 354 | MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); |
Chris Lattner | 698f925 | 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 | 4ecb25f | 2010-04-09 15:40:42 +0000 | [diff] [blame] | 361 | MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams, |
| 362 | NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 365 | void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 366 | VisitNamedDecl(CD); |
Ted Kremenek | 782f2f5 | 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 | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 372 | void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 373 | VisitObjCContainerDecl(ID); |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 374 | ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
Chris Lattner | 698f925 | 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 | 18df52b | 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 | 698f925 | 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 | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 393 | ID->setCategoryList( |
| 394 | cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 395 | ID->setForwardDecl(Record[Idx++]); |
| 396 | ID->setImplicitInterfaceDecl(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 397 | ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 398 | ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Argyrios Kyrtzidis | c999f1f | 2009-07-18 00:33:23 +0000 | [diff] [blame] | 399 | ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 402 | void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 403 | VisitFieldDecl(IVD); |
| 404 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); |
Fariborz Jahanian | ac0021b | 2010-07-17 18:35:47 +0000 | [diff] [blame] | 405 | bool synth = Record[Idx++]; |
| 406 | IVD->setSynthesize(synth); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 409 | void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 410 | VisitObjCContainerDecl(PD); |
| 411 | PD->setForwardDecl(Record[Idx++]); |
| 412 | PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 413 | unsigned NumProtoRefs = Record[Idx++]; |
| 414 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 415 | ProtoRefs.reserve(NumProtoRefs); |
| 416 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 417 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 418 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 419 | ProtoLocs.reserve(NumProtoRefs); |
| 420 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 421 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 422 | PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 423 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 426 | void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 427 | VisitFieldDecl(FD); |
| 428 | } |
| 429 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 430 | void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 431 | VisitDecl(CD); |
| 432 | unsigned NumClassRefs = Record[Idx++]; |
| 433 | llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs; |
| 434 | ClassRefs.reserve(NumClassRefs); |
| 435 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 436 | ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 437 | llvm::SmallVector<SourceLocation, 16> SLocs; |
| 438 | SLocs.reserve(NumClassRefs); |
| 439 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 440 | SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 441 | CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(), |
| 442 | NumClassRefs); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 445 | void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 446 | VisitDecl(FPD); |
| 447 | unsigned NumProtoRefs = Record[Idx++]; |
| 448 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 449 | ProtoRefs.reserve(NumProtoRefs); |
| 450 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 451 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 452 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 453 | ProtoLocs.reserve(NumProtoRefs); |
| 454 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 455 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 456 | FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 457 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 460 | void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 461 | VisitObjCContainerDecl(CD); |
| 462 | CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 463 | unsigned NumProtoRefs = Record[Idx++]; |
| 464 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 465 | ProtoRefs.reserve(NumProtoRefs); |
| 466 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 467 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 468 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 469 | ProtoLocs.reserve(NumProtoRefs); |
| 470 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 471 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 472 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 473 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 474 | CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 475 | CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 476 | CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 479 | void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 480 | VisitNamedDecl(CAD); |
| 481 | CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 482 | } |
| 483 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 484 | void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 485 | VisitNamedDecl(D); |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 486 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 487 | D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 488 | // FIXME: stable encoding |
| 489 | D->setPropertyAttributes( |
| 490 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
Fariborz Jahanian | 80aa1cd | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 491 | D->setPropertyAttributesAsWritten( |
| 492 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 493 | // FIXME: stable encoding |
| 494 | D->setPropertyImplementation( |
| 495 | (ObjCPropertyDecl::PropertyControl)Record[Idx++]); |
| 496 | D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 497 | D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 498 | D->setGetterMethodDecl( |
| 499 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 500 | D->setSetterMethodDecl( |
| 501 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 502 | D->setPropertyIvarDecl( |
| 503 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 504 | } |
| 505 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 506 | void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | aecae62 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 507 | VisitObjCContainerDecl(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 508 | D->setClassInterface( |
| 509 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 512 | void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 513 | VisitObjCImplDecl(D); |
| 514 | D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx)); |
| 515 | } |
| 516 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 517 | void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 518 | VisitObjCImplDecl(D); |
| 519 | D->setSuperClass( |
| 520 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Argyrios Kyrtzidis | 9d50c06 | 2010-08-09 10:54:20 +0000 | [diff] [blame] | 521 | llvm::tie(D->IvarInitializers, D->NumIvarInitializers) |
| 522 | = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 526 | void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 527 | VisitDecl(D); |
| 528 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 529 | D->setPropertyDecl( |
| 530 | cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 531 | D->setPropertyIvarDecl( |
| 532 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Argyrios Kyrtzidis | 2f92230 | 2010-08-09 10:54:37 +0000 | [diff] [blame] | 533 | D->setGetterCXXConstructor(Reader.ReadExpr(Cursor)); |
| 534 | D->setSetterCXXAssignment(Reader.ReadExpr(Cursor)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 537 | void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 538 | VisitDeclaratorDecl(FD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 539 | FD->setMutable(Record[Idx++]); |
| 540 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 541 | FD->setBitWidth(Reader.ReadExpr(Cursor)); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 542 | if (!FD->getDeclName()) { |
| 543 | FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])); |
| 544 | if (Tmpl) |
| 545 | Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); |
| 546 | } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 549 | void ASTDeclReader::VisitVarDecl(VarDecl *VD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 550 | VisitDeclaratorDecl(VD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 551 | VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]); |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 552 | VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 553 | VD->setThreadSpecified(Record[Idx++]); |
| 554 | VD->setCXXDirectInitializer(Record[Idx++]); |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 555 | VD->setExceptionVariable(Record[Idx++]); |
Douglas Gregor | 5077c38 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 556 | VD->setNRVOVariable(Record[Idx++]); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 557 | VisitRedeclarable(VD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 558 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 559 | VD->setInit(Reader.ReadExpr(Cursor)); |
Argyrios Kyrtzidis | 9421adc | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 560 | |
| 561 | if (Record[Idx++]) { // HasMemberSpecializationInfo. |
| 562 | VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++])); |
| 563 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 564 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 565 | Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); |
| 566 | } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 569 | void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 570 | VisitVarDecl(PD); |
| 571 | } |
| 572 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 573 | void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 574 | VisitVarDecl(PD); |
| 575 | PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 576 | PD->setHasInheritedDefaultArg(Record[Idx++]); |
Argyrios Kyrtzidis | 691d77f | 2010-07-04 21:44:07 +0000 | [diff] [blame] | 577 | if (Record[Idx++]) // hasUninstantiatedDefaultArg. |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 578 | PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 581 | void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 582 | VisitDecl(AD); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 583 | AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 586 | void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 587 | VisitDecl(BD); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 588 | BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor))); |
| 589 | BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 590 | unsigned NumParams = Record[Idx++]; |
| 591 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 592 | Params.reserve(NumParams); |
| 593 | for (unsigned I = 0; I != NumParams; ++I) |
| 594 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 838db38 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 595 | BD->setParams(Params.data(), NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 598 | void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 599 | VisitDecl(D); |
| 600 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]); |
| 601 | D->setHasBraces(Record[Idx++]); |
| 602 | } |
| 603 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 604 | void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 605 | VisitNamedDecl(D); |
| 606 | D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 607 | D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 608 | D->setNextNamespace( |
| 609 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 610 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 611 | bool IsOriginal = Record[Idx++]; |
Argyrios Kyrtzidis | a038c1d | 2010-07-03 07:57:53 +0000 | [diff] [blame] | 612 | D->OrigOrAnonNamespace.setInt(IsOriginal); |
| 613 | D->OrigOrAnonNamespace.setPointer( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 614 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 615 | } |
| 616 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 617 | void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 618 | VisitNamedDecl(D); |
| 619 | |
| 620 | D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 621 | D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 622 | D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 623 | D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 624 | D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 625 | } |
| 626 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 627 | void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 628 | VisitNamedDecl(D); |
| 629 | D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 630 | D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 631 | D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx)); |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 632 | // FIXME: read the DNLoc component. |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 633 | |
| 634 | // FIXME: It would probably be more efficient to read these into a vector |
| 635 | // and then re-cosntruct the shadow decl set over that vector since it |
| 636 | // would avoid existence checks. |
| 637 | unsigned NumShadows = Record[Idx++]; |
| 638 | for(unsigned I = 0; I != NumShadows; ++I) { |
Argyrios Kyrtzidis | 82f8e79 | 2010-07-08 13:09:41 +0000 | [diff] [blame] | 639 | // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still |
| 640 | // be initializing. |
| 641 | D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 642 | } |
| 643 | D->setTypeName(Record[Idx++]); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 644 | NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
| 645 | if (Pattern) |
| 646 | Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 649 | void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 650 | VisitNamedDecl(D); |
| 651 | D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 652 | D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++]))); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 653 | UsingShadowDecl *Pattern |
| 654 | = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])); |
| 655 | if (Pattern) |
| 656 | Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 659 | void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 660 | VisitNamedDecl(D); |
| 661 | D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 662 | D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 663 | D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 664 | D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 665 | D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 666 | D->setCommonAncestor(cast_or_null<DeclContext>( |
| 667 | Reader.GetDecl(Record[Idx++]))); |
| 668 | } |
| 669 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 670 | void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 671 | VisitValueDecl(D); |
| 672 | D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 673 | D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 674 | D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 675 | // FIXME: read the DNLoc component. |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 678 | void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 679 | UnresolvedUsingTypenameDecl *D) { |
| 680 | VisitTypeDecl(D); |
| 681 | D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 682 | D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 683 | D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 684 | D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 685 | } |
| 686 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 687 | void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 688 | ASTContext &C = *Reader.getContext(); |
| 689 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 690 | // We need to allocate the DefinitionData struct ahead of VisitRecordDecl |
| 691 | // so that the other CXXRecordDecls can get a pointer even when the owner |
| 692 | // is still initializing. |
| 693 | bool OwnsDefinitionData = false; |
| 694 | enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner }; |
| 695 | switch ((DataOwnership)Record[Idx++]) { |
| 696 | default: |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 697 | assert(0 && "Out of sync with ASTDeclWriter or messed up reading"); |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 698 | case Data_NoDefData: |
| 699 | break; |
| 700 | case Data_Owner: |
| 701 | OwnsDefinitionData = true; |
| 702 | D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D); |
| 703 | break; |
| 704 | case Data_NotOwner: |
| 705 | D->DefinitionData |
| 706 | = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData; |
| 707 | break; |
| 708 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 709 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 710 | VisitRecordDecl(D); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 711 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 712 | if (OwnsDefinitionData) { |
| 713 | assert(D->DefinitionData); |
| 714 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 715 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 716 | Data.UserDeclaredConstructor = Record[Idx++]; |
| 717 | Data.UserDeclaredCopyConstructor = Record[Idx++]; |
| 718 | Data.UserDeclaredCopyAssignment = Record[Idx++]; |
| 719 | Data.UserDeclaredDestructor = Record[Idx++]; |
| 720 | Data.Aggregate = Record[Idx++]; |
| 721 | Data.PlainOldData = Record[Idx++]; |
| 722 | Data.Empty = Record[Idx++]; |
| 723 | Data.Polymorphic = Record[Idx++]; |
| 724 | Data.Abstract = Record[Idx++]; |
| 725 | Data.HasTrivialConstructor = Record[Idx++]; |
| 726 | Data.HasTrivialCopyConstructor = Record[Idx++]; |
| 727 | Data.HasTrivialCopyAssignment = Record[Idx++]; |
| 728 | Data.HasTrivialDestructor = Record[Idx++]; |
| 729 | Data.ComputedVisibleConversions = Record[Idx++]; |
| 730 | Data.DeclaredDefaultConstructor = Record[Idx++]; |
| 731 | Data.DeclaredCopyConstructor = Record[Idx++]; |
| 732 | Data.DeclaredCopyAssignment = Record[Idx++]; |
| 733 | Data.DeclaredDestructor = Record[Idx++]; |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 734 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 735 | // setBases() is unsuitable since it may try to iterate the bases of an |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 736 | // uninitialized base. |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 737 | Data.NumBases = Record[Idx++]; |
| 738 | Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases]; |
| 739 | for (unsigned i = 0; i != Data.NumBases; ++i) |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 740 | Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 741 | |
| 742 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 743 | Data.NumVBases = Record[Idx++]; |
| 744 | Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases]; |
| 745 | for (unsigned i = 0; i != Data.NumVBases; ++i) |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 746 | Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 747 | |
| 748 | Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx); |
| 749 | Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx); |
| 750 | assert(Data.Definition && "Data.Definition should be already set!"); |
| 751 | Data.FirstFriend |
| 752 | = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 755 | enum CXXRecKind { |
| 756 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 757 | }; |
| 758 | switch ((CXXRecKind)Record[Idx++]) { |
| 759 | default: |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 760 | assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 761 | case CXXRecNotTemplate: |
| 762 | break; |
| 763 | case CXXRecTemplate: |
| 764 | D->setDescribedClassTemplate( |
| 765 | cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))); |
| 766 | break; |
| 767 | case CXXRecMemberSpecialization: { |
| 768 | CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])); |
| 769 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 770 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 771 | D->setInstantiationOfMemberClass(RD, TSK); |
| 772 | D->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 773 | break; |
| 774 | } |
| 775 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 778 | void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 779 | VisitFunctionDecl(D); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 780 | unsigned NumOverridenMethods = Record[Idx++]; |
| 781 | while (NumOverridenMethods--) { |
| 782 | CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++])); |
| 783 | // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, |
| 784 | // MD may be initializing. |
| 785 | Reader.getContext()->addOverriddenMethod(D, MD); |
| 786 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 789 | void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 790 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 791 | |
| 792 | D->IsExplicitSpecified = Record[Idx++]; |
| 793 | D->ImplicitlyDefined = Record[Idx++]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 794 | llvm::tie(D->BaseOrMemberInitializers, D->NumBaseOrMemberInitializers) |
| 795 | = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 798 | void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 799 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 800 | |
| 801 | D->ImplicitlyDefined = Record[Idx++]; |
| 802 | D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 805 | void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 806 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 807 | D->IsExplicitSpecified = Record[Idx++]; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 810 | void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 811 | VisitDecl(D); |
| 812 | D->setColonLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 813 | } |
| 814 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 815 | void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 816 | VisitDecl(D); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 817 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 818 | D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 819 | else |
| 820 | D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
| 821 | D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++])); |
| 822 | D->FriendLoc = Reader.ReadSourceLocation(Record, Idx); |
| 823 | } |
| 824 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 825 | void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 826 | VisitDecl(D); |
| 827 | unsigned NumParams = Record[Idx++]; |
| 828 | D->NumParams = NumParams; |
| 829 | D->Params = new TemplateParameterList*[NumParams]; |
| 830 | for (unsigned i = 0; i != NumParams; ++i) |
| 831 | D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx); |
| 832 | if (Record[Idx++]) // HasFriendDecl |
| 833 | D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
| 834 | else |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 835 | D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 836 | D->FriendLoc = Reader.ReadSourceLocation(Record, Idx); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 839 | void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 840 | VisitNamedDecl(D); |
| 841 | |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 842 | NamedDecl *TemplatedDecl |
| 843 | = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 844 | TemplateParameterList* TemplateParams |
| 845 | = Reader.ReadTemplateParameterList(Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 846 | D->init(TemplatedDecl, TemplateParams); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 847 | } |
| 848 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 849 | void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 850 | VisitTemplateDecl(D); |
| 851 | |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 852 | D->IdentifierNamespace = Record[Idx++]; |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 853 | RedeclarableTemplateDecl *PrevDecl = |
| 854 | cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
| 855 | assert((PrevDecl == 0 || PrevDecl->getKind() == D->getKind()) && |
| 856 | "PrevDecl kind mismatch"); |
| 857 | if (PrevDecl) |
| 858 | D->CommonOrPrev = PrevDecl; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 859 | if (PrevDecl == 0) { |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 860 | if (RedeclarableTemplateDecl *RTD |
| 861 | = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) { |
| 862 | assert(RTD->getKind() == D->getKind() && |
| 863 | "InstantiatedFromMemberTemplate kind mismatch"); |
| 864 | D->setInstantiatedFromMemberTemplateImpl(RTD); |
| 865 | if (Record[Idx++]) |
| 866 | D->setMemberSpecialization(); |
| 867 | } |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 868 | |
| 869 | RedeclarableTemplateDecl *LatestDecl = |
| 870 | cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 871 | |
| 872 | // This decl is a first one and the latest declaration that it points to is |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 873 | // in the same AST file. However, if this actually needs to point to a |
| 874 | // redeclaration in another AST file, we need to update it by checking |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 875 | // the FirstLatestDeclIDs map which tracks this kind of decls. |
| 876 | assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?"); |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 877 | ASTReader::FirstLatestDeclIDMap::iterator I |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 878 | = Reader.FirstLatestDeclIDs.find(ThisDeclID); |
| 879 | if (I != Reader.FirstLatestDeclIDs.end()) { |
| 880 | Decl *NewLatest = Reader.GetDecl(I->second); |
| 881 | assert((LatestDecl->getLocation().isInvalid() || |
| 882 | NewLatest->getLocation().isInvalid() || |
| 883 | Reader.SourceMgr.isBeforeInTranslationUnit( |
| 884 | LatestDecl->getLocation(), |
| 885 | NewLatest->getLocation())) && |
| 886 | "The new latest is supposed to come after the previous latest"); |
| 887 | LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest); |
| 888 | } |
| 889 | |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 890 | assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch"); |
| 891 | D->getCommonPtr()->Latest = LatestDecl; |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 895 | void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 896 | VisitRedeclarableTemplateDecl(D); |
| 897 | |
| 898 | if (D->getPreviousDeclaration() == 0) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 899 | // This ClassTemplateDecl owns a CommonPtr; read it. |
| 900 | |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 901 | // FoldingSets are filled in VisitClassTemplateSpecializationDecl. |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 902 | unsigned size = Record[Idx++]; |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 903 | while (size--) |
| 904 | cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 905 | |
| 906 | size = Record[Idx++]; |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 907 | while (size--) |
| 908 | cast<ClassTemplatePartialSpecializationDecl>( |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 909 | Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 910 | |
| 911 | // InjectedClassNameType is computed. |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 912 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 915 | void ASTDeclReader::VisitClassTemplateSpecializationDecl( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 916 | ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 917 | VisitCXXRecordDecl(D); |
| 918 | |
| 919 | if (Decl *InstD = Reader.GetDecl(Record[Idx++])) { |
| 920 | if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { |
| 921 | D->setInstantiationOf(CTD); |
| 922 | } else { |
| 923 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 924 | Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 925 | D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD), |
| 926 | TemplArgs.data(), TemplArgs.size()); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | // Explicit info. |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 931 | if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 932 | D->setTypeAsWritten(TyInfo); |
| 933 | D->setExternLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 934 | D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 935 | } |
| 936 | |
| 937 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 938 | Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 939 | D->initTemplateArgs(TemplArgs.data(), TemplArgs.size()); |
| 940 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 941 | if (POI.isValid()) |
| 942 | D->setPointOfInstantiation(POI); |
| 943 | D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]); |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 944 | |
Argyrios Kyrtzidis | bc5ab7c | 2010-07-20 13:59:40 +0000 | [diff] [blame] | 945 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 946 | ClassTemplateDecl *CanonPattern |
| 947 | = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
| 948 | if (ClassTemplatePartialSpecializationDecl *Partial |
| 949 | = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Argyrios Kyrtzidis | 0a67edd | 2010-07-12 21:41:31 +0000 | [diff] [blame] | 950 | CanonPattern->getPartialSpecializations().InsertNode(Partial); |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 951 | } else { |
Argyrios Kyrtzidis | 0a67edd | 2010-07-12 21:41:31 +0000 | [diff] [blame] | 952 | CanonPattern->getSpecializations().InsertNode(D); |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 953 | } |
| 954 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 957 | void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 958 | ClassTemplatePartialSpecializationDecl *D) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 959 | VisitClassTemplateSpecializationDecl(D); |
| 960 | |
| 961 | D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx)); |
| 962 | |
| 963 | TemplateArgumentListInfo ArgInfos; |
| 964 | unsigned NumArgs = Record[Idx++]; |
| 965 | while (NumArgs--) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 966 | ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 967 | D->initTemplateArgsAsWritten(ArgInfos); |
| 968 | |
| 969 | D->setSequenceNumber(Record[Idx++]); |
| 970 | |
| 971 | // These are read/set from/to the first declaration. |
| 972 | if (D->getPreviousDeclaration() == 0) { |
| 973 | D->setInstantiatedFromMember( |
| 974 | cast_or_null<ClassTemplatePartialSpecializationDecl>( |
| 975 | Reader.GetDecl(Record[Idx++]))); |
| 976 | if (Record[Idx++]) |
Argyrios Kyrtzidis | 64a5e2c | 2010-07-09 21:11:35 +0000 | [diff] [blame] | 977 | D->setMemberSpecialization(); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 978 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 981 | void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 982 | VisitRedeclarableTemplateDecl(D); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 983 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 984 | if (D->getPreviousDeclaration() == 0) { |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 985 | // This FunctionTemplateDecl owns a CommonPtr; read it. |
| 986 | |
Argyrios Kyrtzidis | 057d9af | 2010-07-06 15:37:09 +0000 | [diff] [blame] | 987 | // Read the function specialization declarations. |
| 988 | // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled |
| 989 | // through the specialized FunctionDecl's setFunctionTemplateSpecialization. |
| 990 | unsigned NumSpecs = Record[Idx++]; |
| 991 | while (NumSpecs--) |
| 992 | Reader.GetDecl(Record[Idx++]); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 993 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 996 | void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 997 | VisitTypeDecl(D); |
| 998 | |
| 999 | D->setDeclaredWithTypename(Record[Idx++]); |
| 1000 | D->setParameterPack(Record[Idx++]); |
| 1001 | |
| 1002 | bool Inherited = Record[Idx++]; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1003 | TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1004 | D->setDefaultArgument(DefArg, Inherited); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1007 | void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1008 | VisitVarDecl(D); |
| 1009 | // TemplateParmPosition. |
| 1010 | D->setDepth(Record[Idx++]); |
| 1011 | D->setPosition(Record[Idx++]); |
| 1012 | // Rest of NonTypeTemplateParmDecl. |
| 1013 | if (Record[Idx++]) { |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1014 | Expr *DefArg = Reader.ReadExpr(Cursor); |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1015 | bool Inherited = Record[Idx++]; |
| 1016 | D->setDefaultArgument(DefArg, Inherited); |
| 1017 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1020 | void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 1021 | VisitTemplateDecl(D); |
| 1022 | // TemplateParmPosition. |
| 1023 | D->setDepth(Record[Idx++]); |
| 1024 | D->setPosition(Record[Idx++]); |
| 1025 | // Rest of TemplateTemplateParmDecl. |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1026 | TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx); |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 1027 | bool IsInherited = Record[Idx++]; |
| 1028 | D->setDefaultArgument(Arg, IsInherited); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1031 | void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { |
Argyrios Kyrtzidis | 0d39689 | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 1032 | VisitDecl(D); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1033 | D->AssertExpr = Reader.ReadExpr(Cursor); |
| 1034 | D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor)); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1037 | std::pair<uint64_t, uint64_t> |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1038 | ASTDeclReader::VisitDeclContext(DeclContext *DC) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1039 | uint64_t LexicalOffset = Record[Idx++]; |
| 1040 | uint64_t VisibleOffset = Record[Idx++]; |
| 1041 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 1042 | } |
| 1043 | |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1044 | template <typename T> |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1045 | void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1046 | enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest }; |
| 1047 | RedeclKind Kind = (RedeclKind)Record[Idx++]; |
| 1048 | switch (Kind) { |
| 1049 | default: |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1050 | assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up" |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1051 | " reading"); |
| 1052 | case NoRedeclaration: |
| 1053 | break; |
| 1054 | case PointsToPrevious: |
| 1055 | D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink( |
| 1056 | cast_or_null<T>(Reader.GetDecl(Record[Idx++]))); |
| 1057 | break; |
| 1058 | case PointsToLatest: |
| 1059 | D->RedeclLink = typename Redeclarable<T>::LatestDeclLink( |
| 1060 | cast_or_null<T>(Reader.GetDecl(Record[Idx++]))); |
| 1061 | break; |
| 1062 | } |
| 1063 | |
| 1064 | assert(!(Kind == PointsToPrevious && |
| 1065 | Reader.FirstLatestDeclIDs.find(ThisDeclID) != |
| 1066 | Reader.FirstLatestDeclIDs.end()) && |
| 1067 | "This decl is not first, it should not be in the map"); |
| 1068 | if (Kind == PointsToPrevious) |
| 1069 | return; |
| 1070 | |
| 1071 | // This decl is a first one and the latest declaration that it points to is in |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1072 | // the same AST file. However, if this actually needs to point to a |
| 1073 | // redeclaration in another AST file, we need to update it by checking the |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1074 | // FirstLatestDeclIDs map which tracks this kind of decls. |
| 1075 | assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) && |
| 1076 | "Invalid ThisDeclID ?"); |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1077 | ASTReader::FirstLatestDeclIDMap::iterator I |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1078 | = Reader.FirstLatestDeclIDs.find(ThisDeclID); |
| 1079 | if (I != Reader.FirstLatestDeclIDs.end()) { |
| 1080 | Decl *NewLatest = Reader.GetDecl(I->second); |
| 1081 | assert((D->getMostRecentDeclaration()->getLocation().isInvalid() || |
| 1082 | NewLatest->getLocation().isInvalid() || |
| 1083 | Reader.SourceMgr.isBeforeInTranslationUnit( |
| 1084 | D->getMostRecentDeclaration()->getLocation(), |
| 1085 | NewLatest->getLocation())) && |
| 1086 | "The new latest is supposed to come after the previous latest"); |
| 1087 | D->RedeclLink |
| 1088 | = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest)); |
| 1089 | } |
| 1090 | } |
| 1091 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1092 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1093 | // Attribute Reading |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1094 | //===----------------------------------------------------------------------===// |
| 1095 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1096 | /// \brief Reads attributes from the current stream position. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1097 | void ASTReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor, |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 1098 | AttrVec &Attrs) { |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1099 | unsigned Code = DeclsCursor.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | assert(Code == llvm::bitc::UNABBREV_RECORD && |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1101 | "Expected unabbreviated record"); (void)Code; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1103 | RecordData Record; |
| 1104 | unsigned Idx = 0; |
| 1105 | unsigned RecCode = DeclsCursor.ReadRecord(Code, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1106 | assert(RecCode == DECL_ATTR && "Expected attribute record"); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1107 | (void)RecCode; |
| 1108 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1109 | while (Idx < Record.size()) { |
| 1110 | Attr *New = 0; |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1111 | attr::Kind Kind = (attr::Kind)Record[Idx++]; |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 1112 | SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 1113 | bool isInherited = Record[Idx++]; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1114 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 1115 | #include "clang/Serialization/AttrPCHRead.inc" |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1116 | |
| 1117 | assert(New && "Unable to decode attribute?"); |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 1118 | New->setInherited(isInherited); |
| 1119 | Attrs.push_back(New); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1120 | } |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1124 | // ASTReader Implementation |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1125 | //===----------------------------------------------------------------------===// |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1126 | |
| 1127 | /// \brief Note that we have loaded the declaration with the given |
| 1128 | /// Index. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | /// |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1130 | /// This routine notes that this declaration has already been loaded, |
| 1131 | /// so that future GetDecl calls will return this declaration rather |
| 1132 | /// than trying to load a new declaration. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1133 | inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1134 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 1135 | DeclsLoaded[Index] = D; |
| 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | /// \brief Determine whether the consumer will be interested in seeing |
| 1140 | /// this declaration (via HandleTopLevelDecl). |
| 1141 | /// |
| 1142 | /// This routine should return true for anything that might affect |
| 1143 | /// code generation, e.g., inline function definitions, Objective-C |
| 1144 | /// declarations with metadata, etc. |
| 1145 | static bool isConsumerInterestedIn(Decl *D) { |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 1146 | if (isa<FileScopeAsmDecl>(D)) |
| 1147 | return true; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1148 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) |
Argyrios Kyrtzidis | 3f95477 | 2010-08-05 09:47:59 +0000 | [diff] [blame] | 1149 | return Var->isFileVarDecl() && |
| 1150 | Var->isThisDeclarationADefinition() == VarDecl::Definition; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1151 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) |
| 1152 | return Func->isThisDeclarationADefinition(); |
Argyrios Kyrtzidis | 9d50c06 | 2010-08-09 10:54:20 +0000 | [diff] [blame] | 1153 | return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Sebastian Redl | cb526aa | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 1156 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1157 | ASTReader::RecordLocation |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1158 | ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 1159 | // See if there's an override. |
| 1160 | DeclReplacementMap::iterator It = ReplacedDecls.find(ID); |
| 1161 | if (It != ReplacedDecls.end()) |
| 1162 | return RecordLocation(&It->second.first->DeclsCursor, It->second.second); |
| 1163 | |
Sebastian Redl | cb526aa | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 1164 | PerFileData *F = 0; |
| 1165 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1166 | F = Chain[N - I - 1]; |
| 1167 | if (Index < F->LocalNumDecls) |
| 1168 | break; |
| 1169 | Index -= F->LocalNumDecls; |
| 1170 | } |
| 1171 | assert(F && F->LocalNumDecls > Index && "Broken chain"); |
Sebastian Redl | 971dd44 | 2010-07-20 22:55:31 +0000 | [diff] [blame] | 1172 | return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]); |
Sebastian Redl | cb526aa | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1175 | /// \brief Read the declaration at the given offset from the AST file. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1176 | Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 1177 | RecordLocation Loc = DeclCursorForIndex(Index, ID); |
Sebastian Redl | 971dd44 | 2010-07-20 22:55:31 +0000 | [diff] [blame] | 1178 | llvm::BitstreamCursor &DeclsCursor = *Loc.first; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1179 | // Keep track of where we are in the stream, then jump back there |
| 1180 | // after reading this declaration. |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1181 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1182 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 1183 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 1184 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 1185 | // Note that we are loading a declaration record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 1186 | Deserializing ADecl(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | |
Sebastian Redl | cb526aa | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 1188 | DeclsCursor.JumpToBit(Loc.second); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1189 | RecordData Record; |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1190 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1191 | unsigned Idx = 0; |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1192 | ASTDeclReader Reader(*this, DeclsCursor, ID, Record, Idx); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1193 | |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1194 | Decl *D = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1195 | switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 1196 | case DECL_ATTR: |
| 1197 | case DECL_CONTEXT_LEXICAL: |
| 1198 | case DECL_CONTEXT_VISIBLE: |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1199 | assert(false && "Record cannot be de-serialized with ReadDeclRecord"); |
| 1200 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1201 | case DECL_TRANSLATION_UNIT: |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1202 | assert(Index == 0 && "Translation unit must be at index 0"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1203 | D = Context->getTranslationUnitDecl(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1204 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1205 | case DECL_TYPEDEF: |
John McCall | ba6a9bd | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 1206 | D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1207 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1208 | case DECL_ENUM: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1209 | D = EnumDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1210 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1211 | case DECL_RECORD: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1212 | D = RecordDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1213 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1214 | case DECL_ENUM_CONSTANT: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1215 | D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1216 | 0, llvm::APSInt()); |
| 1217 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1218 | case DECL_FUNCTION: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(), |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1220 | QualType(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1221 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1222 | case DECL_LINKAGE_SPEC: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1223 | D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(), |
| 1224 | (LinkageSpecDecl::LanguageIDs)0, |
| 1225 | false); |
| 1226 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1227 | case DECL_NAMESPACE: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1228 | D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0); |
| 1229 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1230 | case DECL_NAMESPACE_ALIAS: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1231 | D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(), |
| 1232 | SourceLocation(), 0, SourceRange(), 0, |
| 1233 | SourceLocation(), 0); |
| 1234 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1235 | case DECL_USING: |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1236 | D = UsingDecl::Create(*Context, 0, SourceRange(), SourceLocation(), |
| 1237 | 0, DeclarationNameInfo(), false); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1238 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1239 | case DECL_USING_SHADOW: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1240 | D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
| 1241 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1242 | case DECL_USING_DIRECTIVE: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1243 | D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(), |
| 1244 | SourceLocation(), SourceRange(), 0, |
| 1245 | SourceLocation(), 0, 0); |
| 1246 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1247 | case DECL_UNRESOLVED_USING_VALUE: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1248 | D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(), |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1249 | SourceRange(), 0, |
| 1250 | DeclarationNameInfo()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1251 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1252 | case DECL_UNRESOLVED_USING_TYPENAME: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1253 | D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(), |
| 1254 | SourceLocation(), SourceRange(), |
| 1255 | 0, SourceLocation(), |
| 1256 | DeclarationName()); |
| 1257 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1258 | case DECL_CXX_RECORD: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1259 | D = CXXRecordDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1260 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1261 | case DECL_CXX_METHOD: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1262 | D = CXXMethodDecl::Create(*Context, 0, DeclarationNameInfo(), |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1263 | QualType(), 0); |
| 1264 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1265 | case DECL_CXX_CONSTRUCTOR: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1266 | D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell()); |
| 1267 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1268 | case DECL_CXX_DESTRUCTOR: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1269 | D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell()); |
| 1270 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1271 | case DECL_CXX_CONVERSION: |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1272 | D = CXXConversionDecl::Create(*Context, Decl::EmptyShell()); |
| 1273 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1274 | case DECL_ACCESS_SPEC: |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1275 | D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(), |
| 1276 | SourceLocation()); |
| 1277 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1278 | case DECL_FRIEND: |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 1279 | D = FriendDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1280 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1281 | case DECL_FRIEND_TEMPLATE: |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1282 | D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1283 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1284 | case DECL_CLASS_TEMPLATE: |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 1285 | D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(), |
| 1286 | DeclarationName(), 0, 0, 0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1287 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1288 | case DECL_CLASS_TEMPLATE_SPECIALIZATION: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1289 | D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1290 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1291 | case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1292 | D = ClassTemplatePartialSpecializationDecl::Create(*Context, |
| 1293 | Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1294 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1295 | case DECL_FUNCTION_TEMPLATE: |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 1296 | D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(), |
| 1297 | DeclarationName(), 0, 0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1298 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1299 | case DECL_TEMPLATE_TYPE_PARM: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1300 | D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1301 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1302 | case DECL_NON_TYPE_TEMPLATE_PARM: |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1303 | D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0, |
| 1304 | QualType(),0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1305 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1306 | case DECL_TEMPLATE_TEMPLATE_PARM: |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 1307 | D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1308 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1309 | case DECL_STATIC_ASSERT: |
Argyrios Kyrtzidis | 0d39689 | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 1310 | D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1311 | break; |
| 1312 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1313 | case DECL_OBJC_METHOD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(), |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 1315 | Selector(), QualType(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1316 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1317 | case DECL_OBJC_INTERFACE: |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 1318 | D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1319 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1320 | case DECL_OBJC_IVAR: |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1321 | D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1322 | ObjCIvarDecl::None); |
| 1323 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1324 | case DECL_OBJC_PROTOCOL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1325 | D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1326 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1327 | case DECL_OBJC_AT_DEFS_FIELD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1329 | QualType(), 0); |
| 1330 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1331 | case DECL_OBJC_CLASS: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1332 | D = ObjCClassDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1333 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1334 | case DECL_OBJC_FORWARD_PROTOCOL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1335 | D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1336 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1337 | case DECL_OBJC_CATEGORY: |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 1338 | D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), |
| 1339 | SourceLocation(), SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1340 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1341 | case DECL_OBJC_CATEGORY_IMPL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1342 | D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1343 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1344 | case DECL_OBJC_IMPLEMENTATION: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1345 | D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1346 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1347 | case DECL_OBJC_COMPATIBLE_ALIAS: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1348 | D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1349 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1350 | case DECL_OBJC_PROPERTY: |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 1351 | D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), |
John McCall | 83a230c | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 1352 | 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1353 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1354 | case DECL_OBJC_PROPERTY_IMPL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1355 | D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1356 | SourceLocation(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1357 | ObjCPropertyImplDecl::Dynamic, 0); |
| 1358 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1359 | case DECL_FIELD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1360 | D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0, |
Argyrios Kyrtzidis | a5d8200 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 1361 | false); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1362 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1363 | case DECL_VAR: |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1364 | D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1365 | VarDecl::None, VarDecl::None); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1366 | break; |
| 1367 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1368 | case DECL_IMPLICIT_PARAM: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1369 | D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1370 | break; |
| 1371 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1372 | case DECL_PARM_VAR: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1374 | VarDecl::None, VarDecl::None, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1375 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1376 | case DECL_FILE_SCOPE_ASM: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1377 | D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1378 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1379 | case DECL_BLOCK: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1380 | D = BlockDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1381 | break; |
| 1382 | } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1383 | |
Sebastian Redl | d527cc0 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1384 | assert(D && "Unknown declaration reading AST file"); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1385 | LoadedDecl(Index, D); |
| 1386 | Reader.Visit(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1387 | |
| 1388 | // If this declaration is also a declaration context, get the |
| 1389 | // offsets for its tables of lexical and visible declarations. |
| 1390 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 1391 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
| 1392 | if (Offsets.first || Offsets.second) { |
| 1393 | DC->setHasExternalLexicalStorage(Offsets.first != 0); |
| 1394 | DC->setHasExternalVisibleStorage(Offsets.second != 0); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1395 | DeclContextInfo Info; |
| 1396 | if (ReadDeclContextStorage(DeclsCursor, Offsets, Info)) |
| 1397 | return 0; |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1398 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 1399 | // Reading the TU will happen after reading its update blocks, so we need |
| 1400 | // to make sure we insert in front. For all other contexts, the vector |
| 1401 | // is empty here anyway, so there's no loss in efficiency. |
| 1402 | Infos.insert(Infos.begin(), Info); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | assert(Idx == Record.size()); |
| 1406 | |
| 1407 | // If we have deserialized a declaration that has a definition the |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 1408 | // AST consumer might need to know about, queue it. |
| 1409 | // We don't pass it to the consumer immediately because we may be in recursive |
| 1410 | // loading, and some declarations may still be initializing. |
| 1411 | if (isConsumerInterestedIn(D)) |
| 1412 | InterestingDecls.push_back(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1413 | |
| 1414 | return D; |
| 1415 | } |