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