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" |
| 20 | #include "clang/AST/Expr.h" |
| 21 | using namespace clang; |
| 22 | |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | // Declaration deserialization |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
| 28 | namespace { |
| 29 | class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> { |
| 30 | PCHReader &Reader; |
| 31 | const PCHReader::RecordData &Record; |
| 32 | unsigned &Idx; |
| 33 | |
| 34 | public: |
| 35 | PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record, |
| 36 | unsigned &Idx) |
| 37 | : Reader(Reader), Record(Record), Idx(Idx) { } |
| 38 | |
| 39 | void VisitDecl(Decl *D); |
| 40 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 41 | void VisitNamedDecl(NamedDecl *ND); |
| 42 | void VisitTypeDecl(TypeDecl *TD); |
| 43 | void VisitTypedefDecl(TypedefDecl *TD); |
| 44 | void VisitTagDecl(TagDecl *TD); |
| 45 | void VisitEnumDecl(EnumDecl *ED); |
| 46 | void VisitRecordDecl(RecordDecl *RD); |
| 47 | void VisitValueDecl(ValueDecl *VD); |
| 48 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
| 49 | void VisitFunctionDecl(FunctionDecl *FD); |
| 50 | void VisitFieldDecl(FieldDecl *FD); |
| 51 | void VisitVarDecl(VarDecl *VD); |
| 52 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); |
| 53 | void VisitParmVarDecl(ParmVarDecl *PD); |
| 54 | void VisitOriginalParmVarDecl(OriginalParmVarDecl *PD); |
| 55 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
| 56 | void VisitBlockDecl(BlockDecl *BD); |
| 57 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
| 58 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 59 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 60 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 61 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 62 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 63 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| 64 | void VisitObjCClassDecl(ObjCClassDecl *D); |
| 65 | void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D); |
| 66 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 67 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 68 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 69 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 70 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 71 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 72 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 73 | }; |
| 74 | } |
| 75 | |
| 76 | void PCHDeclReader::VisitDecl(Decl *D) { |
| 77 | D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 78 | D->setLexicalDeclContext( |
| 79 | cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 80 | D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 81 | D->setInvalidDecl(Record[Idx++]); |
| 82 | if (Record[Idx++]) |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 83 | D->addAttr(Reader.ReadAttributes()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 84 | D->setImplicit(Record[Idx++]); |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 85 | D->setUsed(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 86 | D->setAccess((AccessSpecifier)Record[Idx++]); |
| 87 | } |
| 88 | |
| 89 | void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
| 90 | VisitDecl(TU); |
| 91 | } |
| 92 | |
| 93 | void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) { |
| 94 | VisitDecl(ND); |
| 95 | ND->setDeclName(Reader.ReadDeclarationName(Record, Idx)); |
| 96 | } |
| 97 | |
| 98 | void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) { |
| 99 | VisitNamedDecl(TD); |
| 100 | TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
| 101 | } |
| 102 | |
| 103 | void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
| 104 | // Note that we cannot use VisitTypeDecl here, because we need to |
| 105 | // set the underlying type of the typedef *before* we try to read |
| 106 | // the type associated with the TypedefDecl. |
| 107 | VisitNamedDecl(TD); |
| 108 | TD->setUnderlyingType(Reader.GetType(Record[Idx + 1])); |
| 109 | TD->setTypeForDecl(Reader.GetType(Record[Idx]).getTypePtr()); |
| 110 | Idx += 2; |
| 111 | } |
| 112 | |
| 113 | void PCHDeclReader::VisitTagDecl(TagDecl *TD) { |
| 114 | VisitTypeDecl(TD); |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 115 | TD->setPreviousDeclaration( |
| 116 | cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 117 | TD->setTagKind((TagDecl::TagKind)Record[Idx++]); |
| 118 | TD->setDefinition(Record[Idx++]); |
| 119 | TD->setTypedefForAnonDecl( |
| 120 | cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++]))); |
Argyrios Kyrtzidis | ad93a74 | 2009-07-14 03:18:02 +0000 | [diff] [blame] | 121 | TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 122 | TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) { |
| 126 | VisitTagDecl(ED); |
| 127 | ED->setIntegerType(Reader.GetType(Record[Idx++])); |
Douglas Gregor | 8dbc3c6 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 128 | // FIXME: C++ InstantiatedFrom |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) { |
| 132 | VisitTagDecl(RD); |
| 133 | RD->setHasFlexibleArrayMember(Record[Idx++]); |
| 134 | RD->setAnonymousStructOrUnion(Record[Idx++]); |
Fariborz Jahanian | 643b7df | 2009-07-08 16:37:44 +0000 | [diff] [blame] | 135 | RD->setHasObjectMember(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void PCHDeclReader::VisitValueDecl(ValueDecl *VD) { |
| 139 | VisitNamedDecl(VD); |
| 140 | VD->setType(Reader.GetType(Record[Idx++])); |
| 141 | } |
| 142 | |
| 143 | void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
| 144 | VisitValueDecl(ECD); |
| 145 | if (Record[Idx++]) |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 146 | ECD->setInitExpr(Reader.ReadDeclExpr()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 147 | ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); |
| 148 | } |
| 149 | |
| 150 | void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
| 151 | VisitValueDecl(FD); |
| 152 | if (Record[Idx++]) |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 153 | FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 154 | FD->setPreviousDeclaration( |
| 155 | cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]))); |
| 156 | FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]); |
| 157 | FD->setInline(Record[Idx++]); |
| 158 | FD->setC99InlineDefinition(Record[Idx++]); |
Anders Carlsson | 77b7f1d | 2009-05-14 22:15:41 +0000 | [diff] [blame] | 159 | FD->setVirtualAsWritten(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 160 | FD->setPure(Record[Idx++]); |
Anders Carlsson | a75e853 | 2009-05-14 21:46:00 +0000 | [diff] [blame] | 161 | FD->setHasInheritedPrototype(Record[Idx++]); |
| 162 | FD->setHasWrittenPrototype(Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 163 | FD->setDeleted(Record[Idx++]); |
| 164 | FD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Argyrios Kyrtzidis | 8cff90e | 2009-06-20 08:09:34 +0000 | [diff] [blame] | 165 | FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 166 | // FIXME: C++ TemplateOrInstantiation |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 167 | unsigned NumParams = Record[Idx++]; |
| 168 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 169 | Params.reserve(NumParams); |
| 170 | for (unsigned I = 0; I != NumParams; ++I) |
| 171 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 172 | FD->setParams(*Reader.getContext(), Params.data(), NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
| 176 | VisitNamedDecl(MD); |
| 177 | if (Record[Idx++]) { |
| 178 | // In practice, this won't be executed (since method definitions |
| 179 | // don't occur in header files). |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 180 | MD->setBody(Reader.ReadDeclStmt()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 181 | MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 182 | MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 183 | } |
| 184 | MD->setInstanceMethod(Record[Idx++]); |
| 185 | MD->setVariadic(Record[Idx++]); |
| 186 | MD->setSynthesized(Record[Idx++]); |
| 187 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); |
| 188 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
| 189 | MD->setResultType(Reader.GetType(Record[Idx++])); |
| 190 | MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 191 | unsigned NumParams = Record[Idx++]; |
| 192 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 193 | Params.reserve(NumParams); |
| 194 | for (unsigned I = 0; I != NumParams; ++I) |
| 195 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 196 | MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
| 200 | VisitNamedDecl(CD); |
| 201 | CD->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 202 | } |
| 203 | |
| 204 | void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
| 205 | VisitObjCContainerDecl(ID); |
| 206 | ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
| 207 | ID->setSuperClass(cast_or_null<ObjCInterfaceDecl> |
| 208 | (Reader.GetDecl(Record[Idx++]))); |
| 209 | unsigned NumProtocols = Record[Idx++]; |
| 210 | llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 211 | Protocols.reserve(NumProtocols); |
| 212 | for (unsigned I = 0; I != NumProtocols; ++I) |
| 213 | Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 214 | ID->setProtocolList(Protocols.data(), NumProtocols, *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 215 | unsigned NumIvars = Record[Idx++]; |
| 216 | llvm::SmallVector<ObjCIvarDecl *, 16> IVars; |
| 217 | IVars.reserve(NumIvars); |
| 218 | for (unsigned I = 0; I != NumIvars; ++I) |
| 219 | IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 220 | ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 221 | ID->setCategoryList( |
| 222 | cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
| 223 | ID->setForwardDecl(Record[Idx++]); |
| 224 | ID->setImplicitInterfaceDecl(Record[Idx++]); |
| 225 | ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 226 | ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Argyrios Kyrtzidis | c999f1f | 2009-07-18 00:33:23 +0000 | [diff] [blame] | 227 | ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
| 231 | VisitFieldDecl(IVD); |
| 232 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); |
| 233 | } |
| 234 | |
| 235 | void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 236 | VisitObjCContainerDecl(PD); |
| 237 | PD->setForwardDecl(Record[Idx++]); |
| 238 | PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 239 | unsigned NumProtoRefs = Record[Idx++]; |
| 240 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 241 | ProtoRefs.reserve(NumProtoRefs); |
| 242 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 243 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 244 | PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
| 248 | VisitFieldDecl(FD); |
| 249 | } |
| 250 | |
| 251 | void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) { |
| 252 | VisitDecl(CD); |
| 253 | unsigned NumClassRefs = Record[Idx++]; |
| 254 | llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs; |
| 255 | ClassRefs.reserve(NumClassRefs); |
| 256 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 257 | ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 258 | CD->setClassList(*Reader.getContext(), ClassRefs.data(), NumClassRefs); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) { |
| 262 | VisitDecl(FPD); |
| 263 | unsigned NumProtoRefs = Record[Idx++]; |
| 264 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 265 | ProtoRefs.reserve(NumProtoRefs); |
| 266 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 267 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 268 | FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
| 272 | VisitObjCContainerDecl(CD); |
| 273 | CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 274 | unsigned NumProtoRefs = Record[Idx++]; |
| 275 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 276 | ProtoRefs.reserve(NumProtoRefs); |
| 277 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 278 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Ted Kremenek | 66ef111 | 2009-05-22 22:34:23 +0000 | [diff] [blame] | 279 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, *Reader.getContext()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 280 | CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
| 281 | CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 282 | } |
| 283 | |
| 284 | void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
| 285 | VisitNamedDecl(CAD); |
| 286 | CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 287 | } |
| 288 | |
| 289 | void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 290 | VisitNamedDecl(D); |
| 291 | D->setType(Reader.GetType(Record[Idx++])); |
| 292 | // FIXME: stable encoding |
| 293 | D->setPropertyAttributes( |
| 294 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
| 295 | // FIXME: stable encoding |
| 296 | D->setPropertyImplementation( |
| 297 | (ObjCPropertyDecl::PropertyControl)Record[Idx++]); |
| 298 | D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 299 | D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 300 | D->setGetterMethodDecl( |
| 301 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 302 | D->setSetterMethodDecl( |
| 303 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 304 | D->setPropertyIvarDecl( |
| 305 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 306 | } |
| 307 | |
| 308 | void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | aecae62 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 309 | VisitObjCContainerDecl(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 310 | D->setClassInterface( |
| 311 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 315 | VisitObjCImplDecl(D); |
| 316 | D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx)); |
| 317 | } |
| 318 | |
| 319 | void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 320 | VisitObjCImplDecl(D); |
| 321 | D->setSuperClass( |
| 322 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 323 | } |
| 324 | |
| 325 | |
| 326 | void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 327 | VisitDecl(D); |
| 328 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 329 | D->setPropertyDecl( |
| 330 | cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 331 | D->setPropertyIvarDecl( |
| 332 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 333 | } |
| 334 | |
| 335 | void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) { |
| 336 | VisitValueDecl(FD); |
| 337 | FD->setMutable(Record[Idx++]); |
Steve Naroff | ea218b8 | 2009-07-14 14:58:18 +0000 | [diff] [blame] | 338 | FD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 339 | if (Record[Idx++]) |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 340 | FD->setBitWidth(Reader.ReadDeclExpr()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | void PCHDeclReader::VisitVarDecl(VarDecl *VD) { |
| 344 | VisitValueDecl(VD); |
| 345 | VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]); |
| 346 | VD->setThreadSpecified(Record[Idx++]); |
| 347 | VD->setCXXDirectInitializer(Record[Idx++]); |
| 348 | VD->setDeclaredInCondition(Record[Idx++]); |
| 349 | VD->setPreviousDeclaration( |
| 350 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 351 | VD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 352 | if (Record[Idx++]) |
Douglas Gregor | 78d1583 | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 353 | VD->setInit(*Reader.getContext(), Reader.ReadDeclExpr()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
| 357 | VisitVarDecl(PD); |
| 358 | } |
| 359 | |
| 360 | void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
| 361 | VisitVarDecl(PD); |
| 362 | PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) { |
| 366 | VisitParmVarDecl(PD); |
| 367 | PD->setOriginalType(Reader.GetType(Record[Idx++])); |
| 368 | } |
| 369 | |
| 370 | void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
| 371 | VisitDecl(AD); |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 372 | AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr())); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) { |
| 376 | VisitDecl(BD); |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 377 | BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt())); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 378 | unsigned NumParams = Record[Idx++]; |
| 379 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 380 | Params.reserve(NumParams); |
| 381 | for (unsigned I = 0; I != NumParams; ++I) |
| 382 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 383 | BD->setParams(*Reader.getContext(), Params.data(), NumParams); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | std::pair<uint64_t, uint64_t> |
| 387 | PCHDeclReader::VisitDeclContext(DeclContext *DC) { |
| 388 | uint64_t LexicalOffset = Record[Idx++]; |
| 389 | uint64_t VisibleOffset = Record[Idx++]; |
| 390 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 391 | } |
| 392 | |
| 393 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 394 | // Attribute Reading |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 395 | //===----------------------------------------------------------------------===// |
| 396 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 397 | /// \brief Reads attributes from the current stream position. |
| 398 | Attr *PCHReader::ReadAttributes() { |
| 399 | unsigned Code = DeclsCursor.ReadCode(); |
| 400 | assert(Code == llvm::bitc::UNABBREV_RECORD && |
| 401 | "Expected unabbreviated record"); (void)Code; |
| 402 | |
| 403 | RecordData Record; |
| 404 | unsigned Idx = 0; |
| 405 | unsigned RecCode = DeclsCursor.ReadRecord(Code, Record); |
| 406 | assert(RecCode == pch::DECL_ATTR && "Expected attribute record"); |
| 407 | (void)RecCode; |
| 408 | |
| 409 | #define SIMPLE_ATTR(Name) \ |
| 410 | case Attr::Name: \ |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 411 | New = ::new (*Context) Name##Attr(); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 412 | break |
| 413 | |
| 414 | #define STRING_ATTR(Name) \ |
| 415 | case Attr::Name: \ |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 416 | New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 417 | break |
| 418 | |
| 419 | #define UNSIGNED_ATTR(Name) \ |
| 420 | case Attr::Name: \ |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 421 | New = ::new (*Context) Name##Attr(Record[Idx++]); \ |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 422 | break |
| 423 | |
| 424 | Attr *Attrs = 0; |
| 425 | while (Idx < Record.size()) { |
| 426 | Attr *New = 0; |
| 427 | Attr::Kind Kind = (Attr::Kind)Record[Idx++]; |
| 428 | bool IsInherited = Record[Idx++]; |
| 429 | |
| 430 | switch (Kind) { |
| 431 | STRING_ATTR(Alias); |
| 432 | UNSIGNED_ATTR(Aligned); |
| 433 | SIMPLE_ATTR(AlwaysInline); |
| 434 | SIMPLE_ATTR(AnalyzerNoReturn); |
| 435 | STRING_ATTR(Annotate); |
| 436 | STRING_ATTR(AsmLabel); |
| 437 | |
| 438 | case Attr::Blocks: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 439 | New = ::new (*Context) BlocksAttr( |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 440 | (BlocksAttr::BlocksAttrTypes)Record[Idx++]); |
| 441 | break; |
| 442 | |
| 443 | case Attr::Cleanup: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 444 | New = ::new (*Context) CleanupAttr( |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 445 | cast<FunctionDecl>(GetDecl(Record[Idx++]))); |
| 446 | break; |
| 447 | |
| 448 | SIMPLE_ATTR(Const); |
| 449 | UNSIGNED_ATTR(Constructor); |
| 450 | SIMPLE_ATTR(DLLExport); |
| 451 | SIMPLE_ATTR(DLLImport); |
| 452 | SIMPLE_ATTR(Deprecated); |
| 453 | UNSIGNED_ATTR(Destructor); |
| 454 | SIMPLE_ATTR(FastCall); |
| 455 | |
| 456 | case Attr::Format: { |
| 457 | std::string Type = ReadString(Record, Idx); |
| 458 | unsigned FormatIdx = Record[Idx++]; |
| 459 | unsigned FirstArg = Record[Idx++]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 460 | New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 461 | break; |
| 462 | } |
Fariborz Jahanian | 5b53005 | 2009-05-13 18:09:35 +0000 | [diff] [blame] | 463 | |
Fariborz Jahanian | 5b16092 | 2009-05-20 17:41:43 +0000 | [diff] [blame] | 464 | case Attr::FormatArg: { |
| 465 | unsigned FormatIdx = Record[Idx++]; |
| 466 | New = ::new (*Context) FormatArgAttr(FormatIdx); |
| 467 | break; |
| 468 | } |
| 469 | |
Fariborz Jahanian | 5b53005 | 2009-05-13 18:09:35 +0000 | [diff] [blame] | 470 | case Attr::Sentinel: { |
| 471 | int sentinel = Record[Idx++]; |
| 472 | int nullPos = Record[Idx++]; |
| 473 | New = ::new (*Context) SentinelAttr(sentinel, nullPos); |
| 474 | break; |
| 475 | } |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 476 | |
| 477 | SIMPLE_ATTR(GNUInline); |
| 478 | |
| 479 | case Attr::IBOutletKind: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 480 | New = ::new (*Context) IBOutletAttr(); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 481 | break; |
| 482 | |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame^] | 483 | SIMPLE_ATTR(Malloc); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 484 | SIMPLE_ATTR(NoReturn); |
| 485 | SIMPLE_ATTR(NoThrow); |
| 486 | SIMPLE_ATTR(Nodebug); |
| 487 | SIMPLE_ATTR(Noinline); |
| 488 | |
| 489 | case Attr::NonNull: { |
| 490 | unsigned Size = Record[Idx++]; |
| 491 | llvm::SmallVector<unsigned, 16> ArgNums; |
| 492 | ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size); |
| 493 | Idx += Size; |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 494 | New = ::new (*Context) NonNullAttr(ArgNums.data(), Size); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 495 | break; |
| 496 | } |
Nate Begeman | 6f3d838 | 2009-06-26 06:32:41 +0000 | [diff] [blame] | 497 | |
| 498 | case Attr::ReqdWorkGroupSize: { |
| 499 | unsigned X = Record[Idx++]; |
| 500 | unsigned Y = Record[Idx++]; |
| 501 | unsigned Z = Record[Idx++]; |
| 502 | New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z); |
| 503 | break; |
| 504 | } |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 505 | |
| 506 | SIMPLE_ATTR(ObjCException); |
| 507 | SIMPLE_ATTR(ObjCNSObject); |
Ted Kremenek | b71368d | 2009-05-09 02:44:38 +0000 | [diff] [blame] | 508 | SIMPLE_ATTR(CFReturnsRetained); |
| 509 | SIMPLE_ATTR(NSReturnsRetained); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 510 | SIMPLE_ATTR(Overloadable); |
Anders Carlsson | a860e75 | 2009-08-08 18:23:56 +0000 | [diff] [blame] | 511 | SIMPLE_ATTR(Packed); |
| 512 | UNSIGNED_ATTR(PragmaPack); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 513 | SIMPLE_ATTR(Pure); |
| 514 | UNSIGNED_ATTR(Regparm); |
| 515 | STRING_ATTR(Section); |
| 516 | SIMPLE_ATTR(StdCall); |
| 517 | SIMPLE_ATTR(TransparentUnion); |
| 518 | SIMPLE_ATTR(Unavailable); |
| 519 | SIMPLE_ATTR(Unused); |
| 520 | SIMPLE_ATTR(Used); |
| 521 | |
| 522 | case Attr::Visibility: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 523 | New = ::new (*Context) VisibilityAttr( |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 524 | (VisibilityAttr::VisibilityTypes)Record[Idx++]); |
| 525 | break; |
| 526 | |
| 527 | SIMPLE_ATTR(WarnUnusedResult); |
| 528 | SIMPLE_ATTR(Weak); |
| 529 | SIMPLE_ATTR(WeakImport); |
| 530 | } |
| 531 | |
| 532 | assert(New && "Unable to decode attribute?"); |
| 533 | New->setInherited(IsInherited); |
| 534 | New->setNext(Attrs); |
| 535 | Attrs = New; |
| 536 | } |
| 537 | #undef UNSIGNED_ATTR |
| 538 | #undef STRING_ATTR |
| 539 | #undef SIMPLE_ATTR |
| 540 | |
| 541 | // The list of attributes was built backwards. Reverse the list |
| 542 | // before returning it. |
| 543 | Attr *PrevAttr = 0, *NextAttr = 0; |
| 544 | while (Attrs) { |
| 545 | NextAttr = Attrs->getNext(); |
| 546 | Attrs->setNext(PrevAttr); |
| 547 | PrevAttr = Attrs; |
| 548 | Attrs = NextAttr; |
| 549 | } |
| 550 | |
| 551 | return PrevAttr; |
| 552 | } |
| 553 | |
| 554 | //===----------------------------------------------------------------------===// |
| 555 | // PCHReader Implementation |
| 556 | //===----------------------------------------------------------------------===// |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 557 | |
| 558 | /// \brief Note that we have loaded the declaration with the given |
| 559 | /// Index. |
| 560 | /// |
| 561 | /// This routine notes that this declaration has already been loaded, |
| 562 | /// so that future GetDecl calls will return this declaration rather |
| 563 | /// than trying to load a new declaration. |
| 564 | inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) { |
| 565 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 566 | DeclsLoaded[Index] = D; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | /// \brief Determine whether the consumer will be interested in seeing |
| 571 | /// this declaration (via HandleTopLevelDecl). |
| 572 | /// |
| 573 | /// This routine should return true for anything that might affect |
| 574 | /// code generation, e.g., inline function definitions, Objective-C |
| 575 | /// declarations with metadata, etc. |
| 576 | static bool isConsumerInterestedIn(Decl *D) { |
| 577 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) |
| 578 | return Var->isFileVarDecl() && Var->getInit(); |
| 579 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) |
| 580 | return Func->isThisDeclarationADefinition(); |
| 581 | return isa<ObjCProtocolDecl>(D); |
| 582 | } |
| 583 | |
| 584 | /// \brief Read the declaration at the given offset from the PCH file. |
| 585 | Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { |
| 586 | // Keep track of where we are in the stream, then jump back there |
| 587 | // after reading this declaration. |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 588 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 589 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 590 | // Note that we are loading a declaration record. |
| 591 | LoadingTypeOrDecl Loading(*this); |
| 592 | |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 593 | DeclsCursor.JumpToBit(Offset); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 594 | RecordData Record; |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 595 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 596 | unsigned Idx = 0; |
| 597 | PCHDeclReader Reader(*this, Record, Idx); |
| 598 | |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 599 | Decl *D = 0; |
| 600 | switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) { |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 601 | case pch::DECL_ATTR: |
| 602 | case pch::DECL_CONTEXT_LEXICAL: |
| 603 | case pch::DECL_CONTEXT_VISIBLE: |
| 604 | assert(false && "Record cannot be de-serialized with ReadDeclRecord"); |
| 605 | break; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 606 | case pch::DECL_TRANSLATION_UNIT: |
| 607 | assert(Index == 0 && "Translation unit must be at index 0"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 608 | D = Context->getTranslationUnitDecl(); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 609 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 610 | case pch::DECL_TYPEDEF: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 611 | D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, QualType()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 612 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 613 | case pch::DECL_ENUM: |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 614 | D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 615 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 616 | case pch::DECL_RECORD: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 617 | D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(), |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 618 | 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 619 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 620 | case pch::DECL_ENUM_CONSTANT: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 621 | D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 622 | 0, llvm::APSInt()); |
| 623 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 624 | case pch::DECL_FUNCTION: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 625 | D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 626 | QualType()); |
| 627 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 628 | case pch::DECL_OBJC_METHOD: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 629 | D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 630 | Selector(), QualType(), 0); |
| 631 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 632 | case pch::DECL_OBJC_INTERFACE: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 633 | D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 634 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 635 | case pch::DECL_OBJC_IVAR: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 636 | D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 637 | ObjCIvarDecl::None); |
| 638 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 639 | case pch::DECL_OBJC_PROTOCOL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 640 | D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 641 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 642 | case pch::DECL_OBJC_AT_DEFS_FIELD: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 643 | D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0, |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 644 | QualType(), 0); |
| 645 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 646 | case pch::DECL_OBJC_CLASS: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 647 | D = ObjCClassDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 648 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 649 | case pch::DECL_OBJC_FORWARD_PROTOCOL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 650 | D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 651 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 652 | case pch::DECL_OBJC_CATEGORY: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 653 | D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 654 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 655 | case pch::DECL_OBJC_CATEGORY_IMPL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 656 | D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 657 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 658 | case pch::DECL_OBJC_IMPLEMENTATION: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 659 | D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 660 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 661 | case pch::DECL_OBJC_COMPATIBLE_ALIAS: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 662 | D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 663 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 664 | case pch::DECL_OBJC_PROPERTY: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 665 | D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 666 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 667 | case pch::DECL_OBJC_PROPERTY_IMPL: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 668 | D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 669 | SourceLocation(), 0, |
| 670 | ObjCPropertyImplDecl::Dynamic, 0); |
| 671 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 672 | case pch::DECL_FIELD: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 673 | D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, |
Steve Naroff | ea218b8 | 2009-07-14 14:58:18 +0000 | [diff] [blame] | 674 | false, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 675 | break; |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 676 | case pch::DECL_VAR: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 677 | D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 678 | VarDecl::None, SourceLocation()); |
| 679 | break; |
| 680 | |
| 681 | case pch::DECL_IMPLICIT_PARAM: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 682 | D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 683 | break; |
| 684 | |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 685 | case pch::DECL_PARM_VAR: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 686 | D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 687 | VarDecl::None, 0); |
| 688 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 689 | case pch::DECL_ORIGINAL_PARM_VAR: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 690 | D = OriginalParmVarDecl::Create(*Context, 0, SourceLocation(), 0, |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 691 | QualType(), QualType(), VarDecl::None, 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 692 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 693 | case pch::DECL_FILE_SCOPE_ASM: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 694 | D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 695 | break; |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 696 | case pch::DECL_BLOCK: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 697 | D = BlockDecl::Create(*Context, 0, SourceLocation()); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 698 | break; |
| 699 | } |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 700 | |
| 701 | assert(D && "Unknown declaration reading PCH file"); |
Chris Lattner | 4e3fcc8 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 702 | LoadedDecl(Index, D); |
| 703 | Reader.Visit(D); |
Chris Lattner | 698f925 | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 704 | |
| 705 | // If this declaration is also a declaration context, get the |
| 706 | // offsets for its tables of lexical and visible declarations. |
| 707 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 708 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
| 709 | if (Offsets.first || Offsets.second) { |
| 710 | DC->setHasExternalLexicalStorage(Offsets.first != 0); |
| 711 | DC->setHasExternalVisibleStorage(Offsets.second != 0); |
| 712 | DeclContextOffsets[DC] = Offsets; |
| 713 | } |
| 714 | } |
| 715 | assert(Idx == Record.size()); |
| 716 | |
| 717 | // If we have deserialized a declaration that has a definition the |
| 718 | // AST consumer might need to know about, notify the consumer |
| 719 | // about that definition now or queue it for later. |
| 720 | if (isConsumerInterestedIn(D)) { |
| 721 | if (Consumer) { |
| 722 | DeclGroupRef DG(D); |
| 723 | Consumer->HandleTopLevelDecl(DG); |
| 724 | } else { |
| 725 | InterestingDecls.push_back(D); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | return D; |
| 730 | } |
| 731 | |