Chris Lattner | 487412d | 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 | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
| 21 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 22 | #include "clang/AST/Expr.h" |
| 23 | using namespace clang; |
| 24 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 25 | |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | // Declaration deserialization |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 30 | namespace clang { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 31 | class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> { |
| 32 | PCHReader &Reader; |
| 33 | const PCHReader::RecordData &Record; |
| 34 | unsigned &Idx; |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 35 | pch::TypeID TypeIDForTypeDecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 36 | |
| 37 | public: |
| 38 | PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record, |
| 39 | unsigned &Idx) |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 40 | : Reader(Reader), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 41 | |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 42 | void Visit(Decl *D); |
| 43 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 44 | void VisitDecl(Decl *D); |
| 45 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 46 | void VisitNamedDecl(NamedDecl *ND); |
Douglas Gregor | e31bbd9 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 47 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 48 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 49 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 50 | void VisitTypeDecl(TypeDecl *TD); |
| 51 | void VisitTypedefDecl(TypedefDecl *TD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 52 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 53 | void VisitTagDecl(TagDecl *TD); |
| 54 | void VisitEnumDecl(EnumDecl *ED); |
| 55 | void VisitRecordDecl(RecordDecl *RD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 56 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
| 57 | void VisitClassTemplateSpecializationDecl( |
| 58 | ClassTemplateSpecializationDecl *D); |
| 59 | void VisitClassTemplatePartialSpecializationDecl( |
| 60 | ClassTemplatePartialSpecializationDecl *D); |
| 61 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 62 | void VisitValueDecl(ValueDecl *VD); |
| 63 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 64 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 65 | void VisitDeclaratorDecl(DeclaratorDecl *DD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 66 | void VisitFunctionDecl(FunctionDecl *FD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 67 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 68 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 69 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 70 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 71 | void VisitFieldDecl(FieldDecl *FD); |
| 72 | void VisitVarDecl(VarDecl *VD); |
| 73 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); |
| 74 | void VisitParmVarDecl(ParmVarDecl *PD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 75 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 76 | void VisitTemplateDecl(TemplateDecl *D); |
| 77 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 78 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 79 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 80 | void VisitUsingDecl(UsingDecl *D); |
| 81 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 82 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 83 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 84 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 85 | void VisitFriendDecl(FriendDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 86 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 87 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 88 | void VisitBlockDecl(BlockDecl *BD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 89 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 90 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 91 | |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 92 | // FIXME: Reorder according to DeclNodes.td? |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 93 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 94 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 95 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 96 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 97 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 98 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| 99 | void VisitObjCClassDecl(ObjCClassDecl *D); |
| 100 | void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D); |
| 101 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 102 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 103 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 104 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 105 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 106 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 107 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 108 | }; |
| 109 | } |
| 110 | |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 111 | void PCHDeclReader::Visit(Decl *D) { |
| 112 | DeclVisitor<PCHDeclReader, void>::Visit(D); |
| 113 | |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 114 | if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) { |
| 115 | // if we have a fully initialized TypeDecl, we can safely read its type now. |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 116 | TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr()); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 117 | } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 118 | // FunctionDecl's body was written last after all other Stmts/Exprs. |
| 119 | if (Record[Idx++]) |
| 120 | FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo()); |
| 121 | } |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 124 | void PCHDeclReader::VisitDecl(Decl *D) { |
| 125 | D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 126 | D->setLexicalDeclContext( |
| 127 | cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 128 | D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 129 | D->setInvalidDecl(Record[Idx++]); |
| 130 | if (Record[Idx++]) |
Argyrios Kyrtzidis | 9116717 | 2010-06-11 23:09:25 +0000 | [diff] [blame] | 131 | D->initAttrs(Reader.ReadAttributes()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 132 | D->setImplicit(Record[Idx++]); |
Douglas Gregor | c9c02ed | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 133 | D->setUsed(Record[Idx++]); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 134 | D->setAccess((AccessSpecifier)Record[Idx++]); |
Douglas Gregor | 16bef85 | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 135 | D->setPCHLevel(Record[Idx++] + 1); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
| 139 | VisitDecl(TU); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 140 | TU->setAnonymousNamespace( |
| 141 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) { |
| 145 | VisitDecl(ND); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 146 | ND->setDeclName(Reader.ReadDeclarationName(Record, Idx)); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) { |
| 150 | VisitNamedDecl(TD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 151 | // Delay type reading until after we have fully initialized the decl. |
| 152 | TypeIDForTypeDecl = Record[Idx++]; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 156 | VisitTypeDecl(TD); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 157 | TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | void PCHDeclReader::VisitTagDecl(TagDecl *TD) { |
| 161 | VisitTypeDecl(TD); |
Douglas Gregor | b6b8f9e | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 162 | TD->setPreviousDeclaration( |
| 163 | cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 164 | TD->setTagKind((TagDecl::TagKind)Record[Idx++]); |
| 165 | TD->setDefinition(Record[Idx++]); |
Douglas Gregor | 5089c76 | 2010-02-12 17:40:34 +0000 | [diff] [blame] | 166 | TD->setEmbeddedInDeclarator(Record[Idx++]); |
Argyrios Kyrtzidis | 664b690 | 2009-07-14 03:18:02 +0000 | [diff] [blame] | 167 | TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 82fe3e3 | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 168 | TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 169 | // FIXME: maybe read optional qualifier and its range. |
| 170 | TD->setTypedefForAnonDecl( |
| 171 | cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) { |
| 175 | VisitTagDecl(ED); |
| 176 | ED->setIntegerType(Reader.GetType(Record[Idx++])); |
John McCall | 5677499 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 177 | ED->setPromotionType(Reader.GetType(Record[Idx++])); |
John McCall | 9aa35be | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 178 | ED->setNumPositiveBits(Record[Idx++]); |
| 179 | ED->setNumNegativeBits(Record[Idx++]); |
Douglas Gregor | 7a74938 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 180 | // FIXME: C++ InstantiatedFrom |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) { |
| 184 | VisitTagDecl(RD); |
| 185 | RD->setHasFlexibleArrayMember(Record[Idx++]); |
| 186 | RD->setAnonymousStructOrUnion(Record[Idx++]); |
Fariborz Jahanian | 8e0d042 | 2009-07-08 16:37:44 +0000 | [diff] [blame] | 187 | RD->setHasObjectMember(Record[Idx++]); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void PCHDeclReader::VisitValueDecl(ValueDecl *VD) { |
| 191 | VisitNamedDecl(VD); |
| 192 | VD->setType(Reader.GetType(Record[Idx++])); |
| 193 | } |
| 194 | |
| 195 | void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
| 196 | VisitValueDecl(ECD); |
| 197 | if (Record[Idx++]) |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 198 | ECD->setInitExpr(Reader.ReadExpr()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 199 | ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); |
| 200 | } |
| 201 | |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 202 | void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
| 203 | VisitValueDecl(DD); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx); |
| 205 | if (TInfo) |
| 206 | DD->setTypeSourceInfo(TInfo); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 207 | // FIXME: read optional qualifier and its range. |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 210 | void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 211 | VisitDeclaratorDecl(FD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 212 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 213 | switch ((FunctionDecl::TemplatedKind)Record[Idx++]) { |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 214 | default: assert(false && "Unhandled TemplatedKind!"); |
| 215 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 216 | case FunctionDecl::TK_NonTemplate: |
| 217 | break; |
| 218 | case FunctionDecl::TK_FunctionTemplate: |
| 219 | FD->setDescribedFunctionTemplate( |
| 220 | cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))); |
| 221 | break; |
| 222 | case FunctionDecl::TK_MemberSpecialization: { |
| 223 | FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++])); |
| 224 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 225 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 226 | FD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 227 | FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 228 | break; |
| 229 | } |
| 230 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 231 | FunctionTemplateDecl *Template |
| 232 | = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
| 233 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 234 | |
| 235 | // Template arguments. |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 236 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 237 | Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 238 | |
| 239 | // Template args as written. |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 240 | llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 241 | SourceLocation LAngleLoc, RAngleLoc; |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 242 | if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0 |
| 243 | unsigned NumTemplateArgLocs = Record[Idx++]; |
| 244 | TemplArgLocs.reserve(NumTemplateArgLocs); |
| 245 | for (unsigned i=0; i != NumTemplateArgLocs; ++i) |
| 246 | TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx)); |
| 247 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 248 | LAngleLoc = Reader.ReadSourceLocation(Record, Idx); |
| 249 | RAngleLoc = Reader.ReadSourceLocation(Record, Idx); |
| 250 | } |
| 251 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 252 | FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(), |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 253 | TemplArgs.data(), TSK, |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 254 | TemplArgLocs.size(), |
| 255 | TemplArgLocs.data(), |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 256 | LAngleLoc, RAngleLoc); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 257 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 258 | } |
| 259 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 260 | // Templates. |
| 261 | UnresolvedSet<8> TemplDecls; |
| 262 | unsigned NumTemplates = Record[Idx++]; |
| 263 | while (NumTemplates--) |
| 264 | TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 265 | |
| 266 | // Templates args. |
| 267 | TemplateArgumentListInfo TemplArgs; |
| 268 | unsigned NumArgs = Record[Idx++]; |
| 269 | while (NumArgs--) |
| 270 | TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx)); |
| 271 | |
| 272 | FD->setDependentTemplateSpecialization(*Reader.getContext(), |
| 273 | TemplDecls, TemplArgs); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 274 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 275 | } |
| 276 | } |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 277 | |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 278 | // FunctionDecl's body is handled last at PCHReaderDecl::Visit, |
| 279 | // after everything else is read. |
| 280 | |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 281 | FD->setPreviousDeclaration( |
| 282 | cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]))); |
| 283 | FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]); |
| 284 | FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]); |
| 285 | FD->setInlineSpecified(Record[Idx++]); |
| 286 | FD->setVirtualAsWritten(Record[Idx++]); |
| 287 | FD->setPure(Record[Idx++]); |
| 288 | FD->setHasInheritedPrototype(Record[Idx++]); |
| 289 | FD->setHasWrittenPrototype(Record[Idx++]); |
| 290 | FD->setDeleted(Record[Idx++]); |
| 291 | FD->setTrivial(Record[Idx++]); |
| 292 | FD->setCopyAssignment(Record[Idx++]); |
| 293 | FD->setHasImplicitReturnZero(Record[Idx++]); |
| 294 | FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 295 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 296 | // Read in the parameters. |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 297 | unsigned NumParams = Record[Idx++]; |
| 298 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 299 | Params.reserve(NumParams); |
| 300 | for (unsigned I = 0; I != NumParams; ++I) |
| 301 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 302 | FD->setParams(Params.data(), NumParams); |
John McCall | b9467b6 | 2010-04-24 01:30:58 +0000 | [diff] [blame] | 303 | |
| 304 | // FIXME: order this properly w.r.t. friendness |
| 305 | // FIXME: this same thing needs to happen for function templates |
| 306 | if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord()) |
| 307 | FD->setNonMemberOperator(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
| 311 | VisitNamedDecl(MD); |
| 312 | if (Record[Idx++]) { |
| 313 | // In practice, this won't be executed (since method definitions |
| 314 | // don't occur in header files). |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 315 | MD->setBody(Reader.ReadStmt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 316 | MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 317 | MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 318 | } |
| 319 | MD->setInstanceMethod(Record[Idx++]); |
| 320 | MD->setVariadic(Record[Idx++]); |
| 321 | MD->setSynthesized(Record[Idx++]); |
| 322 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); |
| 323 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
Fariborz Jahanian | d9235db | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 324 | MD->setNumSelectorArgs(unsigned(Record[Idx++])); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 325 | MD->setResultType(Reader.GetType(Record[Idx++])); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 326 | MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 327 | MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 328 | unsigned NumParams = Record[Idx++]; |
| 329 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 330 | Params.reserve(NumParams); |
| 331 | for (unsigned I = 0; I != NumParams; ++I) |
| 332 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Fariborz Jahanian | cdabb31 | 2010-04-09 15:40:42 +0000 | [diff] [blame] | 333 | MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams, |
| 334 | NumParams); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
| 338 | VisitNamedDecl(CD); |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 339 | SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 340 | SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 341 | CD->setAtEndRange(SourceRange(A, B)); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
| 345 | VisitObjCContainerDecl(ID); |
| 346 | ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
| 347 | ID->setSuperClass(cast_or_null<ObjCInterfaceDecl> |
| 348 | (Reader.GetDecl(Record[Idx++]))); |
| 349 | unsigned NumProtocols = Record[Idx++]; |
| 350 | llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 351 | Protocols.reserve(NumProtocols); |
| 352 | for (unsigned I = 0; I != NumProtocols; ++I) |
| 353 | Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 354 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 355 | ProtoLocs.reserve(NumProtocols); |
| 356 | for (unsigned I = 0; I != NumProtocols; ++I) |
| 357 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 358 | ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(), |
| 359 | *Reader.getContext()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 360 | unsigned NumIvars = Record[Idx++]; |
| 361 | llvm::SmallVector<ObjCIvarDecl *, 16> IVars; |
| 362 | IVars.reserve(NumIvars); |
| 363 | for (unsigned I = 0; I != NumIvars; ++I) |
| 364 | IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 365 | ID->setCategoryList( |
| 366 | cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
| 367 | ID->setForwardDecl(Record[Idx++]); |
| 368 | ID->setImplicitInterfaceDecl(Record[Idx++]); |
| 369 | ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 370 | ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Argyrios Kyrtzidis | ea72f42 | 2009-07-18 00:33:23 +0000 | [diff] [blame] | 371 | ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
| 375 | VisitFieldDecl(IVD); |
| 376 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); |
| 377 | } |
| 378 | |
| 379 | void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 380 | VisitObjCContainerDecl(PD); |
| 381 | PD->setForwardDecl(Record[Idx++]); |
| 382 | PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 383 | unsigned NumProtoRefs = Record[Idx++]; |
| 384 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 385 | ProtoRefs.reserve(NumProtoRefs); |
| 386 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 387 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 388 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 389 | ProtoLocs.reserve(NumProtoRefs); |
| 390 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 391 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 392 | PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 393 | *Reader.getContext()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
| 397 | VisitFieldDecl(FD); |
| 398 | } |
| 399 | |
| 400 | void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) { |
| 401 | VisitDecl(CD); |
| 402 | unsigned NumClassRefs = Record[Idx++]; |
| 403 | llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs; |
| 404 | ClassRefs.reserve(NumClassRefs); |
| 405 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 406 | ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Ted Kremenek | 9b124e1 | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 407 | llvm::SmallVector<SourceLocation, 16> SLocs; |
| 408 | SLocs.reserve(NumClassRefs); |
| 409 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 410 | SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 411 | CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(), |
| 412 | NumClassRefs); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) { |
| 416 | VisitDecl(FPD); |
| 417 | unsigned NumProtoRefs = Record[Idx++]; |
| 418 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 419 | ProtoRefs.reserve(NumProtoRefs); |
| 420 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 421 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 422 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 423 | ProtoLocs.reserve(NumProtoRefs); |
| 424 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 425 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 426 | FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 427 | *Reader.getContext()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
| 431 | VisitObjCContainerDecl(CD); |
| 432 | CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 433 | unsigned NumProtoRefs = Record[Idx++]; |
| 434 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 435 | ProtoRefs.reserve(NumProtoRefs); |
| 436 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 437 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 438 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 439 | ProtoLocs.reserve(NumProtoRefs); |
| 440 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 441 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 442 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 443 | *Reader.getContext()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 444 | CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 071676f | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 445 | CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 446 | CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
| 450 | VisitNamedDecl(CAD); |
| 451 | CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 452 | } |
| 453 | |
| 454 | void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 455 | VisitNamedDecl(D); |
Fariborz Jahanian | da8ec2b | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 456 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
John McCall | 339bb66 | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 457 | D->setType(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 458 | // FIXME: stable encoding |
| 459 | D->setPropertyAttributes( |
| 460 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 461 | D->setPropertyAttributesAsWritten( |
| 462 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 463 | // FIXME: stable encoding |
| 464 | D->setPropertyImplementation( |
| 465 | (ObjCPropertyDecl::PropertyControl)Record[Idx++]); |
| 466 | D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 467 | D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 468 | D->setGetterMethodDecl( |
| 469 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 470 | D->setSetterMethodDecl( |
| 471 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 472 | D->setPropertyIvarDecl( |
| 473 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 474 | } |
| 475 | |
| 476 | void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | 067c407 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 477 | VisitObjCContainerDecl(D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 478 | D->setClassInterface( |
| 479 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 483 | VisitObjCImplDecl(D); |
| 484 | D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx)); |
| 485 | } |
| 486 | |
| 487 | void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 488 | VisitObjCImplDecl(D); |
| 489 | D->setSuperClass( |
| 490 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Fariborz Jahanian | c83726e | 2010-04-28 16:11:27 +0000 | [diff] [blame] | 491 | // FIXME. Add reading of IvarInitializers and NumIvarInitializers. |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | |
| 495 | void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 496 | VisitDecl(D); |
| 497 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 498 | D->setPropertyDecl( |
| 499 | cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 500 | D->setPropertyIvarDecl( |
| 501 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Fariborz Jahanian | 25491a2 | 2010-05-05 21:52:17 +0000 | [diff] [blame] | 502 | // FIXME. read GetterCXXConstructor and SetterCXXAssignment |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 506 | VisitDeclaratorDecl(FD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 507 | FD->setMutable(Record[Idx++]); |
| 508 | if (Record[Idx++]) |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 509 | FD->setBitWidth(Reader.ReadExpr()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void PCHDeclReader::VisitVarDecl(VarDecl *VD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 513 | VisitDeclaratorDecl(VD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 514 | VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]); |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 515 | VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 516 | VD->setThreadSpecified(Record[Idx++]); |
| 517 | VD->setCXXDirectInitializer(Record[Idx++]); |
| 518 | VD->setDeclaredInCondition(Record[Idx++]); |
Douglas Gregor | 3f324d56 | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 519 | VD->setExceptionVariable(Record[Idx++]); |
Douglas Gregor | 6fd1b18 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 520 | VD->setNRVOVariable(Record[Idx++]); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 521 | VD->setPreviousDeclaration( |
| 522 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 523 | if (Record[Idx++]) |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 524 | VD->setInit(Reader.ReadExpr()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
| 528 | VisitVarDecl(PD); |
| 529 | } |
| 530 | |
| 531 | void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
| 532 | VisitVarDecl(PD); |
| 533 | PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 534 | PD->setHasInheritedDefaultArg(Record[Idx++]); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 537 | void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
| 538 | VisitDecl(AD); |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 539 | AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr())); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) { |
| 543 | VisitDecl(BD); |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 544 | BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt())); |
John McCall | a3ccba0 | 2010-06-04 11:21:44 +0000 | [diff] [blame] | 545 | BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 546 | unsigned NumParams = Record[Idx++]; |
| 547 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 548 | Params.reserve(NumParams); |
| 549 | for (unsigned I = 0; I != NumParams; ++I) |
| 550 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 551 | BD->setParams(Params.data(), NumParams); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 554 | void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 555 | VisitDecl(D); |
| 556 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]); |
| 557 | D->setHasBraces(Record[Idx++]); |
| 558 | } |
| 559 | |
| 560 | void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
| 561 | VisitNamedDecl(D); |
| 562 | D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 563 | D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 564 | D->setNextNamespace( |
| 565 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 566 | |
| 567 | // Only read one reference--the original or anonymous namespace. |
| 568 | bool IsOriginal = Record[Idx++]; |
| 569 | if (IsOriginal) |
| 570 | D->setAnonymousNamespace( |
| 571 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 572 | else |
| 573 | D->setOriginalNamespace( |
| 574 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 575 | } |
| 576 | |
| 577 | void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 578 | VisitNamedDecl(D); |
| 579 | |
| 580 | D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 581 | D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 582 | D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 583 | D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 584 | D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 585 | } |
| 586 | |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 587 | void PCHDeclReader::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 588 | VisitNamedDecl(D); |
| 589 | D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 590 | D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 591 | D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 592 | |
| 593 | // FIXME: It would probably be more efficient to read these into a vector |
| 594 | // and then re-cosntruct the shadow decl set over that vector since it |
| 595 | // would avoid existence checks. |
| 596 | unsigned NumShadows = Record[Idx++]; |
| 597 | for(unsigned I = 0; I != NumShadows; ++I) { |
| 598 | D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]))); |
| 599 | } |
| 600 | D->setTypeName(Record[Idx++]); |
| 601 | } |
| 602 | |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 603 | void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 604 | VisitNamedDecl(D); |
| 605 | D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 606 | D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++]))); |
| 607 | } |
| 608 | |
| 609 | void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 610 | VisitNamedDecl(D); |
| 611 | D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 612 | D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 613 | D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 614 | D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 615 | D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 616 | D->setCommonAncestor(cast_or_null<DeclContext>( |
| 617 | Reader.GetDecl(Record[Idx++]))); |
| 618 | } |
| 619 | |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 620 | void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 621 | VisitValueDecl(D); |
| 622 | D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 623 | D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 624 | D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 625 | } |
| 626 | |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 627 | void PCHDeclReader::VisitUnresolvedUsingTypenameDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 628 | UnresolvedUsingTypenameDecl *D) { |
| 629 | VisitTypeDecl(D); |
| 630 | D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 631 | D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 632 | D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 633 | D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 634 | } |
| 635 | |
| 636 | void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 637 | VisitRecordDecl(D); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 638 | |
| 639 | ASTContext &C = *Reader.getContext(); |
| 640 | |
| 641 | if (D->isFirstDeclaration()) { |
| 642 | if (Record[Idx++]) { // DefinitionData != 0 |
| 643 | D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(0); |
| 644 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
| 645 | |
| 646 | Data.UserDeclaredConstructor = Record[Idx++]; |
| 647 | Data.UserDeclaredCopyConstructor = Record[Idx++]; |
| 648 | Data.UserDeclaredCopyAssignment = Record[Idx++]; |
| 649 | Data.UserDeclaredDestructor = Record[Idx++]; |
| 650 | Data.Aggregate = Record[Idx++]; |
| 651 | Data.PlainOldData = Record[Idx++]; |
| 652 | Data.Empty = Record[Idx++]; |
| 653 | Data.Polymorphic = Record[Idx++]; |
| 654 | Data.Abstract = Record[Idx++]; |
| 655 | Data.HasTrivialConstructor = Record[Idx++]; |
| 656 | Data.HasTrivialCopyConstructor = Record[Idx++]; |
| 657 | Data.HasTrivialCopyAssignment = Record[Idx++]; |
| 658 | Data.HasTrivialDestructor = Record[Idx++]; |
| 659 | Data.ComputedVisibleConversions = Record[Idx++]; |
Douglas Gregor | 9672f92 | 2010-07-03 00:47:00 +0000 | [diff] [blame^] | 660 | Data.DeclaredDefaultConstructor = Record[Idx++]; |
Douglas Gregor | a6d6950 | 2010-07-02 23:41:54 +0000 | [diff] [blame] | 661 | Data.DeclaredCopyConstructor = Record[Idx++]; |
Douglas Gregor | 330b9cf | 2010-07-02 21:50:04 +0000 | [diff] [blame] | 662 | Data.DeclaredCopyAssignment = Record[Idx++]; |
Douglas Gregor | 7454c56 | 2010-07-02 20:37:36 +0000 | [diff] [blame] | 663 | Data.DeclaredDestructor = Record[Idx++]; |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 664 | |
| 665 | // setBases() is unsuitable since it may try to iterate the bases of an |
| 666 | // unitialized base. |
| 667 | Data.NumBases = Record[Idx++]; |
| 668 | Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases]; |
| 669 | for (unsigned i = 0; i != Data.NumBases; ++i) |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 670 | Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Record, Idx); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 671 | |
| 672 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 673 | Data.NumVBases = Record[Idx++]; |
| 674 | Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases]; |
| 675 | for (unsigned i = 0; i != Data.NumVBases; ++i) |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 676 | Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Record, Idx); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 677 | |
| 678 | Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx); |
| 679 | Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx); |
| 680 | Data.Definition = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])); |
| 681 | Data.FirstFriend |
| 682 | = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++])); |
| 683 | } |
| 684 | } else { |
| 685 | D->DefinitionData = D->getPreviousDeclaration()->DefinitionData; |
| 686 | } |
| 687 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 688 | enum CXXRecKind { |
| 689 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 690 | }; |
| 691 | switch ((CXXRecKind)Record[Idx++]) { |
| 692 | default: |
| 693 | assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?"); |
| 694 | case CXXRecNotTemplate: |
| 695 | break; |
| 696 | case CXXRecTemplate: |
| 697 | D->setDescribedClassTemplate( |
| 698 | cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))); |
| 699 | break; |
| 700 | case CXXRecMemberSpecialization: { |
| 701 | CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])); |
| 702 | TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; |
| 703 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 704 | D->setInstantiationOfMemberClass(RD, TSK); |
| 705 | D->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 706 | break; |
| 707 | } |
| 708 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 712 | VisitFunctionDecl(D); |
| 713 | } |
| 714 | |
| 715 | void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 716 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 717 | |
| 718 | D->IsExplicitSpecified = Record[Idx++]; |
| 719 | D->ImplicitlyDefined = Record[Idx++]; |
| 720 | |
| 721 | unsigned NumInitializers = Record[Idx++]; |
| 722 | D->NumBaseOrMemberInitializers = NumInitializers; |
| 723 | if (NumInitializers) { |
| 724 | ASTContext &C = *Reader.getContext(); |
| 725 | |
| 726 | D->BaseOrMemberInitializers |
| 727 | = new (C) CXXBaseOrMemberInitializer*[NumInitializers]; |
| 728 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 729 | TypeSourceInfo *BaseClassInfo; |
| 730 | bool IsBaseVirtual; |
| 731 | FieldDecl *Member; |
| 732 | |
| 733 | bool IsBaseInitializer = Record[Idx++]; |
| 734 | if (IsBaseInitializer) { |
| 735 | BaseClassInfo = Reader.GetTypeSourceInfo(Record, Idx); |
| 736 | IsBaseVirtual = Record[Idx++]; |
| 737 | } else { |
| 738 | Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++])); |
| 739 | } |
| 740 | SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx); |
| 741 | Expr *Init = Reader.ReadExpr(); |
| 742 | FieldDecl *AnonUnionMember |
| 743 | = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++])); |
| 744 | SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx); |
| 745 | SourceLocation RParenLoc = Reader.ReadSourceLocation(Record, Idx); |
| 746 | bool IsWritten = Record[Idx++]; |
| 747 | unsigned SourceOrderOrNumArrayIndices; |
| 748 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 749 | if (IsWritten) { |
| 750 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 751 | } else { |
| 752 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 753 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 754 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 755 | Indices.push_back(cast<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 756 | } |
| 757 | |
| 758 | CXXBaseOrMemberInitializer *BOMInit; |
| 759 | if (IsBaseInitializer) { |
| 760 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo, |
| 761 | IsBaseVirtual, LParenLoc, |
| 762 | Init, RParenLoc); |
| 763 | } else if (IsWritten) { |
| 764 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc, |
| 765 | LParenLoc, Init, RParenLoc); |
| 766 | } else { |
| 767 | BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc, |
| 768 | LParenLoc, Init, RParenLoc, |
| 769 | Indices.data(), |
| 770 | Indices.size()); |
| 771 | } |
| 772 | |
| 773 | BOMInit->setAnonUnionMember(AnonUnionMember); |
| 774 | D->BaseOrMemberInitializers[i] = BOMInit; |
| 775 | } |
| 776 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 780 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 781 | |
| 782 | D->ImplicitlyDefined = Record[Idx++]; |
| 783 | D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 787 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 788 | D->IsExplicitSpecified = Record[Idx++]; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 791 | void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 792 | VisitDecl(D); |
| 793 | D->setColonLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 794 | } |
| 795 | |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 796 | void PCHDeclReader::VisitFriendDecl(FriendDecl *D) { |
| 797 | if (Record[Idx++]) |
| 798 | D->Friend = Reader.GetTypeSourceInfo(Record, Idx); |
| 799 | else |
| 800 | D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
| 801 | D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++])); |
| 802 | D->FriendLoc = Reader.ReadSourceLocation(Record, Idx); |
| 803 | } |
| 804 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 805 | void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
| 806 | assert(false && "cannot read FriendTemplateDecl"); |
| 807 | } |
| 808 | |
| 809 | void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 810 | VisitNamedDecl(D); |
| 811 | |
| 812 | NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 813 | TemplateParameterList* TemplateParams |
| 814 | = Reader.ReadTemplateParameterList(Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 815 | D->init(TemplatedDecl, TemplateParams); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 819 | VisitTemplateDecl(D); |
| 820 | |
| 821 | ClassTemplateDecl *PrevDecl = |
| 822 | cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | a35c8e4 | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 823 | D->setPreviousDeclaration(PrevDecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 824 | if (PrevDecl == 0) { |
| 825 | // This ClassTemplateDecl owns a CommonPtr; read it. |
| 826 | |
| 827 | unsigned size = Record[Idx++]; |
| 828 | while (size--) { |
| 829 | ClassTemplateSpecializationDecl *CTSD |
| 830 | = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | e23371e | 2010-07-02 11:55:37 +0000 | [diff] [blame] | 831 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
| 832 | Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 833 | llvm::FoldingSetNodeID ID; |
| 834 | void *InsertPos = 0; |
Argyrios Kyrtzidis | e23371e | 2010-07-02 11:55:37 +0000 | [diff] [blame] | 835 | ClassTemplateSpecializationDecl::Profile(ID, TemplArgs.data(), |
| 836 | TemplArgs.size(), |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 837 | *Reader.getContext()); |
| 838 | D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos); |
| 839 | D->getSpecializations().InsertNode(CTSD, InsertPos); |
| 840 | } |
| 841 | |
| 842 | size = Record[Idx++]; |
| 843 | while (size--) { |
| 844 | ClassTemplatePartialSpecializationDecl *CTSD |
| 845 | = cast<ClassTemplatePartialSpecializationDecl>( |
| 846 | Reader.GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | e23371e | 2010-07-02 11:55:37 +0000 | [diff] [blame] | 847 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
| 848 | Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 849 | llvm::FoldingSetNodeID ID; |
| 850 | void *InsertPos = 0; |
Argyrios Kyrtzidis | e23371e | 2010-07-02 11:55:37 +0000 | [diff] [blame] | 851 | ClassTemplatePartialSpecializationDecl::Profile(ID, TemplArgs.data(), |
| 852 | TemplArgs.size(), |
| 853 | *Reader.getContext()); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 854 | D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos); |
| 855 | D->getPartialSpecializations().InsertNode(CTSD, InsertPos); |
| 856 | } |
| 857 | |
| 858 | // InjectedClassNameType is computed. |
| 859 | |
| 860 | if (ClassTemplateDecl *CTD |
| 861 | = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) { |
| 862 | D->setInstantiatedFromMemberTemplate(CTD); |
| 863 | if (Record[Idx++]) |
| 864 | D->setMemberSpecialization(); |
| 865 | } |
| 866 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | void PCHDeclReader::VisitClassTemplateSpecializationDecl( |
| 870 | ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 871 | VisitCXXRecordDecl(D); |
| 872 | |
| 873 | if (Decl *InstD = Reader.GetDecl(Record[Idx++])) { |
| 874 | if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { |
| 875 | D->setInstantiationOf(CTD); |
| 876 | } else { |
| 877 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
| 878 | Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx); |
| 879 | D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD), |
| 880 | TemplArgs.data(), TemplArgs.size()); |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | // Explicit info. |
| 885 | if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) { |
| 886 | D->setTypeAsWritten(TyInfo); |
| 887 | D->setExternLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 888 | D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 889 | } |
| 890 | |
| 891 | llvm::SmallVector<TemplateArgument, 8> TemplArgs; |
| 892 | Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx); |
| 893 | D->initTemplateArgs(TemplArgs.data(), TemplArgs.size()); |
| 894 | SourceLocation POI = Reader.ReadSourceLocation(Record, Idx); |
| 895 | if (POI.isValid()) |
| 896 | D->setPointOfInstantiation(POI); |
| 897 | D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl( |
| 901 | ClassTemplatePartialSpecializationDecl *D) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 902 | VisitClassTemplateSpecializationDecl(D); |
| 903 | |
| 904 | D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx)); |
| 905 | |
| 906 | TemplateArgumentListInfo ArgInfos; |
| 907 | unsigned NumArgs = Record[Idx++]; |
| 908 | while (NumArgs--) |
| 909 | ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx)); |
| 910 | D->initTemplateArgsAsWritten(ArgInfos); |
| 911 | |
| 912 | D->setSequenceNumber(Record[Idx++]); |
| 913 | |
| 914 | // These are read/set from/to the first declaration. |
| 915 | if (D->getPreviousDeclaration() == 0) { |
| 916 | D->setInstantiatedFromMember( |
| 917 | cast_or_null<ClassTemplatePartialSpecializationDecl>( |
| 918 | Reader.GetDecl(Record[Idx++]))); |
| 919 | if (Record[Idx++]) |
| 920 | D->isMemberSpecialization(); |
| 921 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 924 | void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 925 | VisitTemplateDecl(D); |
| 926 | |
| 927 | FunctionTemplateDecl *PrevDecl = |
| 928 | cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])); |
| 929 | D->setPreviousDeclaration(PrevDecl); |
| 930 | if (PrevDecl == 0) { |
| 931 | // This FunctionTemplateDecl owns a CommonPtr; read it. |
| 932 | |
| 933 | // FunctionTemplateSpecializationInfos are filled through the |
| 934 | // templated FunctionDecl's setFunctionTemplateSpecialization, no need to |
| 935 | // read them here. |
| 936 | |
| 937 | if (FunctionTemplateDecl *CTD |
| 938 | = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) { |
| 939 | D->setInstantiatedFromMemberTemplate(CTD); |
| 940 | if (Record[Idx++]) |
| 941 | D->setMemberSpecialization(); |
| 942 | } |
| 943 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 947 | VisitTypeDecl(D); |
| 948 | |
| 949 | D->setDeclaredWithTypename(Record[Idx++]); |
| 950 | D->setParameterPack(Record[Idx++]); |
| 951 | |
| 952 | bool Inherited = Record[Idx++]; |
| 953 | TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx); |
| 954 | D->setDefaultArgument(DefArg, Inherited); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Argyrios Kyrtzidis | b1d38e3 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 958 | VisitVarDecl(D); |
| 959 | // TemplateParmPosition. |
| 960 | D->setDepth(Record[Idx++]); |
| 961 | D->setPosition(Record[Idx++]); |
| 962 | // Rest of NonTypeTemplateParmDecl. |
| 963 | if (Record[Idx++]) { |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 964 | Expr *DefArg = Reader.ReadExpr(); |
Argyrios Kyrtzidis | b1d38e3 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 965 | bool Inherited = Record[Idx++]; |
| 966 | D->setDefaultArgument(DefArg, Inherited); |
| 967 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 971 | assert(false && "cannot read TemplateTemplateParmDecl"); |
| 972 | } |
| 973 | |
| 974 | void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 975 | assert(false && "cannot read StaticAssertDecl"); |
| 976 | } |
| 977 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | std::pair<uint64_t, uint64_t> |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 979 | PCHDeclReader::VisitDeclContext(DeclContext *DC) { |
| 980 | uint64_t LexicalOffset = Record[Idx++]; |
| 981 | uint64_t VisibleOffset = Record[Idx++]; |
| 982 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 983 | } |
| 984 | |
| 985 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 986 | // Attribute Reading |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 987 | //===----------------------------------------------------------------------===// |
| 988 | |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 989 | /// \brief Reads attributes from the current stream position. |
| 990 | Attr *PCHReader::ReadAttributes() { |
| 991 | unsigned Code = DeclsCursor.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | assert(Code == llvm::bitc::UNABBREV_RECORD && |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 993 | "Expected unabbreviated record"); (void)Code; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 995 | RecordData Record; |
| 996 | unsigned Idx = 0; |
| 997 | unsigned RecCode = DeclsCursor.ReadRecord(Code, Record); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | assert(RecCode == pch::DECL_ATTR && "Expected attribute record"); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 999 | (void)RecCode; |
| 1000 | |
| 1001 | #define SIMPLE_ATTR(Name) \ |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1002 | case attr::Name: \ |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1003 | New = ::new (*Context) Name##Attr(); \ |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1004 | break |
| 1005 | |
| 1006 | #define STRING_ATTR(Name) \ |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1007 | case attr::Name: \ |
Ted Kremenek | 7f4945a | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 1008 | New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \ |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1009 | break |
| 1010 | |
| 1011 | #define UNSIGNED_ATTR(Name) \ |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1012 | case attr::Name: \ |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1013 | New = ::new (*Context) Name##Attr(Record[Idx++]); \ |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1014 | break |
| 1015 | |
| 1016 | Attr *Attrs = 0; |
| 1017 | while (Idx < Record.size()) { |
| 1018 | Attr *New = 0; |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1019 | attr::Kind Kind = (attr::Kind)Record[Idx++]; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1020 | bool IsInherited = Record[Idx++]; |
| 1021 | |
| 1022 | switch (Kind) { |
Anton Korobeynikov | 55bcea1 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 1023 | default: |
| 1024 | assert(0 && "Unknown attribute!"); |
| 1025 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1026 | STRING_ATTR(Alias); |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 1027 | SIMPLE_ATTR(AlignMac68k); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1028 | UNSIGNED_ATTR(Aligned); |
| 1029 | SIMPLE_ATTR(AlwaysInline); |
| 1030 | SIMPLE_ATTR(AnalyzerNoReturn); |
| 1031 | STRING_ATTR(Annotate); |
| 1032 | STRING_ATTR(AsmLabel); |
Alexis Hunt | 54a0254 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1033 | SIMPLE_ATTR(BaseCheck); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1034 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1035 | case attr::Blocks: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1036 | New = ::new (*Context) BlocksAttr( |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1037 | (BlocksAttr::BlocksAttrTypes)Record[Idx++]); |
| 1038 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1039 | |
Eli Friedman | e4310c8 | 2009-11-09 18:38:53 +0000 | [diff] [blame] | 1040 | SIMPLE_ATTR(CDecl); |
| 1041 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1042 | case attr::Cleanup: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1043 | New = ::new (*Context) CleanupAttr( |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1044 | cast<FunctionDecl>(GetDecl(Record[Idx++]))); |
| 1045 | break; |
| 1046 | |
| 1047 | SIMPLE_ATTR(Const); |
| 1048 | UNSIGNED_ATTR(Constructor); |
| 1049 | SIMPLE_ATTR(DLLExport); |
| 1050 | SIMPLE_ATTR(DLLImport); |
| 1051 | SIMPLE_ATTR(Deprecated); |
| 1052 | UNSIGNED_ATTR(Destructor); |
| 1053 | SIMPLE_ATTR(FastCall); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1054 | SIMPLE_ATTR(Final); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1056 | case attr::Format: { |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1057 | std::string Type = ReadString(Record, Idx); |
| 1058 | unsigned FormatIdx = Record[Idx++]; |
| 1059 | unsigned FirstArg = Record[Idx++]; |
Ted Kremenek | 7f4945a | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 1060 | New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1061 | break; |
| 1062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1064 | case attr::FormatArg: { |
Fariborz Jahanian | f1c2502 | 2009-05-20 17:41:43 +0000 | [diff] [blame] | 1065 | unsigned FormatIdx = Record[Idx++]; |
| 1066 | New = ::new (*Context) FormatArgAttr(FormatIdx); |
| 1067 | break; |
| 1068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1070 | case attr::Sentinel: { |
Fariborz Jahanian | 027b886 | 2009-05-13 18:09:35 +0000 | [diff] [blame] | 1071 | int sentinel = Record[Idx++]; |
| 1072 | int nullPos = Record[Idx++]; |
| 1073 | New = ::new (*Context) SentinelAttr(sentinel, nullPos); |
| 1074 | break; |
| 1075 | } |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1076 | |
| 1077 | SIMPLE_ATTR(GNUInline); |
Alexis Hunt | 54a0254 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1078 | SIMPLE_ATTR(Hiding); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1080 | case attr::IBAction: |
Ted Kremenek | 06be968 | 2010-02-17 02:37:45 +0000 | [diff] [blame] | 1081 | New = ::new (*Context) IBActionAttr(); |
| 1082 | break; |
| 1083 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1084 | case attr::IBOutlet: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1085 | New = ::new (*Context) IBOutletAttr(); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1086 | break; |
| 1087 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1088 | case attr::IBOutletCollection: { |
Ted Kremenek | 26bde77 | 2010-05-19 17:38:06 +0000 | [diff] [blame] | 1089 | ObjCInterfaceDecl *D = |
| 1090 | cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
| 1091 | New = ::new (*Context) IBOutletCollectionAttr(D); |
| 1092 | break; |
| 1093 | } |
| 1094 | |
Ryan Flynn | 1f1fdc0 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 1095 | SIMPLE_ATTR(Malloc); |
Mike Stump | 3722f58 | 2009-08-26 22:31:08 +0000 | [diff] [blame] | 1096 | SIMPLE_ATTR(NoDebug); |
| 1097 | SIMPLE_ATTR(NoInline); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1098 | SIMPLE_ATTR(NoReturn); |
| 1099 | SIMPLE_ATTR(NoThrow); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1101 | case attr::NonNull: { |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1102 | unsigned Size = Record[Idx++]; |
| 1103 | llvm::SmallVector<unsigned, 16> ArgNums; |
| 1104 | ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size); |
| 1105 | Idx += Size; |
Ted Kremenek | 510ee25 | 2010-02-11 07:31:47 +0000 | [diff] [blame] | 1106 | New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1107 | break; |
| 1108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1109 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1110 | case attr::ReqdWorkGroupSize: { |
Nate Begeman | f275870 | 2009-06-26 06:32:41 +0000 | [diff] [blame] | 1111 | unsigned X = Record[Idx++]; |
| 1112 | unsigned Y = Record[Idx++]; |
| 1113 | unsigned Z = Record[Idx++]; |
| 1114 | New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z); |
| 1115 | break; |
| 1116 | } |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1117 | |
| 1118 | SIMPLE_ATTR(ObjCException); |
| 1119 | SIMPLE_ATTR(ObjCNSObject); |
Ted Kremenek | d9c6663 | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 1120 | SIMPLE_ATTR(CFReturnsNotRetained); |
Ted Kremenek | 9ecdfaf | 2009-05-09 02:44:38 +0000 | [diff] [blame] | 1121 | SIMPLE_ATTR(CFReturnsRetained); |
Ted Kremenek | d9c6663 | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 1122 | SIMPLE_ATTR(NSReturnsNotRetained); |
Ted Kremenek | 9ecdfaf | 2009-05-09 02:44:38 +0000 | [diff] [blame] | 1123 | SIMPLE_ATTR(NSReturnsRetained); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1124 | SIMPLE_ATTR(Overloadable); |
Alexis Hunt | 54a0254 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1125 | SIMPLE_ATTR(Override); |
Anders Carlsson | 68e0b68 | 2009-08-08 18:23:56 +0000 | [diff] [blame] | 1126 | SIMPLE_ATTR(Packed); |
Daniel Dunbar | 4013044 | 2010-05-27 01:12:46 +0000 | [diff] [blame] | 1127 | UNSIGNED_ATTR(MaxFieldAlignment); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1128 | SIMPLE_ATTR(Pure); |
| 1129 | UNSIGNED_ATTR(Regparm); |
| 1130 | STRING_ATTR(Section); |
| 1131 | SIMPLE_ATTR(StdCall); |
Douglas Gregor | a941dca | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 1132 | SIMPLE_ATTR(ThisCall); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1133 | SIMPLE_ATTR(TransparentUnion); |
| 1134 | SIMPLE_ATTR(Unavailable); |
| 1135 | SIMPLE_ATTR(Unused); |
| 1136 | SIMPLE_ATTR(Used); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1138 | case attr::Visibility: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1139 | New = ::new (*Context) VisibilityAttr( |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1140 | (VisibilityAttr::VisibilityTypes)Record[Idx++]); |
| 1141 | break; |
| 1142 | |
| 1143 | SIMPLE_ATTR(WarnUnusedResult); |
| 1144 | SIMPLE_ATTR(Weak); |
Rafael Espindola | c18086a | 2010-02-23 22:00:30 +0000 | [diff] [blame] | 1145 | SIMPLE_ATTR(WeakRef); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1146 | SIMPLE_ATTR(WeakImport); |
| 1147 | } |
| 1148 | |
| 1149 | assert(New && "Unable to decode attribute?"); |
| 1150 | New->setInherited(IsInherited); |
| 1151 | New->setNext(Attrs); |
| 1152 | Attrs = New; |
| 1153 | } |
| 1154 | #undef UNSIGNED_ATTR |
| 1155 | #undef STRING_ATTR |
| 1156 | #undef SIMPLE_ATTR |
| 1157 | |
| 1158 | // The list of attributes was built backwards. Reverse the list |
| 1159 | // before returning it. |
| 1160 | Attr *PrevAttr = 0, *NextAttr = 0; |
| 1161 | while (Attrs) { |
| 1162 | NextAttr = Attrs->getNext(); |
| 1163 | Attrs->setNext(PrevAttr); |
| 1164 | PrevAttr = Attrs; |
| 1165 | Attrs = NextAttr; |
| 1166 | } |
| 1167 | |
| 1168 | return PrevAttr; |
| 1169 | } |
| 1170 | |
| 1171 | //===----------------------------------------------------------------------===// |
| 1172 | // PCHReader Implementation |
| 1173 | //===----------------------------------------------------------------------===// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1174 | |
| 1175 | /// \brief Note that we have loaded the declaration with the given |
| 1176 | /// Index. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | /// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1178 | /// This routine notes that this declaration has already been loaded, |
| 1179 | /// so that future GetDecl calls will return this declaration rather |
| 1180 | /// than trying to load a new declaration. |
| 1181 | inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) { |
| 1182 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 1183 | DeclsLoaded[Index] = D; |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | /// \brief Determine whether the consumer will be interested in seeing |
| 1188 | /// this declaration (via HandleTopLevelDecl). |
| 1189 | /// |
| 1190 | /// This routine should return true for anything that might affect |
| 1191 | /// code generation, e.g., inline function definitions, Objective-C |
| 1192 | /// declarations with metadata, etc. |
| 1193 | static bool isConsumerInterestedIn(Decl *D) { |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 1194 | if (isa<FileScopeAsmDecl>(D)) |
| 1195 | return true; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1196 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) |
| 1197 | return Var->isFileVarDecl() && Var->getInit(); |
| 1198 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) |
| 1199 | return Func->isThisDeclarationADefinition(); |
| 1200 | return isa<ObjCProtocolDecl>(D); |
| 1201 | } |
| 1202 | |
| 1203 | /// \brief Read the declaration at the given offset from the PCH file. |
| 1204 | Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { |
| 1205 | // Keep track of where we are in the stream, then jump back there |
| 1206 | // after reading this declaration. |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1207 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1208 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 1209 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 1210 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 1211 | // Note that we are loading a declaration record. |
| 1212 | LoadingTypeOrDecl Loading(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1214 | DeclsCursor.JumpToBit(Offset); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1215 | RecordData Record; |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1216 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1217 | unsigned Idx = 0; |
| 1218 | PCHDeclReader Reader(*this, Record, Idx); |
| 1219 | |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 1220 | Decl *D = 0; |
| 1221 | switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1222 | case pch::DECL_ATTR: |
| 1223 | case pch::DECL_CONTEXT_LEXICAL: |
| 1224 | case pch::DECL_CONTEXT_VISIBLE: |
| 1225 | assert(false && "Record cannot be de-serialized with ReadDeclRecord"); |
| 1226 | break; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1227 | case pch::DECL_TRANSLATION_UNIT: |
| 1228 | assert(Index == 0 && "Translation unit must be at index 0"); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1229 | D = Context->getTranslationUnitDecl(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1230 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1231 | case pch::DECL_TYPEDEF: |
John McCall | 703a3f8 | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 1232 | D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1233 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1234 | case pch::DECL_ENUM: |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1235 | D = EnumDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1236 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1237 | case pch::DECL_RECORD: |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1238 | D = RecordDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1239 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1240 | case pch::DECL_ENUM_CONSTANT: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1241 | D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1242 | 0, llvm::APSInt()); |
| 1243 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1244 | case pch::DECL_FUNCTION: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1245 | D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(), |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1246 | QualType(), 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1247 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1248 | case pch::DECL_LINKAGE_SPEC: |
| 1249 | D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(), |
| 1250 | (LinkageSpecDecl::LanguageIDs)0, |
| 1251 | false); |
| 1252 | break; |
| 1253 | case pch::DECL_NAMESPACE: |
| 1254 | D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0); |
| 1255 | break; |
| 1256 | case pch::DECL_NAMESPACE_ALIAS: |
| 1257 | D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(), |
| 1258 | SourceLocation(), 0, SourceRange(), 0, |
| 1259 | SourceLocation(), 0); |
| 1260 | break; |
| 1261 | case pch::DECL_USING: |
| 1262 | D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(), |
| 1263 | SourceLocation(), 0, DeclarationName(), false); |
| 1264 | break; |
| 1265 | case pch::DECL_USING_SHADOW: |
| 1266 | D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
| 1267 | break; |
| 1268 | case pch::DECL_USING_DIRECTIVE: |
| 1269 | D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(), |
| 1270 | SourceLocation(), SourceRange(), 0, |
| 1271 | SourceLocation(), 0, 0); |
| 1272 | break; |
| 1273 | case pch::DECL_UNRESOLVED_USING_VALUE: |
| 1274 | D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(), |
| 1275 | SourceRange(), 0, SourceLocation(), |
| 1276 | DeclarationName()); |
| 1277 | break; |
| 1278 | case pch::DECL_UNRESOLVED_USING_TYPENAME: |
| 1279 | D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(), |
| 1280 | SourceLocation(), SourceRange(), |
| 1281 | 0, SourceLocation(), |
| 1282 | DeclarationName()); |
| 1283 | break; |
| 1284 | case pch::DECL_CXX_RECORD: |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1285 | D = CXXRecordDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1286 | break; |
| 1287 | case pch::DECL_CXX_METHOD: |
| 1288 | D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(), |
| 1289 | QualType(), 0); |
| 1290 | break; |
| 1291 | case pch::DECL_CXX_CONSTRUCTOR: |
| 1292 | D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell()); |
| 1293 | break; |
| 1294 | case pch::DECL_CXX_DESTRUCTOR: |
| 1295 | D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell()); |
| 1296 | break; |
| 1297 | case pch::DECL_CXX_CONVERSION: |
| 1298 | D = CXXConversionDecl::Create(*Context, Decl::EmptyShell()); |
| 1299 | break; |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1300 | case pch::DECL_ACCESS_SPEC: |
| 1301 | D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(), |
| 1302 | SourceLocation()); |
| 1303 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1304 | case pch::DECL_FRIEND: |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 1305 | D = FriendDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1306 | break; |
| 1307 | case pch::DECL_FRIEND_TEMPLATE: |
| 1308 | assert(false && "cannot read FriendTemplateDecl"); |
| 1309 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1310 | case pch::DECL_CLASS_TEMPLATE: |
Argyrios Kyrtzidis | a35c8e4 | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 1311 | D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(), |
| 1312 | DeclarationName(), 0, 0, 0); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1313 | break; |
| 1314 | case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION: |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1315 | D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1316 | break; |
| 1317 | case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1318 | D = ClassTemplatePartialSpecializationDecl::Create(*Context, |
| 1319 | Decl::EmptyShell()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1320 | break; |
| 1321 | case pch::DECL_FUNCTION_TEMPLATE: |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 1322 | D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(), |
| 1323 | DeclarationName(), 0, 0); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1324 | break; |
| 1325 | case pch::DECL_TEMPLATE_TYPE_PARM: |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 1326 | D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1327 | break; |
| 1328 | case pch::DECL_NON_TYPE_TEMPLATE_PARM: |
Argyrios Kyrtzidis | b1d38e3 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 1329 | D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0, |
| 1330 | QualType(),0); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | case pch::DECL_TEMPLATE_TEMPLATE_PARM: |
| 1333 | assert(false && "cannot read TemplateTemplateParmDecl"); |
| 1334 | break; |
| 1335 | case pch::DECL_STATIC_ASSERT: |
| 1336 | assert(false && "cannot read StaticAssertDecl"); |
| 1337 | break; |
| 1338 | |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1339 | case pch::DECL_OBJC_METHOD: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(), |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 1341 | Selector(), QualType(), 0, 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1342 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1343 | case pch::DECL_OBJC_INTERFACE: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1344 | D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1345 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1346 | case pch::DECL_OBJC_IVAR: |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1347 | D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1348 | ObjCIvarDecl::None); |
| 1349 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1350 | case pch::DECL_OBJC_PROTOCOL: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1351 | D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1352 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1353 | case pch::DECL_OBJC_AT_DEFS_FIELD: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0, |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1355 | QualType(), 0); |
| 1356 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1357 | case pch::DECL_OBJC_CLASS: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1358 | D = ObjCClassDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1359 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1360 | case pch::DECL_OBJC_FORWARD_PROTOCOL: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1361 | D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1362 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1363 | case pch::DECL_OBJC_CATEGORY: |
Douglas Gregor | 071676f | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 1364 | D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), |
| 1365 | SourceLocation(), SourceLocation(), 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1366 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1367 | case pch::DECL_OBJC_CATEGORY_IMPL: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1368 | D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1369 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1370 | case pch::DECL_OBJC_IMPLEMENTATION: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1371 | D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1372 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1373 | case pch::DECL_OBJC_COMPATIBLE_ALIAS: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1374 | D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1375 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1376 | case pch::DECL_OBJC_PROPERTY: |
Fariborz Jahanian | da8ec2b | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 1377 | D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), |
John McCall | 339bb66 | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 1378 | 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1379 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1380 | case pch::DECL_OBJC_PROPERTY_IMPL: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1381 | D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | SourceLocation(), 0, |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1383 | ObjCPropertyImplDecl::Dynamic, 0); |
| 1384 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1385 | case pch::DECL_FIELD: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1386 | D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0, |
Argyrios Kyrtzidis | 6032ef1 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 1387 | false); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1388 | break; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1389 | case pch::DECL_VAR: |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1390 | D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1391 | VarDecl::None, VarDecl::None); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1392 | break; |
| 1393 | |
| 1394 | case pch::DECL_IMPLICIT_PARAM: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1395 | D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1396 | break; |
| 1397 | |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1398 | case pch::DECL_PARM_VAR: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1400 | VarDecl::None, VarDecl::None, 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1401 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1402 | case pch::DECL_FILE_SCOPE_ASM: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1403 | D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1404 | break; |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1405 | case pch::DECL_BLOCK: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1406 | D = BlockDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1407 | break; |
| 1408 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1409 | |
| 1410 | assert(D && "Unknown declaration reading PCH file"); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1411 | LoadedDecl(Index, D); |
| 1412 | Reader.Visit(D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1413 | |
| 1414 | // If this declaration is also a declaration context, get the |
| 1415 | // offsets for its tables of lexical and visible declarations. |
| 1416 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 1417 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
| 1418 | if (Offsets.first || Offsets.second) { |
| 1419 | DC->setHasExternalLexicalStorage(Offsets.first != 0); |
| 1420 | DC->setHasExternalVisibleStorage(Offsets.second != 0); |
| 1421 | DeclContextOffsets[DC] = Offsets; |
| 1422 | } |
| 1423 | } |
| 1424 | assert(Idx == Record.size()); |
| 1425 | |
| 1426 | // If we have deserialized a declaration that has a definition the |
| 1427 | // AST consumer might need to know about, notify the consumer |
| 1428 | // about that definition now or queue it for later. |
| 1429 | if (isConsumerInterestedIn(D)) { |
| 1430 | if (Consumer) { |
| 1431 | DeclGroupRef DG(D); |
| 1432 | Consumer->HandleTopLevelDecl(DG); |
| 1433 | } else { |
| 1434 | InterestingDecls.push_back(D); |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | return D; |
| 1439 | } |