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