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