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