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