Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1 | //===--- PCHReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===// |
| 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 | // |
| 10 | // This file implements the PCHReader::ReadDeclRecord method, which is the |
| 11 | // entrypoint for loading a decl. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Frontend/PCHReader.h" |
| 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; |
| 24 | |
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 { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 31 | class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> { |
| 32 | PCHReader &Reader; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 33 | llvm::BitstreamCursor &Cursor; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 34 | const pch::DeclID ThisDeclID; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 35 | const PCHReader::RecordData &Record; |
| 36 | unsigned &Idx; |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 37 | pch::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 | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 42 | PCHDeclReader(PCHReader &Reader, llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 43 | pch::DeclID thisDeclID, const PCHReader::RecordData &Record, |
| 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 | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 119 | uint64_t PCHDeclReader::GetCurrentCursorOffset() { |
| 120 | uint64_t Off = 0; |
| 121 | for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) { |
| 122 | PCHReader::PerFileData &F = *Reader.Chain[N - I - 1]; |
| 123 | if (&Cursor == &F.DeclsCursor) { |
| 124 | Off += F.DeclsCursor.GetCurrentBitNo(); |
| 125 | break; |
| 126 | } |
| 127 | Off += F.SizeInBits; |
| 128 | } |
| 129 | return Off; |
| 130 | } |
| 131 | |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 132 | void PCHDeclReader::Visit(Decl *D) { |
| 133 | DeclVisitor<PCHDeclReader, void>::Visit(D); |
| 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 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 145 | void PCHDeclReader::VisitDecl(Decl *D) { |
| 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++]); |
| 151 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 152 | D->initAttrs(Reader.ReadAttributes(Cursor)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 153 | D->setImplicit(Record[Idx++]); |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 154 | D->setUsed(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 155 | D->setAccess((AccessSpecifier)Record[Idx++]); |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 156 | D->setPCHLevel(Record[Idx++] + 1); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
| 160 | VisitDecl(TU); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 161 | TU->setAnonymousNamespace( |
| 162 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) { |
| 166 | VisitDecl(ND); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | ND->setDeclName(Reader.ReadDeclarationName(Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) { |
| 171 | VisitNamedDecl(TD); |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 172 | // Delay type reading until after we have fully initialized the decl. |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 173 | TypeIDForTypeDecl = Record[Idx++]; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Argyrios Kyrtzidis | d8a0c6f | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 177 | VisitTypeDecl(TD); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 178 | TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | void PCHDeclReader::VisitTagDecl(TagDecl *TD) { |
| 182 | VisitTypeDecl(TD); |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 183 | TD->IdentifierNamespace = Record[Idx++]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 184 | VisitRedeclarable(TD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 185 | TD->setTagKind((TagDecl::TagKind)Record[Idx++]); |
| 186 | TD->setDefinition(Record[Idx++]); |
Douglas Gregor | b37b648 | 2010-02-12 17:40:34 +0000 | [diff] [blame] | 187 | TD->setEmbeddedInDeclarator(Record[Idx++]); |
Argyrios Kyrtzidis | ad93a74 | 2009-07-14 03:18:02 +0000 | [diff] [blame] | 188 | TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 189 | TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
John McCall | b621766 | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 190 | // FIXME: maybe read optional qualifier and its range. |
| 191 | TD->setTypedefForAnonDecl( |
| 192 | cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) { |
| 196 | VisitTagDecl(ED); |
| 197 | ED->setIntegerType(Reader.GetType(Record[Idx++])); |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 198 | ED->setPromotionType(Reader.GetType(Record[Idx++])); |
John McCall | 1b5a618 | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 199 | ED->setNumPositiveBits(Record[Idx++]); |
| 200 | ED->setNumNegativeBits(Record[Idx++]); |
Argyrios Kyrtzidis | 7422827 | 2010-07-06 15:36:48 +0000 | [diff] [blame] | 201 | ED->setInstantiationOfMemberEnum( |
| 202 | cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) { |
| 206 | VisitTagDecl(RD); |
| 207 | RD->setHasFlexibleArrayMember(Record[Idx++]); |
| 208 | RD->setAnonymousStructOrUnion(Record[Idx++]); |
Fariborz Jahanian | 643b7df | 2009-07-08 16:37:44 +0000 | [diff] [blame] | 209 | RD->setHasObjectMember(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void PCHDeclReader::VisitValueDecl(ValueDecl *VD) { |
| 213 | VisitNamedDecl(VD); |
| 214 | VD->setType(Reader.GetType(Record[Idx++])); |
| 215 | } |
| 216 | |
| 217 | void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
| 218 | VisitValueDecl(ECD); |
| 219 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 220 | ECD->setInitExpr(Reader.ReadExpr(Cursor)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 221 | ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); |
| 222 | } |
| 223 | |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 224 | void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
| 225 | VisitValueDecl(DD); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 226 | TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 227 | if (TInfo) |
| 228 | DD->setTypeSourceInfo(TInfo); |
John McCall | b621766 | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 229 | // FIXME: read optional qualifier and its range. |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 232 | void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 233 | VisitDeclaratorDecl(FD); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 234 | // FIXME: read DeclarationNameLoc. |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 235 | |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 236 | FD->IdentifierNamespace = Record[Idx++]; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 237 | switch ((FunctionDecl::TemplatedKind)Record[Idx++]) { |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 238 | default: assert(false && "Unhandled TemplatedKind!"); |
| 239 | break; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 240 | case FunctionDecl::TK_NonTemplate: |
| 241 | break; |
| 242 | case FunctionDecl::TK_FunctionTemplate: |
| 243 | FD->setDescribedFunctionTemplate( |
| 244 | cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))); |
| 245 | break; |
| 246 | case FunctionDecl::TK_MemberSpecialization: { |
| 247 | FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++])); |
| 248 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 249 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 250 | FD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 251 | FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 252 | break; |
| 253 | } |
| 254 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 255 | FunctionTemplateDecl *Template |
| 256 | = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
| 257 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 258 | |
| 259 | // Template arguments. |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 260 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 261 | Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 262 | |
| 263 | // Template args as written. |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 264 | llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 265 | SourceLocation LAngleLoc, RAngleLoc; |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 266 | if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0 |
| 267 | unsigned NumTemplateArgLocs = Record[Idx++]; |
| 268 | TemplArgLocs.reserve(NumTemplateArgLocs); |
| 269 | for (unsigned i=0; i != NumTemplateArgLocs; ++i) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 270 | TemplArgLocs.push_back( |
| 271 | Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx)); |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 272 | |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 273 | LAngleLoc = Reader.ReadSourceLocation(Record, Idx); |
| 274 | RAngleLoc = Reader.ReadSourceLocation(Record, Idx); |
| 275 | } |
Argyrios Kyrtzidis | 7b081c8 | 2010-07-05 10:37:55 +0000 | [diff] [blame] | 276 | |
| 277 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 278 | |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 279 | if (FD->isCanonicalDecl()) // if canonical add to template's set. |
| 280 | FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(), |
| 281 | TemplArgs.data(), TSK, |
| 282 | TemplArgLocs.size(), |
| 283 | TemplArgLocs.data(), |
| 284 | LAngleLoc, RAngleLoc, POI); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 285 | break; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 286 | } |
| 287 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 288 | // Templates. |
| 289 | UnresolvedSet<8> TemplDecls; |
| 290 | unsigned NumTemplates = Record[Idx++]; |
| 291 | while (NumTemplates--) |
| 292 | TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 293 | |
| 294 | // Templates args. |
| 295 | TemplateArgumentListInfo TemplArgs; |
| 296 | unsigned NumArgs = Record[Idx++]; |
| 297 | while (NumArgs--) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 298 | TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx)); |
Argyrios Kyrtzidis | 7b081c8 | 2010-07-05 10:37:55 +0000 | [diff] [blame] | 299 | TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 300 | TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx)); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 301 | |
| 302 | FD->setDependentTemplateSpecialization(*Reader.getContext(), |
| 303 | TemplDecls, TemplArgs); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 304 | break; |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 307 | |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 308 | // FunctionDecl's body is handled last at PCHReaderDecl::Visit, |
| 309 | // after everything else is read. |
| 310 | |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 311 | VisitRedeclarable(FD); |
Argyrios Kyrtzidis | 5efb06f | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 312 | FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]); |
| 313 | FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]); |
| 314 | FD->setInlineSpecified(Record[Idx++]); |
| 315 | FD->setVirtualAsWritten(Record[Idx++]); |
| 316 | FD->setPure(Record[Idx++]); |
| 317 | FD->setHasInheritedPrototype(Record[Idx++]); |
| 318 | FD->setHasWrittenPrototype(Record[Idx++]); |
| 319 | FD->setDeleted(Record[Idx++]); |
| 320 | FD->setTrivial(Record[Idx++]); |
| 321 | FD->setCopyAssignment(Record[Idx++]); |
| 322 | FD->setHasImplicitReturnZero(Record[Idx++]); |
| 323 | FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 324 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 325 | // Read in the parameters. |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 326 | unsigned NumParams = Record[Idx++]; |
| 327 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 328 | Params.reserve(NumParams); |
| 329 | for (unsigned I = 0; I != NumParams; ++I) |
| 330 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 838db38 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 331 | FD->setParams(Params.data(), NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
| 335 | VisitNamedDecl(MD); |
| 336 | if (Record[Idx++]) { |
| 337 | // In practice, this won't be executed (since method definitions |
| 338 | // don't occur in header files). |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 339 | MD->setBody(Reader.ReadStmt(Cursor)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 340 | MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 341 | MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 342 | } |
| 343 | MD->setInstanceMethod(Record[Idx++]); |
| 344 | MD->setVariadic(Record[Idx++]); |
| 345 | MD->setSynthesized(Record[Idx++]); |
Fariborz Jahanian | 3fe1041 | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 346 | MD->setDefined(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 347 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); |
| 348 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
Fariborz Jahanian | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 349 | MD->setNumSelectorArgs(unsigned(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 350 | MD->setResultType(Reader.GetType(Record[Idx++])); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 351 | MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 352 | MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 353 | unsigned NumParams = Record[Idx++]; |
| 354 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 355 | Params.reserve(NumParams); |
| 356 | for (unsigned I = 0; I != NumParams; ++I) |
| 357 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Fariborz Jahanian | 4ecb25f | 2010-04-09 15:40:42 +0000 | [diff] [blame] | 358 | MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams, |
| 359 | NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
| 363 | VisitNamedDecl(CD); |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 364 | SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 365 | SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 366 | CD->setAtEndRange(SourceRange(A, B)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
| 370 | VisitObjCContainerDecl(ID); |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 371 | ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 372 | ID->setSuperClass(cast_or_null<ObjCInterfaceDecl> |
| 373 | (Reader.GetDecl(Record[Idx++]))); |
| 374 | unsigned NumProtocols = Record[Idx++]; |
| 375 | llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 376 | Protocols.reserve(NumProtocols); |
| 377 | for (unsigned I = 0; I != NumProtocols; ++I) |
| 378 | Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 379 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 380 | ProtoLocs.reserve(NumProtocols); |
| 381 | for (unsigned I = 0; I != NumProtocols; ++I) |
| 382 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 383 | ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(), |
| 384 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 385 | unsigned NumIvars = Record[Idx++]; |
| 386 | llvm::SmallVector<ObjCIvarDecl *, 16> IVars; |
| 387 | IVars.reserve(NumIvars); |
| 388 | for (unsigned I = 0; I != NumIvars; ++I) |
| 389 | IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 390 | ID->setCategoryList( |
| 391 | cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 392 | ID->setForwardDecl(Record[Idx++]); |
| 393 | ID->setImplicitInterfaceDecl(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 394 | ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 395 | ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Argyrios Kyrtzidis | c999f1f | 2009-07-18 00:33:23 +0000 | [diff] [blame] | 396 | ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
| 400 | VisitFieldDecl(IVD); |
| 401 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); |
Fariborz Jahanian | ac0021b | 2010-07-17 18:35:47 +0000 | [diff] [blame] | 402 | bool synth = Record[Idx++]; |
| 403 | IVD->setSynthesize(synth); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 407 | VisitObjCContainerDecl(PD); |
| 408 | PD->setForwardDecl(Record[Idx++]); |
| 409 | PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 410 | unsigned NumProtoRefs = Record[Idx++]; |
| 411 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 412 | ProtoRefs.reserve(NumProtoRefs); |
| 413 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 414 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 415 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 416 | ProtoLocs.reserve(NumProtoRefs); |
| 417 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 418 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 419 | PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 420 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
| 424 | VisitFieldDecl(FD); |
| 425 | } |
| 426 | |
| 427 | void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) { |
| 428 | VisitDecl(CD); |
| 429 | unsigned NumClassRefs = Record[Idx++]; |
| 430 | llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs; |
| 431 | ClassRefs.reserve(NumClassRefs); |
| 432 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 433 | ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 434 | llvm::SmallVector<SourceLocation, 16> SLocs; |
| 435 | SLocs.reserve(NumClassRefs); |
| 436 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 437 | SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 438 | CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(), |
| 439 | NumClassRefs); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) { |
| 443 | VisitDecl(FPD); |
| 444 | unsigned NumProtoRefs = Record[Idx++]; |
| 445 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 446 | ProtoRefs.reserve(NumProtoRefs); |
| 447 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 448 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 449 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 450 | ProtoLocs.reserve(NumProtoRefs); |
| 451 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 452 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 453 | FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 454 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
| 458 | VisitObjCContainerDecl(CD); |
| 459 | CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 460 | unsigned NumProtoRefs = Record[Idx++]; |
| 461 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 462 | ProtoRefs.reserve(NumProtoRefs); |
| 463 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 464 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 465 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 466 | ProtoLocs.reserve(NumProtoRefs); |
| 467 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 468 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 469 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 470 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 471 | CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 472 | CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 473 | CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
| 477 | VisitNamedDecl(CAD); |
| 478 | CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 479 | } |
| 480 | |
| 481 | void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 482 | VisitNamedDecl(D); |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 483 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 484 | D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 485 | // FIXME: stable encoding |
| 486 | D->setPropertyAttributes( |
| 487 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
Fariborz Jahanian | 80aa1cd | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 488 | D->setPropertyAttributesAsWritten( |
| 489 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 490 | // FIXME: stable encoding |
| 491 | D->setPropertyImplementation( |
| 492 | (ObjCPropertyDecl::PropertyControl)Record[Idx++]); |
| 493 | D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 494 | D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 495 | D->setGetterMethodDecl( |
| 496 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 497 | D->setSetterMethodDecl( |
| 498 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 499 | D->setPropertyIvarDecl( |
| 500 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 501 | } |
| 502 | |
| 503 | void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | aecae62 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 504 | VisitObjCContainerDecl(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 505 | D->setClassInterface( |
| 506 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 510 | VisitObjCImplDecl(D); |
| 511 | D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx)); |
| 512 | } |
| 513 | |
| 514 | void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 515 | VisitObjCImplDecl(D); |
| 516 | D->setSuperClass( |
| 517 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Argyrios Kyrtzidis | 9d50c06 | 2010-08-09 10:54:20 +0000 | [diff] [blame] | 518 | llvm::tie(D->IvarInitializers, D->NumIvarInitializers) |
| 519 | = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
| 523 | void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 524 | VisitDecl(D); |
| 525 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 526 | D->setPropertyDecl( |
| 527 | cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 528 | D->setPropertyIvarDecl( |
| 529 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Argyrios Kyrtzidis | 2f92230 | 2010-08-09 10:54:37 +0000 | [diff] [blame] | 530 | D->setGetterCXXConstructor(Reader.ReadExpr(Cursor)); |
| 531 | D->setSetterCXXAssignment(Reader.ReadExpr(Cursor)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 535 | VisitDeclaratorDecl(FD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 536 | FD->setMutable(Record[Idx++]); |
| 537 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 538 | FD->setBitWidth(Reader.ReadExpr(Cursor)); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 539 | if (!FD->getDeclName()) { |
| 540 | FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])); |
| 541 | if (Tmpl) |
| 542 | Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); |
| 543 | } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | void PCHDeclReader::VisitVarDecl(VarDecl *VD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 547 | VisitDeclaratorDecl(VD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 548 | VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]); |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 549 | VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 550 | VD->setThreadSpecified(Record[Idx++]); |
| 551 | VD->setCXXDirectInitializer(Record[Idx++]); |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 552 | VD->setExceptionVariable(Record[Idx++]); |
Douglas Gregor | 5077c38 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 553 | VD->setNRVOVariable(Record[Idx++]); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 554 | VisitRedeclarable(VD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 555 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 556 | VD->setInit(Reader.ReadExpr(Cursor)); |
Argyrios Kyrtzidis | 9421adc | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 557 | |
| 558 | if (Record[Idx++]) { // HasMemberSpecializationInfo. |
| 559 | VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++])); |
| 560 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 561 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 562 | Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); |
| 563 | } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
| 567 | VisitVarDecl(PD); |
| 568 | } |
| 569 | |
| 570 | void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
| 571 | VisitVarDecl(PD); |
| 572 | PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 573 | PD->setHasInheritedDefaultArg(Record[Idx++]); |
Argyrios Kyrtzidis | 691d77f | 2010-07-04 21:44:07 +0000 | [diff] [blame] | 574 | if (Record[Idx++]) // hasUninstantiatedDefaultArg. |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 575 | PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 578 | void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
| 579 | VisitDecl(AD); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 580 | AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) { |
| 584 | VisitDecl(BD); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 585 | BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor))); |
| 586 | BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 587 | unsigned NumParams = Record[Idx++]; |
| 588 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 589 | Params.reserve(NumParams); |
| 590 | for (unsigned I = 0; I != NumParams; ++I) |
| 591 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 838db38 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 592 | BD->setParams(Params.data(), NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 595 | void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 596 | VisitDecl(D); |
| 597 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]); |
| 598 | D->setHasBraces(Record[Idx++]); |
| 599 | } |
| 600 | |
| 601 | void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
| 602 | VisitNamedDecl(D); |
| 603 | D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 604 | D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 605 | D->setNextNamespace( |
| 606 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 607 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 608 | bool IsOriginal = Record[Idx++]; |
Argyrios Kyrtzidis | a038c1d | 2010-07-03 07:57:53 +0000 | [diff] [blame] | 609 | D->OrigOrAnonNamespace.setInt(IsOriginal); |
| 610 | D->OrigOrAnonNamespace.setPointer( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 611 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 612 | } |
| 613 | |
| 614 | void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 615 | VisitNamedDecl(D); |
| 616 | |
| 617 | D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 618 | D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 619 | D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 620 | D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 621 | D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 622 | } |
| 623 | |
Argyrios Kyrtzidis | b01a552 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 624 | void PCHDeclReader::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 625 | VisitNamedDecl(D); |
| 626 | D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 627 | D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 628 | D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx)); |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 629 | // FIXME: read the DNLoc component. |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 630 | |
| 631 | // FIXME: It would probably be more efficient to read these into a vector |
| 632 | // and then re-cosntruct the shadow decl set over that vector since it |
| 633 | // would avoid existence checks. |
| 634 | unsigned NumShadows = Record[Idx++]; |
| 635 | for(unsigned I = 0; I != NumShadows; ++I) { |
Argyrios Kyrtzidis | 82f8e79 | 2010-07-08 13:09:41 +0000 | [diff] [blame] | 636 | // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still |
| 637 | // be initializing. |
| 638 | D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 639 | } |
| 640 | D->setTypeName(Record[Idx++]); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 641 | NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
| 642 | if (Pattern) |
| 643 | Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Argyrios Kyrtzidis | b01a552 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 646 | void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 647 | VisitNamedDecl(D); |
| 648 | D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 649 | D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++]))); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 650 | UsingShadowDecl *Pattern |
| 651 | = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])); |
| 652 | if (Pattern) |
| 653 | Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 657 | VisitNamedDecl(D); |
| 658 | D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 659 | D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 660 | D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 661 | D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 662 | D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 663 | D->setCommonAncestor(cast_or_null<DeclContext>( |
| 664 | Reader.GetDecl(Record[Idx++]))); |
| 665 | } |
| 666 | |
Argyrios Kyrtzidis | 8f4eae9 | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 667 | void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 668 | VisitValueDecl(D); |
| 669 | D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 670 | D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 671 | D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 672 | // FIXME: read the DNLoc component. |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Argyrios Kyrtzidis | 8f4eae9 | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 675 | void PCHDeclReader::VisitUnresolvedUsingTypenameDecl( |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 676 | UnresolvedUsingTypenameDecl *D) { |
| 677 | VisitTypeDecl(D); |
| 678 | D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 679 | D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 680 | D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 681 | D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 682 | } |
| 683 | |
| 684 | void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 685 | ASTContext &C = *Reader.getContext(); |
| 686 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 687 | // We need to allocate the DefinitionData struct ahead of VisitRecordDecl |
| 688 | // so that the other CXXRecordDecls can get a pointer even when the owner |
| 689 | // is still initializing. |
| 690 | bool OwnsDefinitionData = false; |
| 691 | enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner }; |
| 692 | switch ((DataOwnership)Record[Idx++]) { |
| 693 | default: |
| 694 | assert(0 && "Out of sync with PCHDeclWriter or messed up reading"); |
| 695 | case Data_NoDefData: |
| 696 | break; |
| 697 | case Data_Owner: |
| 698 | OwnsDefinitionData = true; |
| 699 | D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D); |
| 700 | break; |
| 701 | case Data_NotOwner: |
| 702 | D->DefinitionData |
| 703 | = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData; |
| 704 | break; |
| 705 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 706 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 707 | VisitRecordDecl(D); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 708 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 709 | if (OwnsDefinitionData) { |
| 710 | assert(D->DefinitionData); |
| 711 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 712 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 713 | Data.UserDeclaredConstructor = Record[Idx++]; |
| 714 | Data.UserDeclaredCopyConstructor = Record[Idx++]; |
| 715 | Data.UserDeclaredCopyAssignment = Record[Idx++]; |
| 716 | Data.UserDeclaredDestructor = Record[Idx++]; |
| 717 | Data.Aggregate = Record[Idx++]; |
| 718 | Data.PlainOldData = Record[Idx++]; |
| 719 | Data.Empty = Record[Idx++]; |
| 720 | Data.Polymorphic = Record[Idx++]; |
| 721 | Data.Abstract = Record[Idx++]; |
| 722 | Data.HasTrivialConstructor = Record[Idx++]; |
| 723 | Data.HasTrivialCopyConstructor = Record[Idx++]; |
| 724 | Data.HasTrivialCopyAssignment = Record[Idx++]; |
| 725 | Data.HasTrivialDestructor = Record[Idx++]; |
| 726 | Data.ComputedVisibleConversions = Record[Idx++]; |
| 727 | Data.DeclaredDefaultConstructor = Record[Idx++]; |
| 728 | Data.DeclaredCopyConstructor = Record[Idx++]; |
| 729 | Data.DeclaredCopyAssignment = Record[Idx++]; |
| 730 | Data.DeclaredDestructor = Record[Idx++]; |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 731 | |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 732 | // 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] | 733 | // uninitialized base. |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 734 | Data.NumBases = Record[Idx++]; |
| 735 | Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases]; |
| 736 | for (unsigned i = 0; i != Data.NumBases; ++i) |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 737 | Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 738 | |
| 739 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 740 | Data.NumVBases = Record[Idx++]; |
| 741 | Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases]; |
| 742 | for (unsigned i = 0; i != Data.NumVBases; ++i) |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 743 | Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 0f47bb9 | 2010-07-06 15:36:58 +0000 | [diff] [blame] | 744 | |
| 745 | Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx); |
| 746 | Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx); |
| 747 | assert(Data.Definition && "Data.Definition should be already set!"); |
| 748 | Data.FirstFriend |
| 749 | = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 752 | enum CXXRecKind { |
| 753 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 754 | }; |
| 755 | switch ((CXXRecKind)Record[Idx++]) { |
| 756 | default: |
| 757 | assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?"); |
| 758 | case CXXRecNotTemplate: |
| 759 | break; |
| 760 | case CXXRecTemplate: |
| 761 | D->setDescribedClassTemplate( |
| 762 | cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))); |
| 763 | break; |
| 764 | case CXXRecMemberSpecialization: { |
| 765 | CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])); |
| 766 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 767 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 768 | D->setInstantiationOfMemberClass(RD, TSK); |
| 769 | D->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 770 | break; |
| 771 | } |
| 772 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 776 | VisitFunctionDecl(D); |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 777 | unsigned NumOverridenMethods = Record[Idx++]; |
| 778 | while (NumOverridenMethods--) { |
| 779 | CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++])); |
| 780 | // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, |
| 781 | // MD may be initializing. |
| 782 | Reader.getContext()->addOverriddenMethod(D, MD); |
| 783 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 787 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 788 | |
| 789 | D->IsExplicitSpecified = Record[Idx++]; |
| 790 | D->ImplicitlyDefined = Record[Idx++]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 791 | llvm::tie(D->BaseOrMemberInitializers, D->NumBaseOrMemberInitializers) |
| 792 | = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 796 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 797 | |
| 798 | D->ImplicitlyDefined = Record[Idx++]; |
| 799 | D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 803 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 9146832 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 804 | D->IsExplicitSpecified = Record[Idx++]; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 807 | void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 808 | VisitDecl(D); |
| 809 | D->setColonLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 810 | } |
| 811 | |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 812 | void PCHDeclReader::VisitFriendDecl(FriendDecl *D) { |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 813 | VisitDecl(D); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 814 | if (Record[Idx++]) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 815 | D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 816 | else |
| 817 | D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
| 818 | D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++])); |
| 819 | D->FriendLoc = Reader.ReadSourceLocation(Record, Idx); |
| 820 | } |
| 821 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 822 | void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 823 | VisitDecl(D); |
| 824 | unsigned NumParams = Record[Idx++]; |
| 825 | D->NumParams = NumParams; |
| 826 | D->Params = new TemplateParameterList*[NumParams]; |
| 827 | for (unsigned i = 0; i != NumParams; ++i) |
| 828 | D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx); |
| 829 | if (Record[Idx++]) // HasFriendDecl |
| 830 | D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
| 831 | else |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 832 | D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 833 | D->FriendLoc = Reader.ReadSourceLocation(Record, Idx); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 837 | VisitNamedDecl(D); |
| 838 | |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 839 | NamedDecl *TemplatedDecl |
| 840 | = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 841 | TemplateParameterList* TemplateParams |
| 842 | = Reader.ReadTemplateParameterList(Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 843 | D->init(TemplatedDecl, TemplateParams); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 846 | void PCHDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 847 | VisitTemplateDecl(D); |
| 848 | |
Argyrios Kyrtzidis | c8f9af2 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 849 | D->IdentifierNamespace = Record[Idx++]; |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 850 | RedeclarableTemplateDecl *PrevDecl = |
| 851 | cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
| 852 | assert((PrevDecl == 0 || PrevDecl->getKind() == D->getKind()) && |
| 853 | "PrevDecl kind mismatch"); |
| 854 | if (PrevDecl) |
| 855 | D->CommonOrPrev = PrevDecl; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 856 | if (PrevDecl == 0) { |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 857 | if (RedeclarableTemplateDecl *RTD |
| 858 | = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) { |
| 859 | assert(RTD->getKind() == D->getKind() && |
| 860 | "InstantiatedFromMemberTemplate kind mismatch"); |
| 861 | D->setInstantiatedFromMemberTemplateImpl(RTD); |
| 862 | if (Record[Idx++]) |
| 863 | D->setMemberSpecialization(); |
| 864 | } |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 865 | |
| 866 | RedeclarableTemplateDecl *LatestDecl = |
| 867 | cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 868 | |
| 869 | // This decl is a first one and the latest declaration that it points to is |
| 870 | // in the same PCH. However, if this actually needs to point to a |
| 871 | // redeclaration in another chained PCH, we need to update it by checking |
| 872 | // the FirstLatestDeclIDs map which tracks this kind of decls. |
| 873 | assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?"); |
| 874 | PCHReader::FirstLatestDeclIDMap::iterator I |
| 875 | = Reader.FirstLatestDeclIDs.find(ThisDeclID); |
| 876 | if (I != Reader.FirstLatestDeclIDs.end()) { |
| 877 | Decl *NewLatest = Reader.GetDecl(I->second); |
| 878 | assert((LatestDecl->getLocation().isInvalid() || |
| 879 | NewLatest->getLocation().isInvalid() || |
| 880 | Reader.SourceMgr.isBeforeInTranslationUnit( |
| 881 | LatestDecl->getLocation(), |
| 882 | NewLatest->getLocation())) && |
| 883 | "The new latest is supposed to come after the previous latest"); |
| 884 | LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest); |
| 885 | } |
| 886 | |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 887 | assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch"); |
| 888 | D->getCommonPtr()->Latest = LatestDecl; |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
| 892 | void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 893 | VisitRedeclarableTemplateDecl(D); |
| 894 | |
| 895 | if (D->getPreviousDeclaration() == 0) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 896 | // This ClassTemplateDecl owns a CommonPtr; read it. |
| 897 | |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 898 | // FoldingSets are filled in VisitClassTemplateSpecializationDecl. |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 899 | unsigned size = Record[Idx++]; |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 900 | while (size--) |
| 901 | cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 902 | |
| 903 | size = Record[Idx++]; |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 904 | while (size--) |
| 905 | cast<ClassTemplatePartialSpecializationDecl>( |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 906 | Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 907 | |
| 908 | // InjectedClassNameType is computed. |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 909 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | void PCHDeclReader::VisitClassTemplateSpecializationDecl( |
| 913 | ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 914 | VisitCXXRecordDecl(D); |
| 915 | |
| 916 | if (Decl *InstD = Reader.GetDecl(Record[Idx++])) { |
| 917 | if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { |
| 918 | D->setInstantiationOf(CTD); |
| 919 | } else { |
| 920 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 921 | Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 922 | D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD), |
| 923 | TemplArgs.data(), TemplArgs.size()); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | // Explicit info. |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 928 | if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 929 | D->setTypeAsWritten(TyInfo); |
| 930 | D->setExternLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 931 | D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 932 | } |
| 933 | |
| 934 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 935 | Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 936 | D->initTemplateArgs(TemplArgs.data(), TemplArgs.size()); |
| 937 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 938 | if (POI.isValid()) |
| 939 | D->setPointOfInstantiation(POI); |
| 940 | D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]); |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 941 | |
Argyrios Kyrtzidis | bc5ab7c | 2010-07-20 13:59:40 +0000 | [diff] [blame] | 942 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 943 | ClassTemplateDecl *CanonPattern |
| 944 | = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
| 945 | if (ClassTemplatePartialSpecializationDecl *Partial |
| 946 | = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Argyrios Kyrtzidis | 0a67edd | 2010-07-12 21:41:31 +0000 | [diff] [blame] | 947 | CanonPattern->getPartialSpecializations().InsertNode(Partial); |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 948 | } else { |
Argyrios Kyrtzidis | 0a67edd | 2010-07-12 21:41:31 +0000 | [diff] [blame] | 949 | CanonPattern->getSpecializations().InsertNode(D); |
Argyrios Kyrtzidis | ecf966e | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 950 | } |
| 951 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl( |
| 955 | ClassTemplatePartialSpecializationDecl *D) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 956 | VisitClassTemplateSpecializationDecl(D); |
| 957 | |
| 958 | D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx)); |
| 959 | |
| 960 | TemplateArgumentListInfo ArgInfos; |
| 961 | unsigned NumArgs = Record[Idx++]; |
| 962 | while (NumArgs--) |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 963 | ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 964 | D->initTemplateArgsAsWritten(ArgInfos); |
| 965 | |
| 966 | D->setSequenceNumber(Record[Idx++]); |
| 967 | |
| 968 | // These are read/set from/to the first declaration. |
| 969 | if (D->getPreviousDeclaration() == 0) { |
| 970 | D->setInstantiatedFromMember( |
| 971 | cast_or_null<ClassTemplatePartialSpecializationDecl>( |
| 972 | Reader.GetDecl(Record[Idx++]))); |
| 973 | if (Record[Idx++]) |
Argyrios Kyrtzidis | 64a5e2c | 2010-07-09 21:11:35 +0000 | [diff] [blame] | 974 | D->setMemberSpecialization(); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 975 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 978 | void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 979 | VisitRedeclarableTemplateDecl(D); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 980 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 981 | if (D->getPreviousDeclaration() == 0) { |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 982 | // This FunctionTemplateDecl owns a CommonPtr; read it. |
| 983 | |
Argyrios Kyrtzidis | 057d9af | 2010-07-06 15:37:09 +0000 | [diff] [blame] | 984 | // Read the function specialization declarations. |
| 985 | // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled |
| 986 | // through the specialized FunctionDecl's setFunctionTemplateSpecialization. |
| 987 | unsigned NumSpecs = Record[Idx++]; |
| 988 | while (NumSpecs--) |
| 989 | Reader.GetDecl(Record[Idx++]); |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 990 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 994 | VisitTypeDecl(D); |
| 995 | |
| 996 | D->setDeclaredWithTypename(Record[Idx++]); |
| 997 | D->setParameterPack(Record[Idx++]); |
| 998 | |
| 999 | bool Inherited = Record[Idx++]; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1000 | TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1001 | D->setDefaultArgument(DefArg, Inherited); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1005 | VisitVarDecl(D); |
| 1006 | // TemplateParmPosition. |
| 1007 | D->setDepth(Record[Idx++]); |
| 1008 | D->setPosition(Record[Idx++]); |
| 1009 | // Rest of NonTypeTemplateParmDecl. |
| 1010 | if (Record[Idx++]) { |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1011 | Expr *DefArg = Reader.ReadExpr(Cursor); |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1012 | bool Inherited = Record[Idx++]; |
| 1013 | D->setDefaultArgument(DefArg, Inherited); |
| 1014 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 1018 | VisitTemplateDecl(D); |
| 1019 | // TemplateParmPosition. |
| 1020 | D->setDepth(Record[Idx++]); |
| 1021 | D->setPosition(Record[Idx++]); |
| 1022 | // Rest of TemplateTemplateParmDecl. |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1023 | TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx); |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 1024 | bool IsInherited = Record[Idx++]; |
| 1025 | D->setDefaultArgument(Arg, IsInherited); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { |
Argyrios Kyrtzidis | 0d39689 | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 1029 | VisitDecl(D); |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1030 | D->AssertExpr = Reader.ReadExpr(Cursor); |
| 1031 | D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor)); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1034 | std::pair<uint64_t, uint64_t> |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1035 | PCHDeclReader::VisitDeclContext(DeclContext *DC) { |
| 1036 | uint64_t LexicalOffset = Record[Idx++]; |
| 1037 | uint64_t VisibleOffset = Record[Idx++]; |
| 1038 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 1039 | } |
| 1040 | |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1041 | template <typename T> |
| 1042 | void PCHDeclReader::VisitRedeclarable(Redeclarable<T> *D) { |
| 1043 | enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest }; |
| 1044 | RedeclKind Kind = (RedeclKind)Record[Idx++]; |
| 1045 | switch (Kind) { |
| 1046 | default: |
| 1047 | assert(0 && "Out of sync with PCHDeclWriter::VisitRedeclarable or messed up" |
| 1048 | " reading"); |
| 1049 | case NoRedeclaration: |
| 1050 | break; |
| 1051 | case PointsToPrevious: |
| 1052 | D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink( |
| 1053 | cast_or_null<T>(Reader.GetDecl(Record[Idx++]))); |
| 1054 | break; |
| 1055 | case PointsToLatest: |
| 1056 | D->RedeclLink = typename Redeclarable<T>::LatestDeclLink( |
| 1057 | cast_or_null<T>(Reader.GetDecl(Record[Idx++]))); |
| 1058 | break; |
| 1059 | } |
| 1060 | |
| 1061 | assert(!(Kind == PointsToPrevious && |
| 1062 | Reader.FirstLatestDeclIDs.find(ThisDeclID) != |
| 1063 | Reader.FirstLatestDeclIDs.end()) && |
| 1064 | "This decl is not first, it should not be in the map"); |
| 1065 | if (Kind == PointsToPrevious) |
| 1066 | return; |
| 1067 | |
| 1068 | // This decl is a first one and the latest declaration that it points to is in |
| 1069 | // the same PCH. However, if this actually needs to point to a redeclaration |
| 1070 | // in another chained PCH, we need to update it by checking the |
| 1071 | // FirstLatestDeclIDs map which tracks this kind of decls. |
| 1072 | assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) && |
| 1073 | "Invalid ThisDeclID ?"); |
| 1074 | PCHReader::FirstLatestDeclIDMap::iterator I |
| 1075 | = Reader.FirstLatestDeclIDs.find(ThisDeclID); |
| 1076 | if (I != Reader.FirstLatestDeclIDs.end()) { |
| 1077 | Decl *NewLatest = Reader.GetDecl(I->second); |
| 1078 | assert((D->getMostRecentDeclaration()->getLocation().isInvalid() || |
| 1079 | NewLatest->getLocation().isInvalid() || |
| 1080 | Reader.SourceMgr.isBeforeInTranslationUnit( |
| 1081 | D->getMostRecentDeclaration()->getLocation(), |
| 1082 | NewLatest->getLocation())) && |
| 1083 | "The new latest is supposed to come after the previous latest"); |
| 1084 | D->RedeclLink |
| 1085 | = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest)); |
| 1086 | } |
| 1087 | } |
| 1088 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1089 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1090 | // Attribute Reading |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1091 | //===----------------------------------------------------------------------===// |
| 1092 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1093 | /// \brief Reads attributes from the current stream position. |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 1094 | Attr *PCHReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor) { |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1095 | unsigned Code = DeclsCursor.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | assert(Code == llvm::bitc::UNABBREV_RECORD && |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1097 | "Expected unabbreviated record"); (void)Code; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1099 | RecordData Record; |
| 1100 | unsigned Idx = 0; |
| 1101 | unsigned RecCode = DeclsCursor.ReadRecord(Code, Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | assert(RecCode == pch::DECL_ATTR && "Expected attribute record"); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1103 | (void)RecCode; |
| 1104 | |
| 1105 | #define SIMPLE_ATTR(Name) \ |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1106 | case attr::Name: \ |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1107 | New = ::new (*Context) Name##Attr(); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1108 | break |
| 1109 | |
| 1110 | #define STRING_ATTR(Name) \ |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1111 | case attr::Name: \ |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 1112 | New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1113 | break |
| 1114 | |
| 1115 | #define UNSIGNED_ATTR(Name) \ |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1116 | case attr::Name: \ |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1117 | New = ::new (*Context) Name##Attr(Record[Idx++]); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1118 | break |
| 1119 | |
| 1120 | Attr *Attrs = 0; |
| 1121 | while (Idx < Record.size()) { |
| 1122 | Attr *New = 0; |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1123 | attr::Kind Kind = (attr::Kind)Record[Idx++]; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1124 | bool IsInherited = Record[Idx++]; |
| 1125 | |
| 1126 | switch (Kind) { |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 1127 | default: |
| 1128 | assert(0 && "Unknown attribute!"); |
| 1129 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1130 | STRING_ATTR(Alias); |
Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 1131 | SIMPLE_ATTR(AlignMac68k); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1132 | UNSIGNED_ATTR(Aligned); |
| 1133 | SIMPLE_ATTR(AlwaysInline); |
| 1134 | SIMPLE_ATTR(AnalyzerNoReturn); |
| 1135 | STRING_ATTR(Annotate); |
| 1136 | STRING_ATTR(AsmLabel); |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1137 | SIMPLE_ATTR(BaseCheck); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1139 | case attr::Blocks: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1140 | New = ::new (*Context) BlocksAttr( |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1141 | (BlocksAttr::BlocksAttrTypes)Record[Idx++]); |
| 1142 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1143 | |
Eli Friedman | 8f4c59e | 2009-11-09 18:38:53 +0000 | [diff] [blame] | 1144 | SIMPLE_ATTR(CDecl); |
| 1145 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1146 | case attr::Cleanup: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1147 | New = ::new (*Context) CleanupAttr( |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1148 | cast<FunctionDecl>(GetDecl(Record[Idx++]))); |
| 1149 | break; |
| 1150 | |
| 1151 | SIMPLE_ATTR(Const); |
| 1152 | UNSIGNED_ATTR(Constructor); |
| 1153 | SIMPLE_ATTR(DLLExport); |
| 1154 | SIMPLE_ATTR(DLLImport); |
| 1155 | SIMPLE_ATTR(Deprecated); |
| 1156 | UNSIGNED_ATTR(Destructor); |
| 1157 | SIMPLE_ATTR(FastCall); |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1158 | SIMPLE_ATTR(Final); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1160 | case attr::Format: { |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1161 | std::string Type = ReadString(Record, Idx); |
| 1162 | unsigned FormatIdx = Record[Idx++]; |
| 1163 | unsigned FirstArg = Record[Idx++]; |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 1164 | New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1165 | break; |
| 1166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1167 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1168 | case attr::FormatArg: { |
Fariborz Jahanian | 5b16092 | 2009-05-20 17:41:43 +0000 | [diff] [blame] | 1169 | unsigned FormatIdx = Record[Idx++]; |
| 1170 | New = ::new (*Context) FormatArgAttr(FormatIdx); |
| 1171 | break; |
| 1172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1173 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1174 | case attr::Sentinel: { |
Fariborz Jahanian | 5b53005 | 2009-05-13 18:09:35 +0000 | [diff] [blame] | 1175 | int sentinel = Record[Idx++]; |
| 1176 | int nullPos = Record[Idx++]; |
| 1177 | New = ::new (*Context) SentinelAttr(sentinel, nullPos); |
| 1178 | break; |
| 1179 | } |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1180 | |
| 1181 | SIMPLE_ATTR(GNUInline); |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1182 | SIMPLE_ATTR(Hiding); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1183 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1184 | case attr::IBAction: |
Ted Kremenek | efbddd2 | 2010-02-17 02:37:45 +0000 | [diff] [blame] | 1185 | New = ::new (*Context) IBActionAttr(); |
| 1186 | break; |
| 1187 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1188 | case attr::IBOutlet: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1189 | New = ::new (*Context) IBOutletAttr(); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1190 | break; |
| 1191 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1192 | case attr::IBOutletCollection: { |
Ted Kremenek | 857e918 | 2010-05-19 17:38:06 +0000 | [diff] [blame] | 1193 | ObjCInterfaceDecl *D = |
| 1194 | cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
| 1195 | New = ::new (*Context) IBOutletCollectionAttr(D); |
| 1196 | break; |
| 1197 | } |
| 1198 | |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 1199 | SIMPLE_ATTR(Malloc); |
Mike Stump | 1feade8 | 2009-08-26 22:31:08 +0000 | [diff] [blame] | 1200 | SIMPLE_ATTR(NoDebug); |
| 1201 | SIMPLE_ATTR(NoInline); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1202 | SIMPLE_ATTR(NoReturn); |
| 1203 | SIMPLE_ATTR(NoThrow); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1204 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1205 | case attr::NonNull: { |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1206 | unsigned Size = Record[Idx++]; |
| 1207 | llvm::SmallVector<unsigned, 16> ArgNums; |
| 1208 | ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size); |
| 1209 | Idx += Size; |
Ted Kremenek | 5961611 | 2010-02-11 07:31:47 +0000 | [diff] [blame] | 1210 | New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1211 | break; |
| 1212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1214 | case attr::ReqdWorkGroupSize: { |
Nate Begeman | 6f3d838 | 2009-06-26 06:32:41 +0000 | [diff] [blame] | 1215 | unsigned X = Record[Idx++]; |
| 1216 | unsigned Y = Record[Idx++]; |
| 1217 | unsigned Z = Record[Idx++]; |
| 1218 | New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z); |
| 1219 | break; |
| 1220 | } |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1221 | |
| 1222 | SIMPLE_ATTR(ObjCException); |
| 1223 | SIMPLE_ATTR(ObjCNSObject); |
Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 1224 | SIMPLE_ATTR(CFReturnsNotRetained); |
Ted Kremenek | b71368d | 2009-05-09 02:44:38 +0000 | [diff] [blame] | 1225 | SIMPLE_ATTR(CFReturnsRetained); |
Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 1226 | SIMPLE_ATTR(NSReturnsNotRetained); |
Ted Kremenek | b71368d | 2009-05-09 02:44:38 +0000 | [diff] [blame] | 1227 | SIMPLE_ATTR(NSReturnsRetained); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1228 | SIMPLE_ATTR(Overloadable); |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1229 | SIMPLE_ATTR(Override); |
Anders Carlsson | a860e75 | 2009-08-08 18:23:56 +0000 | [diff] [blame] | 1230 | SIMPLE_ATTR(Packed); |
Daniel Dunbar | 8a2c92c | 2010-05-27 01:12:46 +0000 | [diff] [blame] | 1231 | UNSIGNED_ATTR(MaxFieldAlignment); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1232 | SIMPLE_ATTR(Pure); |
| 1233 | UNSIGNED_ATTR(Regparm); |
| 1234 | STRING_ATTR(Section); |
| 1235 | SIMPLE_ATTR(StdCall); |
Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 1236 | SIMPLE_ATTR(ThisCall); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1237 | SIMPLE_ATTR(TransparentUnion); |
| 1238 | SIMPLE_ATTR(Unavailable); |
| 1239 | SIMPLE_ATTR(Unused); |
| 1240 | SIMPLE_ATTR(Used); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1241 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1242 | case attr::Visibility: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1243 | New = ::new (*Context) VisibilityAttr( |
Eli Friedman | aa8b0d1 | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 1244 | (VisibilityAttr::VisibilityTypes)Record[Idx++], |
| 1245 | (bool)Record[Idx++]); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1246 | break; |
| 1247 | |
| 1248 | SIMPLE_ATTR(WarnUnusedResult); |
| 1249 | SIMPLE_ATTR(Weak); |
Rafael Espindola | 11e8ce7 | 2010-02-23 22:00:30 +0000 | [diff] [blame] | 1250 | SIMPLE_ATTR(WeakRef); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1251 | SIMPLE_ATTR(WeakImport); |
| 1252 | } |
| 1253 | |
| 1254 | assert(New && "Unable to decode attribute?"); |
| 1255 | New->setInherited(IsInherited); |
| 1256 | New->setNext(Attrs); |
| 1257 | Attrs = New; |
| 1258 | } |
| 1259 | #undef UNSIGNED_ATTR |
| 1260 | #undef STRING_ATTR |
| 1261 | #undef SIMPLE_ATTR |
| 1262 | |
| 1263 | // The list of attributes was built backwards. Reverse the list |
| 1264 | // before returning it. |
| 1265 | Attr *PrevAttr = 0, *NextAttr = 0; |
| 1266 | while (Attrs) { |
| 1267 | NextAttr = Attrs->getNext(); |
| 1268 | Attrs->setNext(PrevAttr); |
| 1269 | PrevAttr = Attrs; |
| 1270 | Attrs = NextAttr; |
| 1271 | } |
| 1272 | |
| 1273 | return PrevAttr; |
| 1274 | } |
| 1275 | |
| 1276 | //===----------------------------------------------------------------------===// |
| 1277 | // PCHReader Implementation |
| 1278 | //===----------------------------------------------------------------------===// |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1279 | |
| 1280 | /// \brief Note that we have loaded the declaration with the given |
| 1281 | /// Index. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1282 | /// |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1283 | /// This routine notes that this declaration has already been loaded, |
| 1284 | /// so that future GetDecl calls will return this declaration rather |
| 1285 | /// than trying to load a new declaration. |
| 1286 | inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) { |
| 1287 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 1288 | DeclsLoaded[Index] = D; |
| 1289 | } |
| 1290 | |
| 1291 | |
| 1292 | /// \brief Determine whether the consumer will be interested in seeing |
| 1293 | /// this declaration (via HandleTopLevelDecl). |
| 1294 | /// |
| 1295 | /// This routine should return true for anything that might affect |
| 1296 | /// code generation, e.g., inline function definitions, Objective-C |
| 1297 | /// declarations with metadata, etc. |
| 1298 | static bool isConsumerInterestedIn(Decl *D) { |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 1299 | if (isa<FileScopeAsmDecl>(D)) |
| 1300 | return true; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1301 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) |
Argyrios Kyrtzidis | 3f95477 | 2010-08-05 09:47:59 +0000 | [diff] [blame] | 1302 | return Var->isFileVarDecl() && |
| 1303 | Var->isThisDeclarationADefinition() == VarDecl::Definition; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1304 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) |
| 1305 | return Func->isThisDeclarationADefinition(); |
Argyrios Kyrtzidis | 9d50c06 | 2010-08-09 10:54:20 +0000 | [diff] [blame] | 1306 | return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Sebastian Redl | cb526aa | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 1309 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame^] | 1310 | PCHReader::RecordLocation |
| 1311 | PCHReader::DeclCursorForIndex(unsigned Index, pch::DeclID ID) { |
| 1312 | // See if there's an override. |
| 1313 | DeclReplacementMap::iterator It = ReplacedDecls.find(ID); |
| 1314 | if (It != ReplacedDecls.end()) |
| 1315 | return RecordLocation(&It->second.first->DeclsCursor, It->second.second); |
| 1316 | |
Sebastian Redl | cb526aa | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 1317 | PerFileData *F = 0; |
| 1318 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1319 | F = Chain[N - I - 1]; |
| 1320 | if (Index < F->LocalNumDecls) |
| 1321 | break; |
| 1322 | Index -= F->LocalNumDecls; |
| 1323 | } |
| 1324 | assert(F && F->LocalNumDecls > Index && "Broken chain"); |
Sebastian Redl | 971dd44 | 2010-07-20 22:55:31 +0000 | [diff] [blame] | 1325 | return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]); |
Sebastian Redl | cb526aa | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1328 | /// \brief Read the declaration at the given offset from the PCH file. |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1329 | Decl *PCHReader::ReadDeclRecord(unsigned Index, pch::DeclID ID) { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame^] | 1330 | RecordLocation Loc = DeclCursorForIndex(Index, ID); |
Sebastian Redl | 971dd44 | 2010-07-20 22:55:31 +0000 | [diff] [blame] | 1331 | llvm::BitstreamCursor &DeclsCursor = *Loc.first; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1332 | // Keep track of where we are in the stream, then jump back there |
| 1333 | // after reading this declaration. |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1334 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1335 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 1336 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 1337 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 1338 | // Note that we are loading a declaration record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 1339 | Deserializing ADecl(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | |
Sebastian Redl | cb526aa | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 1341 | DeclsCursor.JumpToBit(Loc.second); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1342 | RecordData Record; |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1343 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1344 | unsigned Idx = 0; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1345 | PCHDeclReader Reader(*this, DeclsCursor, ID, Record, Idx); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1346 | |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1347 | Decl *D = 0; |
| 1348 | switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1349 | case pch::DECL_ATTR: |
| 1350 | case pch::DECL_CONTEXT_LEXICAL: |
| 1351 | case pch::DECL_CONTEXT_VISIBLE: |
| 1352 | assert(false && "Record cannot be de-serialized with ReadDeclRecord"); |
| 1353 | break; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1354 | case pch::DECL_TRANSLATION_UNIT: |
| 1355 | assert(Index == 0 && "Translation unit must be at index 0"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1356 | D = Context->getTranslationUnitDecl(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1357 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1358 | case pch::DECL_TYPEDEF: |
John McCall | ba6a9bd | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 1359 | D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1360 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1361 | case pch::DECL_ENUM: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1362 | D = EnumDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1363 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1364 | case pch::DECL_RECORD: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1365 | D = RecordDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1366 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1367 | case pch::DECL_ENUM_CONSTANT: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1368 | D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1369 | 0, llvm::APSInt()); |
| 1370 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1371 | case pch::DECL_FUNCTION: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(), |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1373 | QualType(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1374 | break; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1375 | case pch::DECL_LINKAGE_SPEC: |
| 1376 | D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(), |
| 1377 | (LinkageSpecDecl::LanguageIDs)0, |
| 1378 | false); |
| 1379 | break; |
| 1380 | case pch::DECL_NAMESPACE: |
| 1381 | D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0); |
| 1382 | break; |
| 1383 | case pch::DECL_NAMESPACE_ALIAS: |
| 1384 | D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(), |
| 1385 | SourceLocation(), 0, SourceRange(), 0, |
| 1386 | SourceLocation(), 0); |
| 1387 | break; |
| 1388 | case pch::DECL_USING: |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1389 | D = UsingDecl::Create(*Context, 0, SourceRange(), SourceLocation(), |
| 1390 | 0, DeclarationNameInfo(), false); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1391 | break; |
| 1392 | case pch::DECL_USING_SHADOW: |
| 1393 | D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
| 1394 | break; |
| 1395 | case pch::DECL_USING_DIRECTIVE: |
| 1396 | D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(), |
| 1397 | SourceLocation(), SourceRange(), 0, |
| 1398 | SourceLocation(), 0, 0); |
| 1399 | break; |
| 1400 | case pch::DECL_UNRESOLVED_USING_VALUE: |
| 1401 | D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(), |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1402 | SourceRange(), 0, |
| 1403 | DeclarationNameInfo()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1404 | break; |
| 1405 | case pch::DECL_UNRESOLVED_USING_TYPENAME: |
| 1406 | D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(), |
| 1407 | SourceLocation(), SourceRange(), |
| 1408 | 0, SourceLocation(), |
| 1409 | DeclarationName()); |
| 1410 | break; |
| 1411 | case pch::DECL_CXX_RECORD: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1412 | D = CXXRecordDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1413 | break; |
| 1414 | case pch::DECL_CXX_METHOD: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1415 | D = CXXMethodDecl::Create(*Context, 0, DeclarationNameInfo(), |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1416 | QualType(), 0); |
| 1417 | break; |
| 1418 | case pch::DECL_CXX_CONSTRUCTOR: |
| 1419 | D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell()); |
| 1420 | break; |
| 1421 | case pch::DECL_CXX_DESTRUCTOR: |
| 1422 | D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell()); |
| 1423 | break; |
| 1424 | case pch::DECL_CXX_CONVERSION: |
| 1425 | D = CXXConversionDecl::Create(*Context, Decl::EmptyShell()); |
| 1426 | break; |
Abramo Bagnara | 6206d53 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1427 | case pch::DECL_ACCESS_SPEC: |
| 1428 | D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(), |
| 1429 | SourceLocation()); |
| 1430 | break; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1431 | case pch::DECL_FRIEND: |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 1432 | D = FriendDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1433 | break; |
| 1434 | case pch::DECL_FRIEND_TEMPLATE: |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1435 | D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1436 | break; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1437 | case pch::DECL_CLASS_TEMPLATE: |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 1438 | D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(), |
| 1439 | DeclarationName(), 0, 0, 0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1440 | break; |
| 1441 | case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1442 | D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1443 | break; |
| 1444 | case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1445 | D = ClassTemplatePartialSpecializationDecl::Create(*Context, |
| 1446 | Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1447 | break; |
| 1448 | case pch::DECL_FUNCTION_TEMPLATE: |
Argyrios Kyrtzidis | f511ba6 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 1449 | D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(), |
| 1450 | DeclarationName(), 0, 0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1451 | break; |
| 1452 | case pch::DECL_TEMPLATE_TYPE_PARM: |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1453 | D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1454 | break; |
| 1455 | case pch::DECL_NON_TYPE_TEMPLATE_PARM: |
Argyrios Kyrtzidis | b24e199 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1456 | D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0, |
| 1457 | QualType(),0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1458 | break; |
| 1459 | case pch::DECL_TEMPLATE_TEMPLATE_PARM: |
Argyrios Kyrtzidis | bfcc92c | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 1460 | D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1461 | break; |
| 1462 | case pch::DECL_STATIC_ASSERT: |
Argyrios Kyrtzidis | 0d39689 | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 1463 | D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1464 | break; |
| 1465 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1466 | case pch::DECL_OBJC_METHOD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1467 | D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(), |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 1468 | Selector(), QualType(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1469 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1470 | case pch::DECL_OBJC_INTERFACE: |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 1471 | D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1472 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1473 | case pch::DECL_OBJC_IVAR: |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1474 | D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1475 | ObjCIvarDecl::None); |
| 1476 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1477 | case pch::DECL_OBJC_PROTOCOL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1478 | D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1479 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1480 | case pch::DECL_OBJC_AT_DEFS_FIELD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1481 | D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1482 | QualType(), 0); |
| 1483 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1484 | case pch::DECL_OBJC_CLASS: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1485 | D = ObjCClassDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1486 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1487 | case pch::DECL_OBJC_FORWARD_PROTOCOL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1488 | D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1489 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1490 | case pch::DECL_OBJC_CATEGORY: |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 1491 | D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), |
| 1492 | SourceLocation(), SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1493 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1494 | case pch::DECL_OBJC_CATEGORY_IMPL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1495 | D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1496 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1497 | case pch::DECL_OBJC_IMPLEMENTATION: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1498 | D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1499 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1500 | case pch::DECL_OBJC_COMPATIBLE_ALIAS: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1501 | D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1502 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1503 | case pch::DECL_OBJC_PROPERTY: |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 1504 | D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), |
John McCall | 83a230c | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 1505 | 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1506 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1507 | case pch::DECL_OBJC_PROPERTY_IMPL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1508 | D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1509 | SourceLocation(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1510 | ObjCPropertyImplDecl::Dynamic, 0); |
| 1511 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1512 | case pch::DECL_FIELD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1513 | D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0, |
Argyrios Kyrtzidis | a5d8200 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 1514 | false); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1515 | break; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1516 | case pch::DECL_VAR: |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1517 | D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1518 | VarDecl::None, VarDecl::None); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1519 | break; |
| 1520 | |
| 1521 | case pch::DECL_IMPLICIT_PARAM: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1522 | D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1523 | break; |
| 1524 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1525 | case pch::DECL_PARM_VAR: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1526 | D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1527 | VarDecl::None, VarDecl::None, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1528 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1529 | case pch::DECL_FILE_SCOPE_ASM: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1530 | D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1531 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1532 | case pch::DECL_BLOCK: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1533 | D = BlockDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1534 | break; |
| 1535 | } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1536 | |
| 1537 | assert(D && "Unknown declaration reading PCH file"); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1538 | LoadedDecl(Index, D); |
| 1539 | Reader.Visit(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1540 | |
| 1541 | // If this declaration is also a declaration context, get the |
| 1542 | // offsets for its tables of lexical and visible declarations. |
| 1543 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 1544 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
| 1545 | if (Offsets.first || Offsets.second) { |
| 1546 | DC->setHasExternalLexicalStorage(Offsets.first != 0); |
| 1547 | DC->setHasExternalVisibleStorage(Offsets.second != 0); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1548 | DeclContextInfo Info; |
| 1549 | if (ReadDeclContextStorage(DeclsCursor, Offsets, Info)) |
| 1550 | return 0; |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1551 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 1552 | // Reading the TU will happen after reading its update blocks, so we need |
| 1553 | // to make sure we insert in front. For all other contexts, the vector |
| 1554 | // is empty here anyway, so there's no loss in efficiency. |
| 1555 | Infos.insert(Infos.begin(), Info); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | assert(Idx == Record.size()); |
| 1559 | |
| 1560 | // If we have deserialized a declaration that has a definition the |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 1561 | // AST consumer might need to know about, queue it. |
| 1562 | // We don't pass it to the consumer immediately because we may be in recursive |
| 1563 | // loading, and some declarations may still be initializing. |
| 1564 | if (isConsumerInterestedIn(D)) |
| 1565 | InterestingDecls.push_back(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1566 | |
| 1567 | return D; |
| 1568 | } |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1569 | |
| 1570 | bool PCHReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 1571 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 1572 | DeclContextInfo &Info) { |
| 1573 | SavedStreamPosition SavedPosition(Cursor); |
| 1574 | // First the lexical decls. |
| 1575 | if (Offsets.first != 0) { |
| 1576 | Cursor.JumpToBit(Offsets.first); |
| 1577 | |
| 1578 | RecordData Record; |
| 1579 | const char *Blob; |
| 1580 | unsigned BlobLen; |
| 1581 | unsigned Code = Cursor.ReadCode(); |
| 1582 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 1583 | if (RecCode != pch::DECL_CONTEXT_LEXICAL) { |
| 1584 | Error("Expected lexical block"); |
| 1585 | return true; |
| 1586 | } |
| 1587 | |
| 1588 | Info.LexicalDecls = reinterpret_cast<const pch::DeclID*>(Blob); |
| 1589 | Info.NumLexicalDecls = BlobLen / sizeof(pch::DeclID); |
| 1590 | } else { |
| 1591 | Info.LexicalDecls = 0; |
| 1592 | Info.NumLexicalDecls = 0; |
| 1593 | } |
| 1594 | |
| 1595 | // Now the visible decls. |
| 1596 | Info.Stream = &Cursor; |
| 1597 | Info.OffsetToVisibleDecls = Offsets.second; |
| 1598 | |
| 1599 | return false; |
| 1600 | } |