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