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