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