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