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