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 | |
| 41 | void VisitDecl(Decl *D); |
| 42 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 43 | void VisitNamedDecl(NamedDecl *ND); |
Douglas Gregor | 0cef483 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 44 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 45 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 46 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 47 | void VisitTypeDecl(TypeDecl *TD); |
| 48 | void VisitTypedefDecl(TypedefDecl *TD); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 49 | void VisitUnresolvedUsingTypename(UnresolvedUsingTypenameDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 50 | void VisitTagDecl(TagDecl *TD); |
| 51 | void VisitEnumDecl(EnumDecl *ED); |
| 52 | void VisitRecordDecl(RecordDecl *RD); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 53 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
| 54 | void VisitClassTemplateSpecializationDecl( |
| 55 | ClassTemplateSpecializationDecl *D); |
| 56 | void VisitClassTemplatePartialSpecializationDecl( |
| 57 | ClassTemplatePartialSpecializationDecl *D); |
| 58 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 59 | void VisitValueDecl(ValueDecl *VD); |
| 60 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 61 | void VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 62 | void VisitDeclaratorDecl(DeclaratorDecl *DD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 63 | void VisitFunctionDecl(FunctionDecl *FD); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 64 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 65 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 66 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 67 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 68 | void VisitFieldDecl(FieldDecl *FD); |
| 69 | void VisitVarDecl(VarDecl *VD); |
| 70 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); |
| 71 | void VisitParmVarDecl(ParmVarDecl *PD); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 72 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 73 | void VisitTemplateDecl(TemplateDecl *D); |
| 74 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 75 | void visitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| 76 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 77 | void VisitUsing(UsingDecl *D); |
| 78 | void VisitUsingShadow(UsingShadowDecl *D); |
| 79 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 80 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 81 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 82 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 83 | void VisitBlockDecl(BlockDecl *BD); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 85 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 86 | |
| 87 | // FIXME: Reorder according to DeclNodes.def? |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 88 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 89 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 90 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 91 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 92 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 93 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| 94 | void VisitObjCClassDecl(ObjCClassDecl *D); |
| 95 | void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D); |
| 96 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 97 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 98 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 99 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 100 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 101 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 102 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 103 | }; |
| 104 | } |
| 105 | |
| 106 | void PCHDeclReader::VisitDecl(Decl *D) { |
| 107 | D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 108 | D->setLexicalDeclContext( |
| 109 | cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 110 | D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 111 | D->setInvalidDecl(Record[Idx++]); |
| 112 | if (Record[Idx++]) |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 113 | D->addAttr(Reader.ReadAttributes()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 114 | D->setImplicit(Record[Idx++]); |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 115 | D->setUsed(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 116 | D->setAccess((AccessSpecifier)Record[Idx++]); |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 117 | D->setPCHLevel(Record[Idx++] + 1); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
| 121 | VisitDecl(TU); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 122 | TU->setAnonymousNamespace( |
| 123 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) { |
| 127 | VisitDecl(ND); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | ND->setDeclName(Reader.ReadDeclarationName(Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) { |
| 132 | VisitNamedDecl(TD); |
| 133 | TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
| 134 | } |
| 135 | |
| 136 | void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
| 137 | // Note that we cannot use VisitTypeDecl here, because we need to |
| 138 | // set the underlying type of the typedef *before* we try to read |
| 139 | // the type associated with the TypedefDecl. |
| 140 | VisitNamedDecl(TD); |
John McCall | ba6a9bd | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 141 | uint64_t TypeData = Record[Idx++]; |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 142 | TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); |
John McCall | ba6a9bd | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 143 | TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void PCHDeclReader::VisitTagDecl(TagDecl *TD) { |
| 147 | VisitTypeDecl(TD); |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 148 | TD->setPreviousDeclaration( |
| 149 | cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 150 | TD->setTagKind((TagDecl::TagKind)Record[Idx++]); |
| 151 | TD->setDefinition(Record[Idx++]); |
Douglas Gregor | b37b648 | 2010-02-12 17:40:34 +0000 | [diff] [blame] | 152 | TD->setEmbeddedInDeclarator(Record[Idx++]); |
Argyrios Kyrtzidis | ad93a74 | 2009-07-14 03:18:02 +0000 | [diff] [blame] | 153 | TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 154 | TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
John McCall | b621766 | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 155 | // FIXME: maybe read optional qualifier and its range. |
| 156 | TD->setTypedefForAnonDecl( |
| 157 | cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) { |
| 161 | VisitTagDecl(ED); |
| 162 | ED->setIntegerType(Reader.GetType(Record[Idx++])); |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 163 | ED->setPromotionType(Reader.GetType(Record[Idx++])); |
John McCall | 1b5a618 | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 164 | ED->setNumPositiveBits(Record[Idx++]); |
| 165 | ED->setNumNegativeBits(Record[Idx++]); |
Douglas Gregor | 8dbc3c6 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 166 | // FIXME: C++ InstantiatedFrom |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) { |
| 170 | VisitTagDecl(RD); |
| 171 | RD->setHasFlexibleArrayMember(Record[Idx++]); |
| 172 | RD->setAnonymousStructOrUnion(Record[Idx++]); |
Fariborz Jahanian | 643b7df | 2009-07-08 16:37:44 +0000 | [diff] [blame] | 173 | RD->setHasObjectMember(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void PCHDeclReader::VisitValueDecl(ValueDecl *VD) { |
| 177 | VisitNamedDecl(VD); |
| 178 | VD->setType(Reader.GetType(Record[Idx++])); |
| 179 | } |
| 180 | |
| 181 | void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
| 182 | VisitValueDecl(ECD); |
| 183 | if (Record[Idx++]) |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 184 | ECD->setInitExpr(Reader.ReadDeclExpr()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 185 | ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); |
| 186 | } |
| 187 | |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 188 | void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
| 189 | VisitValueDecl(DD); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 190 | TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx); |
| 191 | if (TInfo) |
| 192 | DD->setTypeSourceInfo(TInfo); |
John McCall | b621766 | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 193 | // FIXME: read optional qualifier and its range. |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 196 | void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 197 | VisitDeclaratorDecl(FD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 198 | if (Record[Idx++]) |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 199 | FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 200 | FD->setPreviousDeclaration( |
| 201 | cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]))); |
| 202 | FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]); |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 203 | FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]); |
Douglas Gregor | 0130f3c | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 204 | FD->setInlineSpecified(Record[Idx++]); |
Anders Carlsson | 77b7f1d | 2009-05-14 22:15:41 +0000 | [diff] [blame] | 205 | FD->setVirtualAsWritten(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 206 | FD->setPure(Record[Idx++]); |
Anders Carlsson | a75e853 | 2009-05-14 21:46:00 +0000 | [diff] [blame] | 207 | FD->setHasInheritedPrototype(Record[Idx++]); |
| 208 | FD->setHasWrittenPrototype(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 209 | FD->setDeleted(Record[Idx++]); |
Daniel Dunbar | 7f8b57a | 2009-09-22 05:38:14 +0000 | [diff] [blame] | 210 | FD->setTrivial(Record[Idx++]); |
| 211 | FD->setCopyAssignment(Record[Idx++]); |
| 212 | FD->setHasImplicitReturnZero(Record[Idx++]); |
Argyrios Kyrtzidis | 8cff90e | 2009-06-20 08:09:34 +0000 | [diff] [blame] | 213 | FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 214 | // FIXME: C++ TemplateOrInstantiation |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 215 | |
| 216 | // Read in the parameters. |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 217 | unsigned NumParams = Record[Idx++]; |
| 218 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 219 | Params.reserve(NumParams); |
| 220 | for (unsigned I = 0; I != NumParams; ++I) |
| 221 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 838db38 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 222 | FD->setParams(Params.data(), NumParams); |
John McCall | 76d3264 | 2010-04-24 01:30:58 +0000 | [diff] [blame] | 223 | |
| 224 | // FIXME: order this properly w.r.t. friendness |
| 225 | // FIXME: this same thing needs to happen for function templates |
| 226 | if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord()) |
| 227 | FD->setNonMemberOperator(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
| 231 | VisitNamedDecl(MD); |
| 232 | if (Record[Idx++]) { |
| 233 | // In practice, this won't be executed (since method definitions |
| 234 | // don't occur in header files). |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 235 | MD->setBody(Reader.ReadDeclStmt()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 236 | MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 237 | MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 238 | } |
| 239 | MD->setInstanceMethod(Record[Idx++]); |
| 240 | MD->setVariadic(Record[Idx++]); |
| 241 | MD->setSynthesized(Record[Idx++]); |
| 242 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); |
| 243 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
Fariborz Jahanian | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 244 | MD->setNumSelectorArgs(unsigned(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 245 | MD->setResultType(Reader.GetType(Record[Idx++])); |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 246 | MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 247 | MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 248 | unsigned NumParams = Record[Idx++]; |
| 249 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 250 | Params.reserve(NumParams); |
| 251 | for (unsigned I = 0; I != NumParams; ++I) |
| 252 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Fariborz Jahanian | 4ecb25f | 2010-04-09 15:40:42 +0000 | [diff] [blame] | 253 | MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams, |
| 254 | NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
| 258 | VisitNamedDecl(CD); |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 259 | SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 260 | SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 261 | CD->setAtEndRange(SourceRange(A, B)); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
| 265 | VisitObjCContainerDecl(ID); |
| 266 | ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
| 267 | ID->setSuperClass(cast_or_null<ObjCInterfaceDecl> |
| 268 | (Reader.GetDecl(Record[Idx++]))); |
| 269 | unsigned NumProtocols = Record[Idx++]; |
| 270 | llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 271 | Protocols.reserve(NumProtocols); |
| 272 | for (unsigned I = 0; I != NumProtocols; ++I) |
| 273 | Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 274 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 275 | ProtoLocs.reserve(NumProtocols); |
| 276 | for (unsigned I = 0; I != NumProtocols; ++I) |
| 277 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 278 | ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(), |
| 279 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 280 | unsigned NumIvars = Record[Idx++]; |
| 281 | llvm::SmallVector<ObjCIvarDecl *, 16> IVars; |
| 282 | IVars.reserve(NumIvars); |
| 283 | for (unsigned I = 0; I != NumIvars; ++I) |
| 284 | IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 285 | ID->setCategoryList( |
| 286 | cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
| 287 | ID->setForwardDecl(Record[Idx++]); |
| 288 | ID->setImplicitInterfaceDecl(Record[Idx++]); |
| 289 | ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 290 | ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Argyrios Kyrtzidis | c999f1f | 2009-07-18 00:33:23 +0000 | [diff] [blame] | 291 | ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
| 295 | VisitFieldDecl(IVD); |
| 296 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); |
| 297 | } |
| 298 | |
| 299 | void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 300 | VisitObjCContainerDecl(PD); |
| 301 | PD->setForwardDecl(Record[Idx++]); |
| 302 | PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 303 | unsigned NumProtoRefs = Record[Idx++]; |
| 304 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 305 | ProtoRefs.reserve(NumProtoRefs); |
| 306 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 307 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 308 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 309 | ProtoLocs.reserve(NumProtoRefs); |
| 310 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 311 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 312 | PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 313 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
| 317 | VisitFieldDecl(FD); |
| 318 | } |
| 319 | |
| 320 | void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) { |
| 321 | VisitDecl(CD); |
| 322 | unsigned NumClassRefs = Record[Idx++]; |
| 323 | llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs; |
| 324 | ClassRefs.reserve(NumClassRefs); |
| 325 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 326 | ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 327 | llvm::SmallVector<SourceLocation, 16> SLocs; |
| 328 | SLocs.reserve(NumClassRefs); |
| 329 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 330 | SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 331 | CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(), |
| 332 | NumClassRefs); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) { |
| 336 | VisitDecl(FPD); |
| 337 | unsigned NumProtoRefs = Record[Idx++]; |
| 338 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 339 | ProtoRefs.reserve(NumProtoRefs); |
| 340 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 341 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 342 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 343 | ProtoLocs.reserve(NumProtoRefs); |
| 344 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 345 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 346 | FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 347 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
| 351 | VisitObjCContainerDecl(CD); |
| 352 | CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 353 | unsigned NumProtoRefs = Record[Idx++]; |
| 354 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 355 | ProtoRefs.reserve(NumProtoRefs); |
| 356 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 357 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 358 | llvm::SmallVector<SourceLocation, 16> ProtoLocs; |
| 359 | ProtoLocs.reserve(NumProtoRefs); |
| 360 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 361 | ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 362 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
| 363 | *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 364 | CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 365 | CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 366 | CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
| 370 | VisitNamedDecl(CAD); |
| 371 | CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 372 | } |
| 373 | |
| 374 | void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 375 | VisitNamedDecl(D); |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 376 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 377 | D->setType(Reader.GetType(Record[Idx++])); |
| 378 | // FIXME: stable encoding |
| 379 | D->setPropertyAttributes( |
| 380 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
| 381 | // FIXME: stable encoding |
| 382 | D->setPropertyImplementation( |
| 383 | (ObjCPropertyDecl::PropertyControl)Record[Idx++]); |
| 384 | D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 385 | D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 386 | D->setGetterMethodDecl( |
| 387 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 388 | D->setSetterMethodDecl( |
| 389 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 390 | D->setPropertyIvarDecl( |
| 391 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 392 | } |
| 393 | |
| 394 | void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | aecae62 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 395 | VisitObjCContainerDecl(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 396 | D->setClassInterface( |
| 397 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 401 | VisitObjCImplDecl(D); |
| 402 | D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx)); |
| 403 | } |
| 404 | |
| 405 | void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 406 | VisitObjCImplDecl(D); |
| 407 | D->setSuperClass( |
| 408 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Fariborz Jahanian | e4498c6 | 2010-04-28 16:11:27 +0000 | [diff] [blame] | 409 | // FIXME. Add reading of IvarInitializers and NumIvarInitializers. |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | |
| 413 | void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 414 | VisitDecl(D); |
| 415 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 416 | D->setPropertyDecl( |
| 417 | cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 418 | D->setPropertyIvarDecl( |
| 419 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Fariborz Jahanian | 17cb326 | 2010-05-05 21:52:17 +0000 | [diff] [blame] | 420 | // FIXME. read GetterCXXConstructor and SetterCXXAssignment |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 424 | VisitDeclaratorDecl(FD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 425 | FD->setMutable(Record[Idx++]); |
| 426 | if (Record[Idx++]) |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 427 | FD->setBitWidth(Reader.ReadDeclExpr()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void PCHDeclReader::VisitVarDecl(VarDecl *VD) { |
Argyrios Kyrtzidis | d4a7e54 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 431 | VisitDeclaratorDecl(VD); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 432 | VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]); |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 433 | VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 434 | VD->setThreadSpecified(Record[Idx++]); |
| 435 | VD->setCXXDirectInitializer(Record[Idx++]); |
| 436 | VD->setDeclaredInCondition(Record[Idx++]); |
Douglas Gregor | 324b54d | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 437 | VD->setExceptionVariable(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 438 | VD->setPreviousDeclaration( |
| 439 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 440 | if (Record[Idx++]) |
Douglas Gregor | 838db38 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 441 | VD->setInit(Reader.ReadDeclExpr()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
| 445 | VisitVarDecl(PD); |
| 446 | } |
| 447 | |
| 448 | void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
| 449 | VisitVarDecl(PD); |
| 450 | PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
John McCall | bf73b35 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 451 | PD->setHasInheritedDefaultArg(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 454 | void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
| 455 | VisitDecl(AD); |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 456 | AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr())); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) { |
| 460 | VisitDecl(BD); |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 461 | BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt())); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 462 | unsigned NumParams = Record[Idx++]; |
| 463 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 464 | Params.reserve(NumParams); |
| 465 | for (unsigned I = 0; I != NumParams; ++I) |
| 466 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 838db38 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 467 | BD->setParams(Params.data(), NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 470 | void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 471 | VisitDecl(D); |
| 472 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]); |
| 473 | D->setHasBraces(Record[Idx++]); |
| 474 | } |
| 475 | |
| 476 | void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
| 477 | VisitNamedDecl(D); |
| 478 | D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 479 | D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 480 | D->setNextNamespace( |
| 481 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 482 | |
| 483 | // Only read one reference--the original or anonymous namespace. |
| 484 | bool IsOriginal = Record[Idx++]; |
| 485 | if (IsOriginal) |
| 486 | D->setAnonymousNamespace( |
| 487 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 488 | else |
| 489 | D->setOriginalNamespace( |
| 490 | cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 491 | } |
| 492 | |
| 493 | void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 494 | VisitNamedDecl(D); |
| 495 | |
| 496 | D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 497 | D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 498 | D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 499 | D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 500 | D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 501 | } |
| 502 | |
| 503 | void PCHDeclReader::VisitUsing(UsingDecl *D) { |
| 504 | VisitNamedDecl(D); |
| 505 | D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 506 | D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 507 | D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 508 | |
| 509 | // FIXME: It would probably be more efficient to read these into a vector |
| 510 | // and then re-cosntruct the shadow decl set over that vector since it |
| 511 | // would avoid existence checks. |
| 512 | unsigned NumShadows = Record[Idx++]; |
| 513 | for(unsigned I = 0; I != NumShadows; ++I) { |
| 514 | D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]))); |
| 515 | } |
| 516 | D->setTypeName(Record[Idx++]); |
| 517 | } |
| 518 | |
| 519 | void PCHDeclReader::VisitUsingShadow(UsingShadowDecl *D) { |
| 520 | VisitNamedDecl(D); |
| 521 | D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 522 | D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++]))); |
| 523 | } |
| 524 | |
| 525 | void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 526 | VisitNamedDecl(D); |
| 527 | D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 528 | D->setQualifierRange(Reader.ReadSourceRange(Record, Idx)); |
| 529 | D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 530 | D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx)); |
| 531 | D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 532 | D->setCommonAncestor(cast_or_null<DeclContext>( |
| 533 | Reader.GetDecl(Record[Idx++]))); |
| 534 | } |
| 535 | |
| 536 | void PCHDeclReader::VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D) { |
| 537 | VisitValueDecl(D); |
| 538 | D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 539 | D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 540 | D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 541 | } |
| 542 | |
| 543 | void PCHDeclReader::VisitUnresolvedUsingTypename( |
| 544 | UnresolvedUsingTypenameDecl *D) { |
| 545 | VisitTypeDecl(D); |
| 546 | D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx)); |
| 547 | D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 548 | D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx)); |
| 549 | D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx)); |
| 550 | } |
| 551 | |
| 552 | void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 553 | // assert(false && "cannot read CXXRecordDecl"); |
| 554 | VisitRecordDecl(D); |
| 555 | } |
| 556 | |
| 557 | void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 558 | // assert(false && "cannot read CXXMethodDecl"); |
| 559 | VisitFunctionDecl(D); |
| 560 | } |
| 561 | |
| 562 | void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 563 | // assert(false && "cannot read CXXConstructorDecl"); |
| 564 | VisitCXXMethodDecl(D); |
| 565 | } |
| 566 | |
| 567 | void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 568 | // assert(false && "cannot read CXXDestructorDecl"); |
| 569 | VisitCXXMethodDecl(D); |
| 570 | } |
| 571 | |
| 572 | void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 573 | // assert(false && "cannot read CXXConversionDecl"); |
| 574 | VisitCXXMethodDecl(D); |
| 575 | } |
| 576 | |
| 577 | void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
| 578 | assert(false && "cannot read FriendTemplateDecl"); |
| 579 | } |
| 580 | |
| 581 | void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
| 582 | assert(false && "cannot read TemplateDecl"); |
| 583 | } |
| 584 | |
| 585 | void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 586 | assert(false && "cannot read ClassTemplateDecl"); |
| 587 | } |
| 588 | |
| 589 | void PCHDeclReader::VisitClassTemplateSpecializationDecl( |
| 590 | ClassTemplateSpecializationDecl *D) { |
| 591 | assert(false && "cannot read ClassTemplateSpecializationDecl"); |
| 592 | } |
| 593 | |
| 594 | void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl( |
| 595 | ClassTemplatePartialSpecializationDecl *D) { |
| 596 | assert(false && "cannot read ClassTemplatePartialSpecializationDecl"); |
| 597 | } |
| 598 | |
| 599 | void PCHDeclReader::visitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 600 | assert(false && "cannot read FunctionTemplateDecl"); |
| 601 | } |
| 602 | |
| 603 | void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 604 | assert(false && "cannot read TemplateTypeParmDecl"); |
| 605 | } |
| 606 | |
| 607 | void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 608 | assert(false && "cannot read NonTypeTemplateParmDecl"); |
| 609 | } |
| 610 | |
| 611 | void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 612 | assert(false && "cannot read TemplateTemplateParmDecl"); |
| 613 | } |
| 614 | |
| 615 | void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 616 | assert(false && "cannot read StaticAssertDecl"); |
| 617 | } |
| 618 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | std::pair<uint64_t, uint64_t> |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 620 | PCHDeclReader::VisitDeclContext(DeclContext *DC) { |
| 621 | uint64_t LexicalOffset = Record[Idx++]; |
| 622 | uint64_t VisibleOffset = Record[Idx++]; |
| 623 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 624 | } |
| 625 | |
| 626 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 627 | // Attribute Reading |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 628 | //===----------------------------------------------------------------------===// |
| 629 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 630 | /// \brief Reads attributes from the current stream position. |
| 631 | Attr *PCHReader::ReadAttributes() { |
| 632 | unsigned Code = DeclsCursor.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | assert(Code == llvm::bitc::UNABBREV_RECORD && |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 634 | "Expected unabbreviated record"); (void)Code; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 636 | RecordData Record; |
| 637 | unsigned Idx = 0; |
| 638 | unsigned RecCode = DeclsCursor.ReadRecord(Code, Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | assert(RecCode == pch::DECL_ATTR && "Expected attribute record"); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 640 | (void)RecCode; |
| 641 | |
| 642 | #define SIMPLE_ATTR(Name) \ |
| 643 | case Attr::Name: \ |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 644 | New = ::new (*Context) Name##Attr(); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 645 | break |
| 646 | |
| 647 | #define STRING_ATTR(Name) \ |
| 648 | case Attr::Name: \ |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 649 | New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 650 | break |
| 651 | |
| 652 | #define UNSIGNED_ATTR(Name) \ |
| 653 | case Attr::Name: \ |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 654 | New = ::new (*Context) Name##Attr(Record[Idx++]); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 655 | break |
| 656 | |
| 657 | Attr *Attrs = 0; |
| 658 | while (Idx < Record.size()) { |
| 659 | Attr *New = 0; |
| 660 | Attr::Kind Kind = (Attr::Kind)Record[Idx++]; |
| 661 | bool IsInherited = Record[Idx++]; |
| 662 | |
| 663 | switch (Kind) { |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 664 | default: |
| 665 | assert(0 && "Unknown attribute!"); |
| 666 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 667 | STRING_ATTR(Alias); |
| 668 | UNSIGNED_ATTR(Aligned); |
| 669 | SIMPLE_ATTR(AlwaysInline); |
| 670 | SIMPLE_ATTR(AnalyzerNoReturn); |
| 671 | STRING_ATTR(Annotate); |
| 672 | STRING_ATTR(AsmLabel); |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 673 | SIMPLE_ATTR(BaseCheck); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 675 | case Attr::Blocks: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 676 | New = ::new (*Context) BlocksAttr( |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 677 | (BlocksAttr::BlocksAttrTypes)Record[Idx++]); |
| 678 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | |
Eli Friedman | 8f4c59e | 2009-11-09 18:38:53 +0000 | [diff] [blame] | 680 | SIMPLE_ATTR(CDecl); |
| 681 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 682 | case Attr::Cleanup: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 683 | New = ::new (*Context) CleanupAttr( |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 684 | cast<FunctionDecl>(GetDecl(Record[Idx++]))); |
| 685 | break; |
| 686 | |
| 687 | SIMPLE_ATTR(Const); |
| 688 | UNSIGNED_ATTR(Constructor); |
| 689 | SIMPLE_ATTR(DLLExport); |
| 690 | SIMPLE_ATTR(DLLImport); |
| 691 | SIMPLE_ATTR(Deprecated); |
| 692 | UNSIGNED_ATTR(Destructor); |
| 693 | SIMPLE_ATTR(FastCall); |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 694 | SIMPLE_ATTR(Final); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 696 | case Attr::Format: { |
| 697 | std::string Type = ReadString(Record, Idx); |
| 698 | unsigned FormatIdx = Record[Idx++]; |
| 699 | unsigned FirstArg = Record[Idx++]; |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 700 | New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 701 | break; |
| 702 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 703 | |
Fariborz Jahanian | 5b16092 | 2009-05-20 17:41:43 +0000 | [diff] [blame] | 704 | case Attr::FormatArg: { |
| 705 | unsigned FormatIdx = Record[Idx++]; |
| 706 | New = ::new (*Context) FormatArgAttr(FormatIdx); |
| 707 | break; |
| 708 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 709 | |
Fariborz Jahanian | 5b53005 | 2009-05-13 18:09:35 +0000 | [diff] [blame] | 710 | case Attr::Sentinel: { |
| 711 | int sentinel = Record[Idx++]; |
| 712 | int nullPos = Record[Idx++]; |
| 713 | New = ::new (*Context) SentinelAttr(sentinel, nullPos); |
| 714 | break; |
| 715 | } |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 716 | |
| 717 | SIMPLE_ATTR(GNUInline); |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 718 | SIMPLE_ATTR(Hiding); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 719 | |
Ted Kremenek | efbddd2 | 2010-02-17 02:37:45 +0000 | [diff] [blame] | 720 | case Attr::IBActionKind: |
| 721 | New = ::new (*Context) IBActionAttr(); |
| 722 | break; |
| 723 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 724 | case Attr::IBOutletKind: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 725 | New = ::new (*Context) IBOutletAttr(); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 726 | break; |
| 727 | |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 728 | SIMPLE_ATTR(Malloc); |
Mike Stump | 1feade8 | 2009-08-26 22:31:08 +0000 | [diff] [blame] | 729 | SIMPLE_ATTR(NoDebug); |
| 730 | SIMPLE_ATTR(NoInline); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 731 | SIMPLE_ATTR(NoReturn); |
| 732 | SIMPLE_ATTR(NoThrow); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 734 | case Attr::NonNull: { |
| 735 | unsigned Size = Record[Idx++]; |
| 736 | llvm::SmallVector<unsigned, 16> ArgNums; |
| 737 | ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size); |
| 738 | Idx += Size; |
Ted Kremenek | 5961611 | 2010-02-11 07:31:47 +0000 | [diff] [blame] | 739 | New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 740 | break; |
| 741 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | |
Nate Begeman | 6f3d838 | 2009-06-26 06:32:41 +0000 | [diff] [blame] | 743 | case Attr::ReqdWorkGroupSize: { |
| 744 | unsigned X = Record[Idx++]; |
| 745 | unsigned Y = Record[Idx++]; |
| 746 | unsigned Z = Record[Idx++]; |
| 747 | New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z); |
| 748 | break; |
| 749 | } |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 750 | |
| 751 | SIMPLE_ATTR(ObjCException); |
| 752 | SIMPLE_ATTR(ObjCNSObject); |
Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 753 | SIMPLE_ATTR(CFReturnsNotRetained); |
Ted Kremenek | b71368d | 2009-05-09 02:44:38 +0000 | [diff] [blame] | 754 | SIMPLE_ATTR(CFReturnsRetained); |
Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 755 | SIMPLE_ATTR(NSReturnsNotRetained); |
Ted Kremenek | b71368d | 2009-05-09 02:44:38 +0000 | [diff] [blame] | 756 | SIMPLE_ATTR(NSReturnsRetained); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 757 | SIMPLE_ATTR(Overloadable); |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 758 | SIMPLE_ATTR(Override); |
Anders Carlsson | a860e75 | 2009-08-08 18:23:56 +0000 | [diff] [blame] | 759 | SIMPLE_ATTR(Packed); |
| 760 | UNSIGNED_ATTR(PragmaPack); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 761 | SIMPLE_ATTR(Pure); |
| 762 | UNSIGNED_ATTR(Regparm); |
| 763 | STRING_ATTR(Section); |
| 764 | SIMPLE_ATTR(StdCall); |
| 765 | SIMPLE_ATTR(TransparentUnion); |
| 766 | SIMPLE_ATTR(Unavailable); |
| 767 | SIMPLE_ATTR(Unused); |
| 768 | SIMPLE_ATTR(Used); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 770 | case Attr::Visibility: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 771 | New = ::new (*Context) VisibilityAttr( |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 772 | (VisibilityAttr::VisibilityTypes)Record[Idx++]); |
| 773 | break; |
| 774 | |
| 775 | SIMPLE_ATTR(WarnUnusedResult); |
| 776 | SIMPLE_ATTR(Weak); |
Rafael Espindola | 11e8ce7 | 2010-02-23 22:00:30 +0000 | [diff] [blame] | 777 | SIMPLE_ATTR(WeakRef); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 778 | SIMPLE_ATTR(WeakImport); |
| 779 | } |
| 780 | |
| 781 | assert(New && "Unable to decode attribute?"); |
| 782 | New->setInherited(IsInherited); |
| 783 | New->setNext(Attrs); |
| 784 | Attrs = New; |
| 785 | } |
| 786 | #undef UNSIGNED_ATTR |
| 787 | #undef STRING_ATTR |
| 788 | #undef SIMPLE_ATTR |
| 789 | |
| 790 | // The list of attributes was built backwards. Reverse the list |
| 791 | // before returning it. |
| 792 | Attr *PrevAttr = 0, *NextAttr = 0; |
| 793 | while (Attrs) { |
| 794 | NextAttr = Attrs->getNext(); |
| 795 | Attrs->setNext(PrevAttr); |
| 796 | PrevAttr = Attrs; |
| 797 | Attrs = NextAttr; |
| 798 | } |
| 799 | |
| 800 | return PrevAttr; |
| 801 | } |
| 802 | |
| 803 | //===----------------------------------------------------------------------===// |
| 804 | // PCHReader Implementation |
| 805 | //===----------------------------------------------------------------------===// |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 806 | |
| 807 | /// \brief Note that we have loaded the declaration with the given |
| 808 | /// Index. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | /// |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 810 | /// This routine notes that this declaration has already been loaded, |
| 811 | /// so that future GetDecl calls will return this declaration rather |
| 812 | /// than trying to load a new declaration. |
| 813 | inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) { |
| 814 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 815 | DeclsLoaded[Index] = D; |
| 816 | } |
| 817 | |
| 818 | |
| 819 | /// \brief Determine whether the consumer will be interested in seeing |
| 820 | /// this declaration (via HandleTopLevelDecl). |
| 821 | /// |
| 822 | /// This routine should return true for anything that might affect |
| 823 | /// code generation, e.g., inline function definitions, Objective-C |
| 824 | /// declarations with metadata, etc. |
| 825 | static bool isConsumerInterestedIn(Decl *D) { |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 826 | if (isa<FileScopeAsmDecl>(D)) |
| 827 | return true; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 828 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) |
| 829 | return Var->isFileVarDecl() && Var->getInit(); |
| 830 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) |
| 831 | return Func->isThisDeclarationADefinition(); |
| 832 | return isa<ObjCProtocolDecl>(D); |
| 833 | } |
| 834 | |
| 835 | /// \brief Read the declaration at the given offset from the PCH file. |
| 836 | Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { |
| 837 | // Keep track of where we are in the stream, then jump back there |
| 838 | // after reading this declaration. |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 839 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 840 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 841 | // Note that we are loading a declaration record. |
| 842 | LoadingTypeOrDecl Loading(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 844 | DeclsCursor.JumpToBit(Offset); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 845 | RecordData Record; |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 846 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 847 | unsigned Idx = 0; |
| 848 | PCHDeclReader Reader(*this, Record, Idx); |
| 849 | |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 850 | Decl *D = 0; |
| 851 | switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 852 | case pch::DECL_ATTR: |
| 853 | case pch::DECL_CONTEXT_LEXICAL: |
| 854 | case pch::DECL_CONTEXT_VISIBLE: |
| 855 | assert(false && "Record cannot be de-serialized with ReadDeclRecord"); |
| 856 | break; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 857 | case pch::DECL_TRANSLATION_UNIT: |
| 858 | assert(Index == 0 && "Translation unit must be at index 0"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 859 | D = Context->getTranslationUnitDecl(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 860 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 861 | case pch::DECL_TYPEDEF: |
John McCall | ba6a9bd | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 862 | D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 863 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 864 | case pch::DECL_ENUM: |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 865 | D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 866 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 867 | case pch::DECL_RECORD: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 868 | D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(), |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 869 | 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 870 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 871 | case pch::DECL_ENUM_CONSTANT: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 872 | D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 873 | 0, llvm::APSInt()); |
| 874 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 875 | case pch::DECL_FUNCTION: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 876 | D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(), |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 877 | QualType(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 878 | break; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 879 | case pch::DECL_LINKAGE_SPEC: |
| 880 | D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(), |
| 881 | (LinkageSpecDecl::LanguageIDs)0, |
| 882 | false); |
| 883 | break; |
| 884 | case pch::DECL_NAMESPACE: |
| 885 | D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0); |
| 886 | break; |
| 887 | case pch::DECL_NAMESPACE_ALIAS: |
| 888 | D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(), |
| 889 | SourceLocation(), 0, SourceRange(), 0, |
| 890 | SourceLocation(), 0); |
| 891 | break; |
| 892 | case pch::DECL_USING: |
| 893 | D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(), |
| 894 | SourceLocation(), 0, DeclarationName(), false); |
| 895 | break; |
| 896 | case pch::DECL_USING_SHADOW: |
| 897 | D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
| 898 | break; |
| 899 | case pch::DECL_USING_DIRECTIVE: |
| 900 | D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(), |
| 901 | SourceLocation(), SourceRange(), 0, |
| 902 | SourceLocation(), 0, 0); |
| 903 | break; |
| 904 | case pch::DECL_UNRESOLVED_USING_VALUE: |
| 905 | D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(), |
| 906 | SourceRange(), 0, SourceLocation(), |
| 907 | DeclarationName()); |
| 908 | break; |
| 909 | case pch::DECL_UNRESOLVED_USING_TYPENAME: |
| 910 | D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(), |
| 911 | SourceLocation(), SourceRange(), |
| 912 | 0, SourceLocation(), |
| 913 | DeclarationName()); |
| 914 | break; |
| 915 | case pch::DECL_CXX_RECORD: |
| 916 | D = CXXRecordDecl::Create(*Context, TagDecl::TK_struct, 0, |
| 917 | SourceLocation(), 0, SourceLocation(), 0); |
| 918 | break; |
| 919 | case pch::DECL_CXX_METHOD: |
| 920 | D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(), |
| 921 | QualType(), 0); |
| 922 | break; |
| 923 | case pch::DECL_CXX_CONSTRUCTOR: |
| 924 | D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell()); |
| 925 | break; |
| 926 | case pch::DECL_CXX_DESTRUCTOR: |
| 927 | D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell()); |
| 928 | break; |
| 929 | case pch::DECL_CXX_CONVERSION: |
| 930 | D = CXXConversionDecl::Create(*Context, Decl::EmptyShell()); |
| 931 | break; |
| 932 | case pch::DECL_FRIEND: |
| 933 | assert(false && "cannot read FriendDecl"); |
| 934 | break; |
| 935 | case pch::DECL_FRIEND_TEMPLATE: |
| 936 | assert(false && "cannot read FriendTemplateDecl"); |
| 937 | break; |
| 938 | case pch::DECL_TEMPLATE: |
| 939 | // FIXME: Should TemplateDecl be ABSTRACT_DECL??? |
| 940 | assert(false && "TemplateDecl should be abstract!"); |
| 941 | break; |
| 942 | case pch::DECL_CLASS_TEMPLATE: |
| 943 | assert(false && "cannot read ClassTemplateDecl"); |
| 944 | break; |
| 945 | case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION: |
| 946 | assert(false && "cannot read ClasstemplateSpecializationDecl"); |
| 947 | break; |
| 948 | case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: |
| 949 | assert(false && "cannot read ClassTemplatePartialSpecializationDecl"); |
| 950 | break; |
| 951 | case pch::DECL_FUNCTION_TEMPLATE: |
| 952 | assert(false && "cannot read FunctionTemplateDecl"); |
| 953 | break; |
| 954 | case pch::DECL_TEMPLATE_TYPE_PARM: |
| 955 | assert(false && "cannot read TemplateTypeParmDecl"); |
| 956 | break; |
| 957 | case pch::DECL_NON_TYPE_TEMPLATE_PARM: |
| 958 | assert(false && "cannot read NonTypeTemplateParmDecl"); |
| 959 | break; |
| 960 | case pch::DECL_TEMPLATE_TEMPLATE_PARM: |
| 961 | assert(false && "cannot read TemplateTemplateParmDecl"); |
| 962 | break; |
| 963 | case pch::DECL_STATIC_ASSERT: |
| 964 | assert(false && "cannot read StaticAssertDecl"); |
| 965 | break; |
| 966 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 967 | case pch::DECL_OBJC_METHOD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 968 | D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(), |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 969 | Selector(), QualType(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 970 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 971 | case pch::DECL_OBJC_INTERFACE: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 972 | D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 973 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 974 | case pch::DECL_OBJC_IVAR: |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 975 | D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 976 | ObjCIvarDecl::None); |
| 977 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 978 | case pch::DECL_OBJC_PROTOCOL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 979 | D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 980 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 981 | case pch::DECL_OBJC_AT_DEFS_FIELD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 982 | D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 983 | QualType(), 0); |
| 984 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 985 | case pch::DECL_OBJC_CLASS: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 986 | D = ObjCClassDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 987 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 988 | case pch::DECL_OBJC_FORWARD_PROTOCOL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 989 | D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 990 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 991 | case pch::DECL_OBJC_CATEGORY: |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 992 | D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), |
| 993 | SourceLocation(), SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 994 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 995 | case pch::DECL_OBJC_CATEGORY_IMPL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 996 | D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 997 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 998 | case pch::DECL_OBJC_IMPLEMENTATION: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 999 | D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1000 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1001 | case pch::DECL_OBJC_COMPATIBLE_ALIAS: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1002 | D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1003 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1004 | case pch::DECL_OBJC_PROPERTY: |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 1005 | D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), |
| 1006 | QualType()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1007 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1008 | case pch::DECL_OBJC_PROPERTY_IMPL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1009 | D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | SourceLocation(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1011 | ObjCPropertyImplDecl::Dynamic, 0); |
| 1012 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1013 | case pch::DECL_FIELD: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0, |
Argyrios Kyrtzidis | a5d8200 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 1015 | false); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1016 | break; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1017 | case pch::DECL_VAR: |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1018 | D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1019 | VarDecl::None, VarDecl::None); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | |
| 1022 | case pch::DECL_IMPLICIT_PARAM: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1023 | D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1024 | break; |
| 1025 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1026 | case pch::DECL_PARM_VAR: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1028 | VarDecl::None, VarDecl::None, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1029 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1030 | case pch::DECL_FILE_SCOPE_ASM: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1031 | D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1032 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1033 | case pch::DECL_BLOCK: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1034 | D = BlockDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1035 | break; |
| 1036 | } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1037 | |
| 1038 | assert(D && "Unknown declaration reading PCH file"); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 1039 | LoadedDecl(Index, D); |
| 1040 | Reader.Visit(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1041 | |
| 1042 | // If this declaration is also a declaration context, get the |
| 1043 | // offsets for its tables of lexical and visible declarations. |
| 1044 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 1045 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
| 1046 | if (Offsets.first || Offsets.second) { |
| 1047 | DC->setHasExternalLexicalStorage(Offsets.first != 0); |
| 1048 | DC->setHasExternalVisibleStorage(Offsets.second != 0); |
| 1049 | DeclContextOffsets[DC] = Offsets; |
| 1050 | } |
| 1051 | } |
| 1052 | assert(Idx == Record.size()); |
| 1053 | |
| 1054 | // If we have deserialized a declaration that has a definition the |
| 1055 | // AST consumer might need to know about, notify the consumer |
| 1056 | // about that definition now or queue it for later. |
| 1057 | if (isConsumerInterestedIn(D)) { |
| 1058 | if (Consumer) { |
| 1059 | DeclGroupRef DG(D); |
| 1060 | Consumer->HandleTopLevelDecl(DG); |
| 1061 | } else { |
| 1062 | InterestingDecls.push_back(D); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | return D; |
| 1067 | } |