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