Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1 | //===--- PCHReader.cpp - Precompiled Headers Reader -------------*- 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 defines the PCHReader class, which reads a precompiled header. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #include "clang/Frontend/PCHReader.h" |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/FrontendDiagnostic.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 15 | #include "../Sema/Sema.h" // FIXME: move Sema headers elsewhere |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/AST/Decl.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclGroup.h" |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclVisitor.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
| 22 | #include "clang/AST/StmtVisitor.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 23 | #include "clang/AST/Type.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 24 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 25 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 26 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 27 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 28 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 29 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 30 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 31 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 32 | #include "llvm/Bitcode/BitstreamReader.h" |
| 33 | #include "llvm/Support/Compiler.h" |
| 34 | #include "llvm/Support/MemoryBuffer.h" |
| 35 | #include <algorithm> |
| 36 | #include <cstdio> |
| 37 | |
| 38 | using namespace clang; |
| 39 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 40 | namespace { |
| 41 | /// \brief Helper class that saves the current stream position and |
| 42 | /// then restores it when destroyed. |
| 43 | struct VISIBILITY_HIDDEN SavedStreamPosition { |
| 44 | explicit SavedStreamPosition(llvm::BitstreamReader &Stream) |
| 45 | : Stream(Stream), Offset(Stream.GetCurrentBitNo()) { } |
| 46 | |
| 47 | ~SavedStreamPosition() { |
| 48 | Stream.JumpToBit(Offset); |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | llvm::BitstreamReader &Stream; |
| 53 | uint64_t Offset; |
| 54 | }; |
| 55 | } |
| 56 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 57 | //===----------------------------------------------------------------------===// |
| 58 | // Declaration deserialization |
| 59 | //===----------------------------------------------------------------------===// |
| 60 | namespace { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 61 | class VISIBILITY_HIDDEN PCHDeclReader |
| 62 | : public DeclVisitor<PCHDeclReader, void> { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 63 | PCHReader &Reader; |
| 64 | const PCHReader::RecordData &Record; |
| 65 | unsigned &Idx; |
| 66 | |
| 67 | public: |
| 68 | PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record, |
| 69 | unsigned &Idx) |
| 70 | : Reader(Reader), Record(Record), Idx(Idx) { } |
| 71 | |
| 72 | void VisitDecl(Decl *D); |
| 73 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 74 | void VisitNamedDecl(NamedDecl *ND); |
| 75 | void VisitTypeDecl(TypeDecl *TD); |
| 76 | void VisitTypedefDecl(TypedefDecl *TD); |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 77 | void VisitTagDecl(TagDecl *TD); |
| 78 | void VisitEnumDecl(EnumDecl *ED); |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 79 | void VisitRecordDecl(RecordDecl *RD); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 80 | void VisitValueDecl(ValueDecl *VD); |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 81 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 82 | void VisitFunctionDecl(FunctionDecl *FD); |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 83 | void VisitFieldDecl(FieldDecl *FD); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 84 | void VisitVarDecl(VarDecl *VD); |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 85 | void VisitParmVarDecl(ParmVarDecl *PD); |
| 86 | void VisitOriginalParmVarDecl(OriginalParmVarDecl *PD); |
Douglas Gregor | 1028bc6 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 87 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
| 88 | void VisitBlockDecl(BlockDecl *BD); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 89 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 90 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
Steve Naroff | 33feeb0 | 2009-04-20 20:09:33 +0000 | [diff] [blame] | 91 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 92 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 93 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 94 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 95 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
| 96 | void VisitObjCClassDecl(ObjCClassDecl *D); |
| 97 | void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D); |
| 98 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 99 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 100 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 101 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 102 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 103 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 104 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 105 | }; |
| 106 | } |
| 107 | |
| 108 | void PCHDeclReader::VisitDecl(Decl *D) { |
| 109 | D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 110 | D->setLexicalDeclContext( |
| 111 | cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 112 | D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 113 | D->setInvalidDecl(Record[Idx++]); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 114 | if (Record[Idx++]) |
| 115 | D->addAttr(Reader.ReadAttributes()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 116 | D->setImplicit(Record[Idx++]); |
| 117 | D->setAccess((AccessSpecifier)Record[Idx++]); |
| 118 | } |
| 119 | |
| 120 | void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
| 121 | VisitDecl(TU); |
| 122 | } |
| 123 | |
| 124 | void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) { |
| 125 | VisitDecl(ND); |
| 126 | ND->setDeclName(Reader.ReadDeclarationName(Record, Idx)); |
| 127 | } |
| 128 | |
| 129 | void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) { |
| 130 | VisitNamedDecl(TD); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 131 | TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
| 132 | } |
| 133 | |
| 134 | void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 135 | // Note that we cannot use VisitTypeDecl here, because we need to |
| 136 | // set the underlying type of the typedef *before* we try to read |
| 137 | // the type associated with the TypedefDecl. |
| 138 | VisitNamedDecl(TD); |
| 139 | TD->setUnderlyingType(Reader.GetType(Record[Idx + 1])); |
| 140 | TD->setTypeForDecl(Reader.GetType(Record[Idx]).getTypePtr()); |
| 141 | Idx += 2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 144 | void PCHDeclReader::VisitTagDecl(TagDecl *TD) { |
| 145 | VisitTypeDecl(TD); |
| 146 | TD->setTagKind((TagDecl::TagKind)Record[Idx++]); |
| 147 | TD->setDefinition(Record[Idx++]); |
| 148 | TD->setTypedefForAnonDecl( |
| 149 | cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++]))); |
| 150 | } |
| 151 | |
| 152 | void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) { |
| 153 | VisitTagDecl(ED); |
| 154 | ED->setIntegerType(Reader.GetType(Record[Idx++])); |
| 155 | } |
| 156 | |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 157 | void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) { |
| 158 | VisitTagDecl(RD); |
| 159 | RD->setHasFlexibleArrayMember(Record[Idx++]); |
| 160 | RD->setAnonymousStructOrUnion(Record[Idx++]); |
| 161 | } |
| 162 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 163 | void PCHDeclReader::VisitValueDecl(ValueDecl *VD) { |
| 164 | VisitNamedDecl(VD); |
| 165 | VD->setType(Reader.GetType(Record[Idx++])); |
| 166 | } |
| 167 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 168 | void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
| 169 | VisitValueDecl(ECD); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 170 | if (Record[Idx++]) |
| 171 | ECD->setInitExpr(Reader.ReadExpr()); |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 172 | ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); |
| 173 | } |
| 174 | |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 175 | void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
| 176 | VisitValueDecl(FD); |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 177 | if (Record[Idx++]) |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 178 | FD->setLazyBody(Reader.getStream().GetCurrentBitNo()); |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 179 | FD->setPreviousDeclaration( |
| 180 | cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]))); |
| 181 | FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]); |
| 182 | FD->setInline(Record[Idx++]); |
Douglas Gregor | b3efa98 | 2009-04-23 18:22:55 +0000 | [diff] [blame] | 183 | FD->setC99InlineDefinition(Record[Idx++]); |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 184 | FD->setVirtual(Record[Idx++]); |
| 185 | FD->setPure(Record[Idx++]); |
| 186 | FD->setInheritedPrototype(Record[Idx++]); |
| 187 | FD->setHasPrototype(Record[Idx++]); |
| 188 | FD->setDeleted(Record[Idx++]); |
| 189 | FD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 190 | unsigned NumParams = Record[Idx++]; |
| 191 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 192 | Params.reserve(NumParams); |
| 193 | for (unsigned I = 0; I != NumParams; ++I) |
| 194 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 195 | FD->setParams(Reader.getContext(), &Params[0], NumParams); |
| 196 | } |
| 197 | |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 198 | void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
| 199 | VisitNamedDecl(MD); |
| 200 | if (Record[Idx++]) { |
| 201 | // In practice, this won't be executed (since method definitions |
| 202 | // don't occur in header files). |
| 203 | MD->setBody(cast<CompoundStmt>(Reader.GetStmt(Record[Idx++]))); |
| 204 | MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 205 | MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 206 | } |
| 207 | MD->setInstanceMethod(Record[Idx++]); |
| 208 | MD->setVariadic(Record[Idx++]); |
| 209 | MD->setSynthesized(Record[Idx++]); |
| 210 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); |
| 211 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
| 212 | MD->setResultType(Reader.GetType(Record[Idx++])); |
| 213 | MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 214 | unsigned NumParams = Record[Idx++]; |
| 215 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 216 | Params.reserve(NumParams); |
| 217 | for (unsigned I = 0; I != NumParams; ++I) |
| 218 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 219 | MD->setMethodParams(Reader.getContext(), &Params[0], NumParams); |
| 220 | } |
| 221 | |
Steve Naroff | 33feeb0 | 2009-04-20 20:09:33 +0000 | [diff] [blame] | 222 | void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
| 223 | VisitNamedDecl(CD); |
| 224 | CD->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 225 | } |
| 226 | |
| 227 | void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
| 228 | VisitObjCContainerDecl(ID); |
| 229 | ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 230 | ID->setSuperClass(cast_or_null<ObjCInterfaceDecl> |
| 231 | (Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | 291be39 | 2009-04-23 03:59:07 +0000 | [diff] [blame] | 232 | unsigned NumProtocols = Record[Idx++]; |
| 233 | llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 234 | Protocols.reserve(NumProtocols); |
| 235 | for (unsigned I = 0; I != NumProtocols; ++I) |
| 236 | Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
Douglas Gregor | d5e662d | 2009-04-24 22:01:00 +0000 | [diff] [blame] | 237 | ID->setProtocolList(&Protocols[0], NumProtocols, Reader.getContext()); |
Steve Naroff | 33feeb0 | 2009-04-20 20:09:33 +0000 | [diff] [blame] | 238 | unsigned NumIvars = Record[Idx++]; |
| 239 | llvm::SmallVector<ObjCIvarDecl *, 16> IVars; |
| 240 | IVars.reserve(NumIvars); |
| 241 | for (unsigned I = 0; I != NumIvars; ++I) |
| 242 | IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 243 | ID->setIVarList(&IVars[0], NumIvars, Reader.getContext()); |
Douglas Gregor | 133f482 | 2009-04-23 22:34:55 +0000 | [diff] [blame] | 244 | ID->setCategoryList( |
| 245 | cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
Steve Naroff | 33feeb0 | 2009-04-20 20:09:33 +0000 | [diff] [blame] | 246 | ID->setForwardDecl(Record[Idx++]); |
| 247 | ID->setImplicitInterfaceDecl(Record[Idx++]); |
| 248 | ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 249 | ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 250 | ID->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Steve Naroff | 33feeb0 | 2009-04-20 20:09:33 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
| 254 | VisitFieldDecl(IVD); |
| 255 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); |
| 256 | } |
| 257 | |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 258 | void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 259 | VisitObjCContainerDecl(PD); |
| 260 | PD->setForwardDecl(Record[Idx++]); |
| 261 | PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 262 | unsigned NumProtoRefs = Record[Idx++]; |
| 263 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 264 | ProtoRefs.reserve(NumProtoRefs); |
| 265 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 266 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
| 267 | PD->setProtocolList(&ProtoRefs[0], NumProtoRefs, Reader.getContext()); |
| 268 | } |
| 269 | |
| 270 | void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
| 271 | VisitFieldDecl(FD); |
| 272 | } |
| 273 | |
| 274 | void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) { |
| 275 | VisitDecl(CD); |
| 276 | unsigned NumClassRefs = Record[Idx++]; |
| 277 | llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs; |
| 278 | ClassRefs.reserve(NumClassRefs); |
| 279 | for (unsigned I = 0; I != NumClassRefs; ++I) |
| 280 | ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 281 | CD->setClassList(Reader.getContext(), &ClassRefs[0], NumClassRefs); |
| 282 | } |
| 283 | |
| 284 | void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) { |
| 285 | VisitDecl(FPD); |
| 286 | unsigned NumProtoRefs = Record[Idx++]; |
| 287 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 288 | ProtoRefs.reserve(NumProtoRefs); |
| 289 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 290 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
| 291 | FPD->setProtocolList(&ProtoRefs[0], NumProtoRefs, Reader.getContext()); |
| 292 | } |
| 293 | |
| 294 | void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
| 295 | VisitObjCContainerDecl(CD); |
| 296 | CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 297 | unsigned NumProtoRefs = Record[Idx++]; |
| 298 | llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 299 | ProtoRefs.reserve(NumProtoRefs); |
| 300 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
| 301 | ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
| 302 | CD->setProtocolList(&ProtoRefs[0], NumProtoRefs, Reader.getContext()); |
Steve Naroff | 0777260 | 2009-04-24 16:59:10 +0000 | [diff] [blame] | 303 | CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++]))); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 304 | CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 305 | } |
| 306 | |
| 307 | void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
| 308 | VisitNamedDecl(CAD); |
| 309 | CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 310 | } |
| 311 | |
| 312 | void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 313 | VisitNamedDecl(D); |
Douglas Gregor | 70e5a14 | 2009-04-22 23:20:34 +0000 | [diff] [blame] | 314 | D->setType(Reader.GetType(Record[Idx++])); |
| 315 | // FIXME: stable encoding |
| 316 | D->setPropertyAttributes( |
| 317 | (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); |
| 318 | // FIXME: stable encoding |
| 319 | D->setPropertyImplementation( |
| 320 | (ObjCPropertyDecl::PropertyControl)Record[Idx++]); |
| 321 | D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 322 | D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector()); |
| 323 | D->setGetterMethodDecl( |
| 324 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 325 | D->setSetterMethodDecl( |
| 326 | cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 327 | D->setPropertyIvarDecl( |
| 328 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 332 | VisitNamedDecl(D); |
Douglas Gregor | 2c2d43c | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 333 | D->setClassInterface( |
| 334 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 335 | D->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 339 | VisitObjCImplDecl(D); |
Douglas Gregor | 10b0e1f | 2009-04-23 02:53:57 +0000 | [diff] [blame] | 340 | D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx)); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 344 | VisitObjCImplDecl(D); |
Douglas Gregor | 8f36aba | 2009-04-23 03:23:08 +0000 | [diff] [blame] | 345 | D->setSuperClass( |
| 346 | cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | |
| 350 | void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 351 | VisitDecl(D); |
Douglas Gregor | 8818c4f | 2009-04-23 03:43:53 +0000 | [diff] [blame] | 352 | D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 353 | D->setPropertyDecl( |
| 354 | cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 355 | D->setPropertyIvarDecl( |
| 356 | cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 359 | void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) { |
| 360 | VisitValueDecl(FD); |
| 361 | FD->setMutable(Record[Idx++]); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 362 | if (Record[Idx++]) |
| 363 | FD->setBitWidth(Reader.ReadExpr()); |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 366 | void PCHDeclReader::VisitVarDecl(VarDecl *VD) { |
| 367 | VisitValueDecl(VD); |
| 368 | VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]); |
| 369 | VD->setThreadSpecified(Record[Idx++]); |
| 370 | VD->setCXXDirectInitializer(Record[Idx++]); |
| 371 | VD->setDeclaredInCondition(Record[Idx++]); |
| 372 | VD->setPreviousDeclaration( |
| 373 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 374 | VD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 375 | if (Record[Idx++]) |
| 376 | VD->setInit(Reader.ReadExpr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 379 | void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
| 380 | VisitVarDecl(PD); |
| 381 | PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 382 | // FIXME: default argument (C++ only) |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) { |
| 386 | VisitParmVarDecl(PD); |
| 387 | PD->setOriginalType(Reader.GetType(Record[Idx++])); |
| 388 | } |
| 389 | |
Douglas Gregor | 1028bc6 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 390 | void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
| 391 | VisitDecl(AD); |
Douglas Gregor | 6a2bfb2 | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 392 | AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr())); |
Douglas Gregor | 1028bc6 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) { |
| 396 | VisitDecl(BD); |
Douglas Gregor | 84af7c2 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 397 | BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt())); |
Douglas Gregor | 1028bc6 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 398 | unsigned NumParams = Record[Idx++]; |
| 399 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 400 | Params.reserve(NumParams); |
| 401 | for (unsigned I = 0; I != NumParams; ++I) |
| 402 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 403 | BD->setParams(Reader.getContext(), &Params[0], NumParams); |
| 404 | } |
| 405 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 406 | std::pair<uint64_t, uint64_t> |
| 407 | PCHDeclReader::VisitDeclContext(DeclContext *DC) { |
| 408 | uint64_t LexicalOffset = Record[Idx++]; |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 409 | uint64_t VisibleOffset = Record[Idx++]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 410 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 411 | } |
| 412 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 413 | //===----------------------------------------------------------------------===// |
| 414 | // Statement/expression deserialization |
| 415 | //===----------------------------------------------------------------------===// |
| 416 | namespace { |
| 417 | class VISIBILITY_HIDDEN PCHStmtReader |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 418 | : public StmtVisitor<PCHStmtReader, unsigned> { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 419 | PCHReader &Reader; |
| 420 | const PCHReader::RecordData &Record; |
| 421 | unsigned &Idx; |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 422 | llvm::SmallVectorImpl<Stmt *> &StmtStack; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 423 | |
| 424 | public: |
| 425 | PCHStmtReader(PCHReader &Reader, const PCHReader::RecordData &Record, |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 426 | unsigned &Idx, llvm::SmallVectorImpl<Stmt *> &StmtStack) |
| 427 | : Reader(Reader), Record(Record), Idx(Idx), StmtStack(StmtStack) { } |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 428 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 429 | /// \brief The number of record fields required for the Stmt class |
| 430 | /// itself. |
| 431 | static const unsigned NumStmtFields = 0; |
| 432 | |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 433 | /// \brief The number of record fields required for the Expr class |
| 434 | /// itself. |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 435 | static const unsigned NumExprFields = NumStmtFields + 3; |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 436 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 437 | // Each of the Visit* functions reads in part of the expression |
| 438 | // from the given record and the current expression stack, then |
| 439 | // return the total number of operands that it read from the |
| 440 | // expression stack. |
| 441 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 442 | unsigned VisitStmt(Stmt *S); |
| 443 | unsigned VisitNullStmt(NullStmt *S); |
| 444 | unsigned VisitCompoundStmt(CompoundStmt *S); |
| 445 | unsigned VisitSwitchCase(SwitchCase *S); |
| 446 | unsigned VisitCaseStmt(CaseStmt *S); |
| 447 | unsigned VisitDefaultStmt(DefaultStmt *S); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 448 | unsigned VisitLabelStmt(LabelStmt *S); |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 449 | unsigned VisitIfStmt(IfStmt *S); |
| 450 | unsigned VisitSwitchStmt(SwitchStmt *S); |
Douglas Gregor | d921cf9 | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 451 | unsigned VisitWhileStmt(WhileStmt *S); |
Douglas Gregor | 67d8249 | 2009-04-17 00:29:51 +0000 | [diff] [blame] | 452 | unsigned VisitDoStmt(DoStmt *S); |
| 453 | unsigned VisitForStmt(ForStmt *S); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 454 | unsigned VisitGotoStmt(GotoStmt *S); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 455 | unsigned VisitIndirectGotoStmt(IndirectGotoStmt *S); |
Douglas Gregor | d921cf9 | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 456 | unsigned VisitContinueStmt(ContinueStmt *S); |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 457 | unsigned VisitBreakStmt(BreakStmt *S); |
Douglas Gregor | 0de9d88 | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 458 | unsigned VisitReturnStmt(ReturnStmt *S); |
Douglas Gregor | 84f2170 | 2009-04-17 16:55:36 +0000 | [diff] [blame] | 459 | unsigned VisitDeclStmt(DeclStmt *S); |
Douglas Gregor | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 460 | unsigned VisitAsmStmt(AsmStmt *S); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 461 | unsigned VisitExpr(Expr *E); |
| 462 | unsigned VisitPredefinedExpr(PredefinedExpr *E); |
| 463 | unsigned VisitDeclRefExpr(DeclRefExpr *E); |
| 464 | unsigned VisitIntegerLiteral(IntegerLiteral *E); |
| 465 | unsigned VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 466 | unsigned VisitImaginaryLiteral(ImaginaryLiteral *E); |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 467 | unsigned VisitStringLiteral(StringLiteral *E); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 468 | unsigned VisitCharacterLiteral(CharacterLiteral *E); |
Douglas Gregor | c04db4f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 469 | unsigned VisitParenExpr(ParenExpr *E); |
Douglas Gregor | 0b0b77f | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 470 | unsigned VisitUnaryOperator(UnaryOperator *E); |
| 471 | unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 472 | unsigned VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 473 | unsigned VisitCallExpr(CallExpr *E); |
| 474 | unsigned VisitMemberExpr(MemberExpr *E); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 475 | unsigned VisitCastExpr(CastExpr *E); |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 476 | unsigned VisitBinaryOperator(BinaryOperator *E); |
Douglas Gregor | ad90e96 | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 477 | unsigned VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 478 | unsigned VisitConditionalOperator(ConditionalOperator *E); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 479 | unsigned VisitImplicitCastExpr(ImplicitCastExpr *E); |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 480 | unsigned VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 481 | unsigned VisitCStyleCastExpr(CStyleCastExpr *E); |
Douglas Gregor | ba6d7e7 | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 482 | unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 483 | unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E); |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 484 | unsigned VisitInitListExpr(InitListExpr *E); |
| 485 | unsigned VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 486 | unsigned VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 487 | unsigned VisitVAArgExpr(VAArgExpr *E); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 488 | unsigned VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | 6a2dd55 | 2009-04-17 19:05:30 +0000 | [diff] [blame] | 489 | unsigned VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | 44cae0c | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 490 | unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E); |
| 491 | unsigned VisitChooseExpr(ChooseExpr *E); |
| 492 | unsigned VisitGNUNullExpr(GNUNullExpr *E); |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 493 | unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E); |
Douglas Gregor | 84af7c2 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 494 | unsigned VisitBlockExpr(BlockExpr *E); |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 495 | unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E); |
Chris Lattner | 3a57a37 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 496 | unsigned VisitObjCStringLiteral(ObjCStringLiteral *E); |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 497 | unsigned VisitObjCEncodeExpr(ObjCEncodeExpr *E); |
Chris Lattner | 3a57a37 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 498 | unsigned VisitObjCSelectorExpr(ObjCSelectorExpr *E); |
| 499 | unsigned VisitObjCProtocolExpr(ObjCProtocolExpr *E); |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 500 | unsigned VisitObjCIvarRefExpr(ObjCIvarRefExpr *E); |
| 501 | unsigned VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E); |
| 502 | unsigned VisitObjCKVCRefExpr(ObjCKVCRefExpr *E); |
Steve Naroff | c4f0bbd | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 503 | unsigned VisitObjCMessageExpr(ObjCMessageExpr *E); |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 504 | unsigned VisitObjCSuperExpr(ObjCSuperExpr *E); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 505 | }; |
| 506 | } |
| 507 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 508 | unsigned PCHStmtReader::VisitStmt(Stmt *S) { |
| 509 | assert(Idx == NumStmtFields && "Incorrect statement field count"); |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | unsigned PCHStmtReader::VisitNullStmt(NullStmt *S) { |
| 514 | VisitStmt(S); |
| 515 | S->setSemiLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | unsigned PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) { |
| 520 | VisitStmt(S); |
| 521 | unsigned NumStmts = Record[Idx++]; |
| 522 | S->setStmts(Reader.getContext(), |
| 523 | &StmtStack[StmtStack.size() - NumStmts], NumStmts); |
| 524 | S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 525 | S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 526 | return NumStmts; |
| 527 | } |
| 528 | |
| 529 | unsigned PCHStmtReader::VisitSwitchCase(SwitchCase *S) { |
| 530 | VisitStmt(S); |
| 531 | Reader.RecordSwitchCaseID(S, Record[Idx++]); |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | unsigned PCHStmtReader::VisitCaseStmt(CaseStmt *S) { |
| 536 | VisitSwitchCase(S); |
| 537 | S->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 538 | S->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 539 | S->setSubStmt(StmtStack.back()); |
| 540 | S->setCaseLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 541 | return 3; |
| 542 | } |
| 543 | |
| 544 | unsigned PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) { |
| 545 | VisitSwitchCase(S); |
| 546 | S->setSubStmt(StmtStack.back()); |
| 547 | S->setDefaultLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 548 | return 1; |
| 549 | } |
| 550 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 551 | unsigned PCHStmtReader::VisitLabelStmt(LabelStmt *S) { |
| 552 | VisitStmt(S); |
| 553 | S->setID(Reader.GetIdentifierInfo(Record, Idx)); |
| 554 | S->setSubStmt(StmtStack.back()); |
| 555 | S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 556 | Reader.RecordLabelStmt(S, Record[Idx++]); |
| 557 | return 1; |
| 558 | } |
| 559 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 560 | unsigned PCHStmtReader::VisitIfStmt(IfStmt *S) { |
| 561 | VisitStmt(S); |
| 562 | S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 563 | S->setThen(StmtStack[StmtStack.size() - 2]); |
| 564 | S->setElse(StmtStack[StmtStack.size() - 1]); |
| 565 | S->setIfLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 566 | return 3; |
| 567 | } |
| 568 | |
| 569 | unsigned PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) { |
| 570 | VisitStmt(S); |
| 571 | S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
| 572 | S->setBody(StmtStack.back()); |
| 573 | S->setSwitchLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 574 | SwitchCase *PrevSC = 0; |
| 575 | for (unsigned N = Record.size(); Idx != N; ++Idx) { |
| 576 | SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]); |
| 577 | if (PrevSC) |
| 578 | PrevSC->setNextSwitchCase(SC); |
| 579 | else |
| 580 | S->setSwitchCaseList(SC); |
| 581 | PrevSC = SC; |
| 582 | } |
| 583 | return 2; |
| 584 | } |
| 585 | |
Douglas Gregor | d921cf9 | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 586 | unsigned PCHStmtReader::VisitWhileStmt(WhileStmt *S) { |
| 587 | VisitStmt(S); |
| 588 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 589 | S->setBody(StmtStack.back()); |
| 590 | S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 591 | return 2; |
| 592 | } |
| 593 | |
Douglas Gregor | 67d8249 | 2009-04-17 00:29:51 +0000 | [diff] [blame] | 594 | unsigned PCHStmtReader::VisitDoStmt(DoStmt *S) { |
| 595 | VisitStmt(S); |
| 596 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 597 | S->setBody(StmtStack.back()); |
| 598 | S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 599 | return 2; |
| 600 | } |
| 601 | |
| 602 | unsigned PCHStmtReader::VisitForStmt(ForStmt *S) { |
| 603 | VisitStmt(S); |
| 604 | S->setInit(StmtStack[StmtStack.size() - 4]); |
| 605 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 3])); |
| 606 | S->setInc(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 607 | S->setBody(StmtStack.back()); |
| 608 | S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 609 | return 4; |
| 610 | } |
| 611 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 612 | unsigned PCHStmtReader::VisitGotoStmt(GotoStmt *S) { |
| 613 | VisitStmt(S); |
| 614 | Reader.SetLabelOf(S, Record[Idx++]); |
| 615 | S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 616 | S->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 617 | return 0; |
| 618 | } |
| 619 | |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 620 | unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 621 | VisitStmt(S); |
Chris Lattner | ad56d68 | 2009-04-19 01:04:21 +0000 | [diff] [blame] | 622 | S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 623 | S->setTarget(cast_or_null<Expr>(StmtStack.back())); |
| 624 | return 1; |
| 625 | } |
| 626 | |
Douglas Gregor | d921cf9 | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 627 | unsigned PCHStmtReader::VisitContinueStmt(ContinueStmt *S) { |
| 628 | VisitStmt(S); |
| 629 | S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 630 | return 0; |
| 631 | } |
| 632 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 633 | unsigned PCHStmtReader::VisitBreakStmt(BreakStmt *S) { |
| 634 | VisitStmt(S); |
| 635 | S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 636 | return 0; |
| 637 | } |
| 638 | |
Douglas Gregor | 0de9d88 | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 639 | unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) { |
| 640 | VisitStmt(S); |
| 641 | S->setRetValue(cast_or_null<Expr>(StmtStack.back())); |
| 642 | S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 643 | return 1; |
| 644 | } |
| 645 | |
Douglas Gregor | 84f2170 | 2009-04-17 16:55:36 +0000 | [diff] [blame] | 646 | unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) { |
| 647 | VisitStmt(S); |
| 648 | S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 649 | S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 650 | |
| 651 | if (Idx + 1 == Record.size()) { |
| 652 | // Single declaration |
| 653 | S->setDeclGroup(DeclGroupRef(Reader.GetDecl(Record[Idx++]))); |
| 654 | } else { |
| 655 | llvm::SmallVector<Decl *, 16> Decls; |
| 656 | Decls.reserve(Record.size() - Idx); |
| 657 | for (unsigned N = Record.size(); Idx != N; ++Idx) |
| 658 | Decls.push_back(Reader.GetDecl(Record[Idx])); |
| 659 | S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(), |
| 660 | &Decls[0], Decls.size()))); |
| 661 | } |
| 662 | return 0; |
| 663 | } |
| 664 | |
Douglas Gregor | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 665 | unsigned PCHStmtReader::VisitAsmStmt(AsmStmt *S) { |
| 666 | VisitStmt(S); |
| 667 | unsigned NumOutputs = Record[Idx++]; |
| 668 | unsigned NumInputs = Record[Idx++]; |
| 669 | unsigned NumClobbers = Record[Idx++]; |
| 670 | S->setAsmLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 671 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 672 | S->setVolatile(Record[Idx++]); |
| 673 | S->setSimple(Record[Idx++]); |
| 674 | |
| 675 | unsigned StackIdx |
| 676 | = StmtStack.size() - (NumOutputs*2 + NumInputs*2 + NumClobbers + 1); |
| 677 | S->setAsmString(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 678 | |
| 679 | // Outputs and inputs |
| 680 | llvm::SmallVector<std::string, 16> Names; |
| 681 | llvm::SmallVector<StringLiteral*, 16> Constraints; |
| 682 | llvm::SmallVector<Stmt*, 16> Exprs; |
| 683 | for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) { |
| 684 | Names.push_back(Reader.ReadString(Record, Idx)); |
| 685 | Constraints.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 686 | Exprs.push_back(StmtStack[StackIdx++]); |
| 687 | } |
| 688 | S->setOutputsAndInputs(NumOutputs, NumInputs, |
| 689 | &Names[0], &Constraints[0], &Exprs[0]); |
| 690 | |
| 691 | // Constraints |
| 692 | llvm::SmallVector<StringLiteral*, 16> Clobbers; |
| 693 | for (unsigned I = 0; I != NumClobbers; ++I) |
| 694 | Clobbers.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 695 | S->setClobbers(&Clobbers[0], NumClobbers); |
| 696 | |
| 697 | assert(StackIdx == StmtStack.size() && "Error deserializing AsmStmt"); |
| 698 | return NumOutputs*2 + NumInputs*2 + NumClobbers + 1; |
| 699 | } |
| 700 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 701 | unsigned PCHStmtReader::VisitExpr(Expr *E) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 702 | VisitStmt(E); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 703 | E->setType(Reader.GetType(Record[Idx++])); |
| 704 | E->setTypeDependent(Record[Idx++]); |
| 705 | E->setValueDependent(Record[Idx++]); |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 706 | assert(Idx == NumExprFields && "Incorrect expression field count"); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 707 | return 0; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 710 | unsigned PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 711 | VisitExpr(E); |
| 712 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 713 | E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 714 | return 0; |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 717 | unsigned PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 718 | VisitExpr(E); |
| 719 | E->setDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 720 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 721 | return 0; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 724 | unsigned PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 725 | VisitExpr(E); |
| 726 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 727 | E->setValue(Reader.ReadAPInt(Record, Idx)); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 728 | return 0; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 731 | unsigned PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 732 | VisitExpr(E); |
| 733 | E->setValue(Reader.ReadAPFloat(Record, Idx)); |
| 734 | E->setExact(Record[Idx++]); |
| 735 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 736 | return 0; |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 739 | unsigned PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 740 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 741 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 742 | return 1; |
| 743 | } |
| 744 | |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 745 | unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) { |
| 746 | VisitExpr(E); |
| 747 | unsigned Len = Record[Idx++]; |
| 748 | assert(Record[Idx] == E->getNumConcatenated() && |
| 749 | "Wrong number of concatenated tokens!"); |
| 750 | ++Idx; |
| 751 | E->setWide(Record[Idx++]); |
| 752 | |
| 753 | // Read string data |
| 754 | llvm::SmallVector<char, 16> Str(&Record[Idx], &Record[Idx] + Len); |
| 755 | E->setStrData(Reader.getContext(), &Str[0], Len); |
| 756 | Idx += Len; |
| 757 | |
| 758 | // Read source locations |
| 759 | for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) |
| 760 | E->setStrTokenLoc(I, SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 761 | |
| 762 | return 0; |
| 763 | } |
| 764 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 765 | unsigned PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 766 | VisitExpr(E); |
| 767 | E->setValue(Record[Idx++]); |
| 768 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 769 | E->setWide(Record[Idx++]); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 770 | return 0; |
| 771 | } |
| 772 | |
Douglas Gregor | c04db4f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 773 | unsigned PCHStmtReader::VisitParenExpr(ParenExpr *E) { |
| 774 | VisitExpr(E); |
| 775 | E->setLParen(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 776 | E->setRParen(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 777 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | c04db4f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 778 | return 1; |
| 779 | } |
| 780 | |
Douglas Gregor | 0b0b77f | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 781 | unsigned PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) { |
| 782 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 783 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 0b0b77f | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 784 | E->setOpcode((UnaryOperator::Opcode)Record[Idx++]); |
| 785 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 786 | return 1; |
| 787 | } |
| 788 | |
| 789 | unsigned PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
| 790 | VisitExpr(E); |
| 791 | E->setSizeof(Record[Idx++]); |
| 792 | if (Record[Idx] == 0) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 793 | E->setArgument(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 0b0b77f | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 794 | ++Idx; |
| 795 | } else { |
| 796 | E->setArgument(Reader.GetType(Record[Idx++])); |
| 797 | } |
| 798 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 799 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 800 | return E->isArgumentType()? 0 : 1; |
| 801 | } |
| 802 | |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 803 | unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 804 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 805 | E->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
Steve Naroff | d3f632e | 2009-04-25 15:19:54 +0000 | [diff] [blame] | 806 | E->setRHS(cast<Expr>(StmtStack[StmtStack.size() - 1])); |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 807 | E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 808 | return 2; |
| 809 | } |
| 810 | |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 811 | unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) { |
| 812 | VisitExpr(E); |
| 813 | E->setNumArgs(Reader.getContext(), Record[Idx++]); |
| 814 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 815 | E->setCallee(cast<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1])); |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 816 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 817 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 818 | return E->getNumArgs() + 1; |
| 819 | } |
| 820 | |
| 821 | unsigned PCHStmtReader::VisitMemberExpr(MemberExpr *E) { |
| 822 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 823 | E->setBase(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 824 | E->setMemberDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 825 | E->setMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 826 | E->setArrow(Record[Idx++]); |
| 827 | return 1; |
| 828 | } |
| 829 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 830 | unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) { |
| 831 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 832 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 833 | return 1; |
| 834 | } |
| 835 | |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 836 | unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) { |
| 837 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 838 | E->setLHS(cast<Expr>(StmtStack.end()[-2])); |
| 839 | E->setRHS(cast<Expr>(StmtStack.end()[-1])); |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 840 | E->setOpcode((BinaryOperator::Opcode)Record[Idx++]); |
| 841 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 842 | return 2; |
| 843 | } |
| 844 | |
Douglas Gregor | ad90e96 | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 845 | unsigned PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 846 | VisitBinaryOperator(E); |
| 847 | E->setComputationLHSType(Reader.GetType(Record[Idx++])); |
| 848 | E->setComputationResultType(Reader.GetType(Record[Idx++])); |
| 849 | return 2; |
| 850 | } |
| 851 | |
| 852 | unsigned PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) { |
| 853 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 854 | E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 855 | E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 856 | E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1])); |
Douglas Gregor | ad90e96 | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 857 | return 3; |
| 858 | } |
| 859 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 860 | unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 861 | VisitCastExpr(E); |
| 862 | E->setLvalueCast(Record[Idx++]); |
| 863 | return 1; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 866 | unsigned PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 867 | VisitCastExpr(E); |
| 868 | E->setTypeAsWritten(Reader.GetType(Record[Idx++])); |
| 869 | return 1; |
| 870 | } |
| 871 | |
| 872 | unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { |
| 873 | VisitExplicitCastExpr(E); |
| 874 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 875 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 876 | return 1; |
| 877 | } |
| 878 | |
Douglas Gregor | ba6d7e7 | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 879 | unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 880 | VisitExpr(E); |
| 881 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 882 | E->setInitializer(cast<Expr>(StmtStack.back())); |
Douglas Gregor | ba6d7e7 | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 883 | E->setFileScope(Record[Idx++]); |
| 884 | return 1; |
| 885 | } |
| 886 | |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 887 | unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { |
| 888 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 889 | E->setBase(cast<Expr>(StmtStack.back())); |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 890 | E->setAccessor(Reader.GetIdentifierInfo(Record, Idx)); |
| 891 | E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 892 | return 1; |
| 893 | } |
| 894 | |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 895 | unsigned PCHStmtReader::VisitInitListExpr(InitListExpr *E) { |
| 896 | VisitExpr(E); |
| 897 | unsigned NumInits = Record[Idx++]; |
| 898 | E->reserveInits(NumInits); |
| 899 | for (unsigned I = 0; I != NumInits; ++I) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 900 | E->updateInit(I, |
| 901 | cast<Expr>(StmtStack[StmtStack.size() - NumInits - 1 + I])); |
| 902 | E->setSyntacticForm(cast_or_null<InitListExpr>(StmtStack.back())); |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 903 | E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 904 | E->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 905 | E->setInitializedFieldInUnion( |
| 906 | cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]))); |
| 907 | E->sawArrayRangeDesignator(Record[Idx++]); |
| 908 | return NumInits + 1; |
| 909 | } |
| 910 | |
| 911 | unsigned PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 912 | typedef DesignatedInitExpr::Designator Designator; |
| 913 | |
| 914 | VisitExpr(E); |
| 915 | unsigned NumSubExprs = Record[Idx++]; |
| 916 | assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs"); |
| 917 | for (unsigned I = 0; I != NumSubExprs; ++I) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 918 | E->setSubExpr(I, cast<Expr>(StmtStack[StmtStack.size() - NumSubExprs + I])); |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 919 | E->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 920 | E->setGNUSyntax(Record[Idx++]); |
| 921 | |
| 922 | llvm::SmallVector<Designator, 4> Designators; |
| 923 | while (Idx < Record.size()) { |
| 924 | switch ((pch::DesignatorTypes)Record[Idx++]) { |
| 925 | case pch::DESIG_FIELD_DECL: { |
| 926 | FieldDecl *Field = cast<FieldDecl>(Reader.GetDecl(Record[Idx++])); |
| 927 | SourceLocation DotLoc |
| 928 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 929 | SourceLocation FieldLoc |
| 930 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 931 | Designators.push_back(Designator(Field->getIdentifier(), DotLoc, |
| 932 | FieldLoc)); |
| 933 | Designators.back().setField(Field); |
| 934 | break; |
| 935 | } |
| 936 | |
| 937 | case pch::DESIG_FIELD_NAME: { |
| 938 | const IdentifierInfo *Name = Reader.GetIdentifierInfo(Record, Idx); |
| 939 | SourceLocation DotLoc |
| 940 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 941 | SourceLocation FieldLoc |
| 942 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 943 | Designators.push_back(Designator(Name, DotLoc, FieldLoc)); |
| 944 | break; |
| 945 | } |
| 946 | |
| 947 | case pch::DESIG_ARRAY: { |
| 948 | unsigned Index = Record[Idx++]; |
| 949 | SourceLocation LBracketLoc |
| 950 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 951 | SourceLocation RBracketLoc |
| 952 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 953 | Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc)); |
| 954 | break; |
| 955 | } |
| 956 | |
| 957 | case pch::DESIG_ARRAY_RANGE: { |
| 958 | unsigned Index = Record[Idx++]; |
| 959 | SourceLocation LBracketLoc |
| 960 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 961 | SourceLocation EllipsisLoc |
| 962 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 963 | SourceLocation RBracketLoc |
| 964 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 965 | Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc, |
| 966 | RBracketLoc)); |
| 967 | break; |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | E->setDesignators(&Designators[0], Designators.size()); |
| 972 | |
| 973 | return NumSubExprs; |
| 974 | } |
| 975 | |
| 976 | unsigned PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 977 | VisitExpr(E); |
| 978 | return 0; |
| 979 | } |
| 980 | |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 981 | unsigned PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) { |
| 982 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 983 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 984 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 985 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 986 | return 1; |
| 987 | } |
| 988 | |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 989 | unsigned PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 990 | VisitExpr(E); |
| 991 | E->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 992 | E->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 993 | Reader.SetLabelOf(E, Record[Idx++]); |
| 994 | return 0; |
| 995 | } |
| 996 | |
Douglas Gregor | 6a2dd55 | 2009-04-17 19:05:30 +0000 | [diff] [blame] | 997 | unsigned PCHStmtReader::VisitStmtExpr(StmtExpr *E) { |
| 998 | VisitExpr(E); |
| 999 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1000 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1001 | E->setSubStmt(cast_or_null<CompoundStmt>(StmtStack.back())); |
| 1002 | return 1; |
| 1003 | } |
| 1004 | |
Douglas Gregor | 44cae0c | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 1005 | unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { |
| 1006 | VisitExpr(E); |
| 1007 | E->setArgType1(Reader.GetType(Record[Idx++])); |
| 1008 | E->setArgType2(Reader.GetType(Record[Idx++])); |
| 1009 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1010 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | unsigned PCHStmtReader::VisitChooseExpr(ChooseExpr *E) { |
| 1015 | VisitExpr(E); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1016 | E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 1017 | E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 1018 | E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1])); |
Douglas Gregor | 44cae0c | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 1019 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1020 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1021 | return 3; |
| 1022 | } |
| 1023 | |
| 1024 | unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) { |
| 1025 | VisitExpr(E); |
| 1026 | E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1027 | return 0; |
| 1028 | } |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 1029 | |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 1030 | unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { |
| 1031 | VisitExpr(E); |
| 1032 | unsigned NumExprs = Record[Idx++]; |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1033 | E->setExprs((Expr **)&StmtStack[StmtStack.size() - NumExprs], NumExprs); |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 1034 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1035 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1036 | return NumExprs; |
| 1037 | } |
| 1038 | |
Douglas Gregor | 84af7c2 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 1039 | unsigned PCHStmtReader::VisitBlockExpr(BlockExpr *E) { |
| 1040 | VisitExpr(E); |
| 1041 | E->setBlockDecl(cast_or_null<BlockDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1042 | E->setHasBlockDeclRefExprs(Record[Idx++]); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 1046 | unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { |
| 1047 | VisitExpr(E); |
| 1048 | E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1049 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1050 | E->setByRef(Record[Idx++]); |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
Chris Lattner | 3a57a37 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 1054 | //===----------------------------------------------------------------------===// |
| 1055 | // Objective-C Expressions and Statements |
| 1056 | |
| 1057 | unsigned PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) { |
| 1058 | VisitExpr(E); |
| 1059 | E->setString(cast<StringLiteral>(StmtStack.back())); |
| 1060 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1061 | return 1; |
| 1062 | } |
| 1063 | |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 1064 | unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { |
| 1065 | VisitExpr(E); |
| 1066 | E->setEncodedType(Reader.GetType(Record[Idx++])); |
| 1067 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1068 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
Chris Lattner | 3a57a37 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 1072 | unsigned PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 1073 | VisitExpr(E); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1074 | E->setSelector(Reader.GetSelector(Record, Idx)); |
Chris Lattner | 3a57a37 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 1075 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1076 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
| 1080 | unsigned PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 1081 | VisitExpr(E); |
| 1082 | E->setProtocol(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1083 | E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1084 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 1088 | unsigned PCHStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| 1089 | VisitExpr(E); |
| 1090 | E->setDecl(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1091 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1092 | E->setBase(cast<Expr>(StmtStack.back())); |
| 1093 | E->setIsArrow(Record[Idx++]); |
| 1094 | E->setIsFreeIvar(Record[Idx++]); |
| 1095 | return 1; |
| 1096 | } |
| 1097 | |
| 1098 | unsigned PCHStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 1099 | VisitExpr(E); |
| 1100 | E->setProperty(cast<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1101 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1102 | E->setBase(cast<Expr>(StmtStack.back())); |
| 1103 | return 1; |
| 1104 | } |
| 1105 | |
| 1106 | unsigned PCHStmtReader::VisitObjCKVCRefExpr(ObjCKVCRefExpr *E) { |
| 1107 | VisitExpr(E); |
| 1108 | E->setGetterMethod(cast<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1109 | E->setSetterMethod(cast<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1110 | E->setClassProp(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 1111 | E->setBase(cast<Expr>(StmtStack.back())); |
| 1112 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1113 | E->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1114 | return 1; |
| 1115 | } |
| 1116 | |
Steve Naroff | c4f0bbd | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 1117 | unsigned PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { |
| 1118 | VisitExpr(E); |
| 1119 | E->setNumArgs(Record[Idx++]); |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 1120 | E->setLeftLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1121 | E->setRightLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Steve Naroff | c4f0bbd | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 1122 | E->setSelector(Reader.GetSelector(Record, Idx)); |
| 1123 | E->setMethodDecl(cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++]))); |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 1124 | |
| 1125 | ObjCMessageExpr::ClassInfo CI; |
| 1126 | CI.first = cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])); |
| 1127 | CI.second = Reader.GetIdentifierInfo(Record, Idx); |
| 1128 | if (E->getMethodDecl() == 0) |
| 1129 | E->setClassInfo(CI); |
| 1130 | |
Steve Naroff | c4f0bbd | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 1131 | E->setReceiver(cast<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1])); |
| 1132 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
| 1133 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
| 1134 | return E->getNumArgs() + 1; |
| 1135 | } |
| 1136 | |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 1137 | unsigned PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) { |
| 1138 | VisitExpr(E); |
| 1139 | E->setLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 1140 | return 0; |
| 1141 | } |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 1142 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1143 | //===----------------------------------------------------------------------===// |
| 1144 | // PCH reader implementation |
| 1145 | //===----------------------------------------------------------------------===// |
| 1146 | |
| 1147 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1148 | class VISIBILITY_HIDDEN PCHMethodPoolLookupTrait { |
| 1149 | PCHReader &Reader; |
| 1150 | |
| 1151 | public: |
| 1152 | typedef std::pair<ObjCMethodList, ObjCMethodList> data_type; |
| 1153 | |
| 1154 | typedef Selector external_key_type; |
| 1155 | typedef external_key_type internal_key_type; |
| 1156 | |
| 1157 | explicit PCHMethodPoolLookupTrait(PCHReader &Reader) : Reader(Reader) { } |
| 1158 | |
| 1159 | static bool EqualKey(const internal_key_type& a, |
| 1160 | const internal_key_type& b) { |
| 1161 | return a == b; |
| 1162 | } |
| 1163 | |
| 1164 | static unsigned ComputeHash(Selector Sel) { |
| 1165 | unsigned N = Sel.getNumArgs(); |
| 1166 | if (N == 0) |
| 1167 | ++N; |
| 1168 | unsigned R = 5381; |
| 1169 | for (unsigned I = 0; I != N; ++I) |
| 1170 | if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I)) |
| 1171 | R = clang::BernsteinHashPartial(II->getName(), II->getLength(), R); |
| 1172 | return R; |
| 1173 | } |
| 1174 | |
| 1175 | // This hopefully will just get inlined and removed by the optimizer. |
| 1176 | static const internal_key_type& |
| 1177 | GetInternalKey(const external_key_type& x) { return x; } |
| 1178 | |
| 1179 | static std::pair<unsigned, unsigned> |
| 1180 | ReadKeyDataLength(const unsigned char*& d) { |
| 1181 | using namespace clang::io; |
| 1182 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 1183 | unsigned DataLen = ReadUnalignedLE16(d); |
| 1184 | return std::make_pair(KeyLen, DataLen); |
| 1185 | } |
| 1186 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1187 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1188 | using namespace clang::io; |
| 1189 | SelectorTable &SelTable = Reader.getContext().Selectors; |
| 1190 | unsigned N = ReadUnalignedLE16(d); |
| 1191 | IdentifierInfo *FirstII |
| 1192 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 1193 | if (N == 0) |
| 1194 | return SelTable.getNullarySelector(FirstII); |
| 1195 | else if (N == 1) |
| 1196 | return SelTable.getUnarySelector(FirstII); |
| 1197 | |
| 1198 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 1199 | Args.push_back(FirstII); |
| 1200 | for (unsigned I = 1; I != N; ++I) |
| 1201 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 1202 | |
| 1203 | return SelTable.getSelector(N, &Args[0]); |
| 1204 | } |
| 1205 | |
| 1206 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 1207 | using namespace clang::io; |
| 1208 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 1209 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 1210 | |
| 1211 | data_type Result; |
| 1212 | |
| 1213 | // Load instance methods |
| 1214 | ObjCMethodList *Prev = 0; |
| 1215 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 1216 | ObjCMethodDecl *Method |
| 1217 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
| 1218 | if (!Result.first.Method) { |
| 1219 | // This is the first method, which is the easy case. |
| 1220 | Result.first.Method = Method; |
| 1221 | Prev = &Result.first; |
| 1222 | continue; |
| 1223 | } |
| 1224 | |
| 1225 | Prev->Next = new ObjCMethodList(Method, 0); |
| 1226 | Prev = Prev->Next; |
| 1227 | } |
| 1228 | |
| 1229 | // Load factory methods |
| 1230 | Prev = 0; |
| 1231 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 1232 | ObjCMethodDecl *Method |
| 1233 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
| 1234 | if (!Result.second.Method) { |
| 1235 | // This is the first method, which is the easy case. |
| 1236 | Result.second.Method = Method; |
| 1237 | Prev = &Result.second; |
| 1238 | continue; |
| 1239 | } |
| 1240 | |
| 1241 | Prev->Next = new ObjCMethodList(Method, 0); |
| 1242 | Prev = Prev->Next; |
| 1243 | } |
| 1244 | |
| 1245 | return Result; |
| 1246 | } |
| 1247 | }; |
| 1248 | |
| 1249 | } // end anonymous namespace |
| 1250 | |
| 1251 | /// \brief The on-disk hash table used for the global method pool. |
| 1252 | typedef OnDiskChainedHashTable<PCHMethodPoolLookupTrait> |
| 1253 | PCHMethodPoolLookupTable; |
| 1254 | |
| 1255 | namespace { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1256 | class VISIBILITY_HIDDEN PCHIdentifierLookupTrait { |
| 1257 | PCHReader &Reader; |
| 1258 | |
| 1259 | // If we know the IdentifierInfo in advance, it is here and we will |
| 1260 | // not build a new one. Used when deserializing information about an |
| 1261 | // identifier that was constructed before the PCH file was read. |
| 1262 | IdentifierInfo *KnownII; |
| 1263 | |
| 1264 | public: |
| 1265 | typedef IdentifierInfo * data_type; |
| 1266 | |
| 1267 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 1268 | |
| 1269 | typedef external_key_type internal_key_type; |
| 1270 | |
| 1271 | explicit PCHIdentifierLookupTrait(PCHReader &Reader, IdentifierInfo *II = 0) |
| 1272 | : Reader(Reader), KnownII(II) { } |
| 1273 | |
| 1274 | static bool EqualKey(const internal_key_type& a, |
| 1275 | const internal_key_type& b) { |
| 1276 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 1277 | : false; |
| 1278 | } |
| 1279 | |
| 1280 | static unsigned ComputeHash(const internal_key_type& a) { |
| 1281 | return BernsteinHash(a.first, a.second); |
| 1282 | } |
| 1283 | |
| 1284 | // This hopefully will just get inlined and removed by the optimizer. |
| 1285 | static const internal_key_type& |
| 1286 | GetInternalKey(const external_key_type& x) { return x; } |
| 1287 | |
| 1288 | static std::pair<unsigned, unsigned> |
| 1289 | ReadKeyDataLength(const unsigned char*& d) { |
| 1290 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 1291 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 1292 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1293 | return std::make_pair(KeyLen, DataLen); |
| 1294 | } |
| 1295 | |
| 1296 | static std::pair<const char*, unsigned> |
| 1297 | ReadKey(const unsigned char* d, unsigned n) { |
| 1298 | assert(n >= 2 && d[n-1] == '\0'); |
| 1299 | return std::make_pair((const char*) d, n-1); |
| 1300 | } |
| 1301 | |
| 1302 | IdentifierInfo *ReadData(const internal_key_type& k, |
| 1303 | const unsigned char* d, |
| 1304 | unsigned DataLen) { |
| 1305 | using namespace clang::io; |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 1306 | uint32_t Bits = ReadUnalignedLE32(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 1307 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 1308 | Bits >>= 1; |
| 1309 | bool Poisoned = Bits & 0x01; |
| 1310 | Bits >>= 1; |
| 1311 | bool ExtensionToken = Bits & 0x01; |
| 1312 | Bits >>= 1; |
| 1313 | bool hasMacroDefinition = Bits & 0x01; |
| 1314 | Bits >>= 1; |
| 1315 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 1316 | Bits >>= 10; |
| 1317 | unsigned TokenID = Bits & 0xFF; |
| 1318 | Bits >>= 8; |
| 1319 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1320 | pch::IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 1321 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1322 | DataLen -= 8; |
| 1323 | |
| 1324 | // Build the IdentifierInfo itself and link the identifier ID with |
| 1325 | // the new IdentifierInfo. |
| 1326 | IdentifierInfo *II = KnownII; |
| 1327 | if (!II) |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 1328 | II = &Reader.getIdentifierTable().CreateIdentifierInfo( |
| 1329 | k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1330 | Reader.SetIdentifierInfo(ID, II); |
| 1331 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 1332 | // Set or check the various bits in the IdentifierInfo structure. |
| 1333 | // FIXME: Load token IDs lazily, too? |
| 1334 | assert((unsigned)II->getTokenID() == TokenID && |
| 1335 | "Incorrect token ID loaded"); |
| 1336 | (void)TokenID; |
| 1337 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 1338 | assert(II->isExtensionToken() == ExtensionToken && |
| 1339 | "Incorrect extension token flag"); |
| 1340 | (void)ExtensionToken; |
| 1341 | II->setIsPoisoned(Poisoned); |
| 1342 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 1343 | "Incorrect C++ operator keyword flag"); |
| 1344 | (void)CPlusPlusOperatorKeyword; |
| 1345 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1346 | // If this identifier is a macro, deserialize the macro |
| 1347 | // definition. |
| 1348 | if (hasMacroDefinition) { |
| 1349 | uint32_t Offset = ReadUnalignedLE64(d); |
| 1350 | Reader.ReadMacroRecord(Offset); |
| 1351 | DataLen -= 8; |
| 1352 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1353 | |
| 1354 | // Read all of the declarations visible at global scope with this |
| 1355 | // name. |
| 1356 | Sema *SemaObj = Reader.getSema(); |
| 1357 | while (DataLen > 0) { |
| 1358 | NamedDecl *D = cast<NamedDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1359 | if (SemaObj) { |
| 1360 | // Introduce this declaration into the translation-unit scope |
| 1361 | // and add it to the declaration chain for this identifier, so |
| 1362 | // that (unqualified) name lookup will find it. |
| 1363 | SemaObj->TUScope->AddDecl(Action::DeclPtrTy::make(D)); |
| 1364 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
| 1365 | } else { |
| 1366 | // Queue this declaration so that it will be added to the |
| 1367 | // translation unit scope and identifier's declaration chain |
| 1368 | // once a Sema object is known. |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 1369 | Reader.PreloadedDecls.push_back(D); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | DataLen -= 4; |
| 1373 | } |
| 1374 | return II; |
| 1375 | } |
| 1376 | }; |
| 1377 | |
| 1378 | } // end anonymous namespace |
| 1379 | |
| 1380 | /// \brief The on-disk hash table used to contain information about |
| 1381 | /// all of the identifiers in the program. |
| 1382 | typedef OnDiskChainedHashTable<PCHIdentifierLookupTrait> |
| 1383 | PCHIdentifierLookupTable; |
| 1384 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1385 | // FIXME: use the diagnostics machinery |
| 1386 | static bool Error(const char *Str) { |
| 1387 | std::fprintf(stderr, "%s\n", Str); |
| 1388 | return true; |
| 1389 | } |
| 1390 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1391 | /// \brief Check the contents of the predefines buffer against the |
| 1392 | /// contents of the predefines buffer used to build the PCH file. |
| 1393 | /// |
| 1394 | /// The contents of the two predefines buffers should be the same. If |
| 1395 | /// not, then some command-line option changed the preprocessor state |
| 1396 | /// and we must reject the PCH file. |
| 1397 | /// |
| 1398 | /// \param PCHPredef The start of the predefines buffer in the PCH |
| 1399 | /// file. |
| 1400 | /// |
| 1401 | /// \param PCHPredefLen The length of the predefines buffer in the PCH |
| 1402 | /// file. |
| 1403 | /// |
| 1404 | /// \param PCHBufferID The FileID for the PCH predefines buffer. |
| 1405 | /// |
| 1406 | /// \returns true if there was a mismatch (in which case the PCH file |
| 1407 | /// should be ignored), or false otherwise. |
| 1408 | bool PCHReader::CheckPredefinesBuffer(const char *PCHPredef, |
| 1409 | unsigned PCHPredefLen, |
| 1410 | FileID PCHBufferID) { |
| 1411 | const char *Predef = PP.getPredefines().c_str(); |
| 1412 | unsigned PredefLen = PP.getPredefines().size(); |
| 1413 | |
| 1414 | // If the two predefines buffers compare equal, we're done!. |
| 1415 | if (PredefLen == PCHPredefLen && |
| 1416 | strncmp(Predef, PCHPredef, PCHPredefLen) == 0) |
| 1417 | return false; |
| 1418 | |
| 1419 | // The predefines buffers are different. Produce a reasonable |
| 1420 | // diagnostic showing where they are different. |
| 1421 | |
| 1422 | // The source locations (potentially in the two different predefines |
| 1423 | // buffers) |
| 1424 | SourceLocation Loc1, Loc2; |
| 1425 | SourceManager &SourceMgr = PP.getSourceManager(); |
| 1426 | |
| 1427 | // Create a source buffer for our predefines string, so |
| 1428 | // that we can build a diagnostic that points into that |
| 1429 | // source buffer. |
| 1430 | FileID BufferID; |
| 1431 | if (Predef && Predef[0]) { |
| 1432 | llvm::MemoryBuffer *Buffer |
| 1433 | = llvm::MemoryBuffer::getMemBuffer(Predef, Predef + PredefLen, |
| 1434 | "<built-in>"); |
| 1435 | BufferID = SourceMgr.createFileIDForMemBuffer(Buffer); |
| 1436 | } |
| 1437 | |
| 1438 | unsigned MinLen = std::min(PredefLen, PCHPredefLen); |
| 1439 | std::pair<const char *, const char *> Locations |
| 1440 | = std::mismatch(Predef, Predef + MinLen, PCHPredef); |
| 1441 | |
| 1442 | if (Locations.first != Predef + MinLen) { |
| 1443 | // We found the location in the two buffers where there is a |
| 1444 | // difference. Form source locations to point there (in both |
| 1445 | // buffers). |
| 1446 | unsigned Offset = Locations.first - Predef; |
| 1447 | Loc1 = SourceMgr.getLocForStartOfFile(BufferID) |
| 1448 | .getFileLocWithOffset(Offset); |
| 1449 | Loc2 = SourceMgr.getLocForStartOfFile(PCHBufferID) |
| 1450 | .getFileLocWithOffset(Offset); |
| 1451 | } else if (PredefLen > PCHPredefLen) { |
| 1452 | Loc1 = SourceMgr.getLocForStartOfFile(BufferID) |
| 1453 | .getFileLocWithOffset(MinLen); |
| 1454 | } else { |
| 1455 | Loc1 = SourceMgr.getLocForStartOfFile(PCHBufferID) |
| 1456 | .getFileLocWithOffset(MinLen); |
| 1457 | } |
| 1458 | |
| 1459 | Diag(Loc1, diag::warn_pch_preprocessor); |
| 1460 | if (Loc2.isValid()) |
| 1461 | Diag(Loc2, diag::note_predef_in_pch); |
| 1462 | Diag(diag::note_ignoring_pch) << FileName; |
| 1463 | return true; |
| 1464 | } |
| 1465 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1466 | /// \brief Read the line table in the source manager block. |
| 1467 | /// \returns true if ther was an error. |
| 1468 | static bool ParseLineTable(SourceManager &SourceMgr, |
| 1469 | llvm::SmallVectorImpl<uint64_t> &Record) { |
| 1470 | unsigned Idx = 0; |
| 1471 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1472 | |
| 1473 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1474 | std::map<int, int> FileIDs; |
| 1475 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1476 | // Extract the file name |
| 1477 | unsigned FilenameLen = Record[Idx++]; |
| 1478 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 1479 | Idx += FilenameLen; |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1480 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
| 1481 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | // Parse the line entries |
| 1485 | std::vector<LineEntry> Entries; |
| 1486 | while (Idx < Record.size()) { |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1487 | int FID = FileIDs[Record[Idx++]]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1488 | |
| 1489 | // Extract the line entries |
| 1490 | unsigned NumEntries = Record[Idx++]; |
| 1491 | Entries.clear(); |
| 1492 | Entries.reserve(NumEntries); |
| 1493 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1494 | unsigned FileOffset = Record[Idx++]; |
| 1495 | unsigned LineNo = Record[Idx++]; |
| 1496 | int FilenameID = Record[Idx++]; |
| 1497 | SrcMgr::CharacteristicKind FileKind |
| 1498 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1499 | unsigned IncludeOffset = Record[Idx++]; |
| 1500 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1501 | FileKind, IncludeOffset)); |
| 1502 | } |
| 1503 | LineTable.AddEntry(FID, Entries); |
| 1504 | } |
| 1505 | |
| 1506 | return false; |
| 1507 | } |
| 1508 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1509 | /// \brief Read the source manager block |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1510 | PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock() { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1511 | using namespace SrcMgr; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1512 | if (Stream.EnterSubBlock(pch::SOURCE_MANAGER_BLOCK_ID)) { |
| 1513 | Error("Malformed source manager block record"); |
| 1514 | return Failure; |
| 1515 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1516 | |
| 1517 | SourceManager &SourceMgr = Context.getSourceManager(); |
| 1518 | RecordData Record; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1519 | unsigned NumHeaderInfos = 0; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1520 | while (true) { |
| 1521 | unsigned Code = Stream.ReadCode(); |
| 1522 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1523 | if (Stream.ReadBlockEnd()) { |
| 1524 | Error("Error at end of Source Manager block"); |
| 1525 | return Failure; |
| 1526 | } |
| 1527 | |
| 1528 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1532 | // No known subblocks, always skip them. |
| 1533 | Stream.ReadSubBlockID(); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1534 | if (Stream.SkipBlock()) { |
| 1535 | Error("Malformed block record"); |
| 1536 | return Failure; |
| 1537 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1538 | continue; |
| 1539 | } |
| 1540 | |
| 1541 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1542 | Stream.ReadAbbrevRecord(); |
| 1543 | continue; |
| 1544 | } |
| 1545 | |
| 1546 | // Read a record. |
| 1547 | const char *BlobStart; |
| 1548 | unsigned BlobLen; |
| 1549 | Record.clear(); |
| 1550 | switch (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1551 | default: // Default behavior: ignore. |
| 1552 | break; |
| 1553 | |
| 1554 | case pch::SM_SLOC_FILE_ENTRY: { |
| 1555 | // FIXME: We would really like to delay the creation of this |
| 1556 | // FileEntry until it is actually required, e.g., when producing |
| 1557 | // a diagnostic with a source location in this file. |
| 1558 | const FileEntry *File |
| 1559 | = PP.getFileManager().getFile(BlobStart, BlobStart + BlobLen); |
| 1560 | // FIXME: Error recovery if file cannot be found. |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1561 | FileID ID = SourceMgr.createFileID(File, |
| 1562 | SourceLocation::getFromRawEncoding(Record[1]), |
| 1563 | (CharacteristicKind)Record[2]); |
| 1564 | if (Record[3]) |
| 1565 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(ID).getFile()) |
| 1566 | .setHasLineDirectives(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1567 | break; |
| 1568 | } |
| 1569 | |
| 1570 | case pch::SM_SLOC_BUFFER_ENTRY: { |
| 1571 | const char *Name = BlobStart; |
| 1572 | unsigned Code = Stream.ReadCode(); |
| 1573 | Record.clear(); |
| 1574 | unsigned RecCode = Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 1575 | assert(RecCode == pch::SM_SLOC_BUFFER_BLOB && "Ill-formed PCH file"); |
Douglas Gregor | 6a2bfb2 | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 1576 | (void)RecCode; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1577 | llvm::MemoryBuffer *Buffer |
| 1578 | = llvm::MemoryBuffer::getMemBuffer(BlobStart, |
| 1579 | BlobStart + BlobLen - 1, |
| 1580 | Name); |
| 1581 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer); |
| 1582 | |
| 1583 | if (strcmp(Name, "<built-in>") == 0 |
| 1584 | && CheckPredefinesBuffer(BlobStart, BlobLen - 1, BufferID)) |
| 1585 | return IgnorePCH; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1586 | break; |
| 1587 | } |
| 1588 | |
| 1589 | case pch::SM_SLOC_INSTANTIATION_ENTRY: { |
| 1590 | SourceLocation SpellingLoc |
| 1591 | = SourceLocation::getFromRawEncoding(Record[1]); |
| 1592 | SourceMgr.createInstantiationLoc( |
| 1593 | SpellingLoc, |
| 1594 | SourceLocation::getFromRawEncoding(Record[2]), |
| 1595 | SourceLocation::getFromRawEncoding(Record[3]), |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1596 | Record[4]); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1597 | break; |
| 1598 | } |
| 1599 | |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1600 | case pch::SM_LINE_TABLE: |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1601 | if (ParseLineTable(SourceMgr, Record)) |
| 1602 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1603 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1604 | |
| 1605 | case pch::SM_HEADER_FILE_INFO: { |
| 1606 | HeaderFileInfo HFI; |
| 1607 | HFI.isImport = Record[0]; |
| 1608 | HFI.DirInfo = Record[1]; |
| 1609 | HFI.NumIncludes = Record[2]; |
| 1610 | HFI.ControllingMacroID = Record[3]; |
| 1611 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, NumHeaderInfos++); |
| 1612 | break; |
| 1613 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1614 | } |
| 1615 | } |
| 1616 | } |
| 1617 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1618 | void PCHReader::ReadMacroRecord(uint64_t Offset) { |
| 1619 | // Keep track of where we are in the stream, then jump back there |
| 1620 | // after reading this macro. |
| 1621 | SavedStreamPosition SavedPosition(Stream); |
| 1622 | |
| 1623 | Stream.JumpToBit(Offset); |
| 1624 | RecordData Record; |
| 1625 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1626 | MacroInfo *Macro = 0; |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 1627 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1628 | while (true) { |
| 1629 | unsigned Code = Stream.ReadCode(); |
| 1630 | switch (Code) { |
| 1631 | case llvm::bitc::END_BLOCK: |
| 1632 | return; |
| 1633 | |
| 1634 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1635 | // No known subblocks, always skip them. |
| 1636 | Stream.ReadSubBlockID(); |
| 1637 | if (Stream.SkipBlock()) { |
| 1638 | Error("Malformed block record"); |
| 1639 | return; |
| 1640 | } |
| 1641 | continue; |
| 1642 | |
| 1643 | case llvm::bitc::DEFINE_ABBREV: |
| 1644 | Stream.ReadAbbrevRecord(); |
| 1645 | continue; |
| 1646 | default: break; |
| 1647 | } |
| 1648 | |
| 1649 | // Read a record. |
| 1650 | Record.clear(); |
| 1651 | pch::PreprocessorRecordTypes RecType = |
| 1652 | (pch::PreprocessorRecordTypes)Stream.ReadRecord(Code, Record); |
| 1653 | switch (RecType) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1654 | case pch::PP_MACRO_OBJECT_LIKE: |
| 1655 | case pch::PP_MACRO_FUNCTION_LIKE: { |
| 1656 | // If we already have a macro, that means that we've hit the end |
| 1657 | // of the definition of the macro we were looking for. We're |
| 1658 | // done. |
| 1659 | if (Macro) |
| 1660 | return; |
| 1661 | |
| 1662 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1663 | if (II == 0) { |
| 1664 | Error("Macro must have a name"); |
| 1665 | return; |
| 1666 | } |
| 1667 | SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[1]); |
| 1668 | bool isUsed = Record[2]; |
| 1669 | |
| 1670 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
| 1671 | MI->setIsUsed(isUsed); |
| 1672 | |
| 1673 | if (RecType == pch::PP_MACRO_FUNCTION_LIKE) { |
| 1674 | // Decode function-like macro info. |
| 1675 | bool isC99VarArgs = Record[3]; |
| 1676 | bool isGNUVarArgs = Record[4]; |
| 1677 | MacroArgs.clear(); |
| 1678 | unsigned NumArgs = Record[5]; |
| 1679 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1680 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1681 | |
| 1682 | // Install function-like macro info. |
| 1683 | MI->setIsFunctionLike(); |
| 1684 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1685 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1686 | MI->setArgumentList(&MacroArgs[0], MacroArgs.size(), |
| 1687 | PP.getPreprocessorAllocator()); |
| 1688 | } |
| 1689 | |
| 1690 | // Finally, install the macro. |
| 1691 | PP.setMacroInfo(II, MI); |
| 1692 | |
| 1693 | // Remember that we saw this macro last so that we add the tokens that |
| 1694 | // form its body to it. |
| 1695 | Macro = MI; |
| 1696 | ++NumMacrosRead; |
| 1697 | break; |
| 1698 | } |
| 1699 | |
| 1700 | case pch::PP_TOKEN: { |
| 1701 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1702 | // erroneous, just pretend we didn't see this. |
| 1703 | if (Macro == 0) break; |
| 1704 | |
| 1705 | Token Tok; |
| 1706 | Tok.startToken(); |
| 1707 | Tok.setLocation(SourceLocation::getFromRawEncoding(Record[0])); |
| 1708 | Tok.setLength(Record[1]); |
| 1709 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1710 | Tok.setIdentifierInfo(II); |
| 1711 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1712 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1713 | Macro->AddTokenToBody(Tok); |
| 1714 | break; |
| 1715 | } |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 1716 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1720 | PCHReader::PCHReadResult |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1721 | PCHReader::ReadPCHBlock() { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1722 | if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) { |
| 1723 | Error("Malformed block record"); |
| 1724 | return Failure; |
| 1725 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1726 | |
| 1727 | // Read all of the records and blocks for the PCH file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1728 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1729 | while (!Stream.AtEndOfStream()) { |
| 1730 | unsigned Code = Stream.ReadCode(); |
| 1731 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1732 | if (Stream.ReadBlockEnd()) { |
| 1733 | Error("Error at end of module block"); |
| 1734 | return Failure; |
| 1735 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1737 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1741 | switch (Stream.ReadSubBlockID()) { |
| 1742 | case pch::DECLS_BLOCK_ID: // Skip decls block (lazily loaded) |
| 1743 | case pch::TYPES_BLOCK_ID: // Skip types block (lazily loaded) |
| 1744 | default: // Skip unknown content. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1745 | if (Stream.SkipBlock()) { |
| 1746 | Error("Malformed block record"); |
| 1747 | return Failure; |
| 1748 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1749 | break; |
| 1750 | |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1751 | case pch::PREPROCESSOR_BLOCK_ID: |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1752 | if (Stream.SkipBlock()) { |
| 1753 | Error("Malformed block record"); |
| 1754 | return Failure; |
| 1755 | } |
| 1756 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1757 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1758 | case pch::SOURCE_MANAGER_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1759 | switch (ReadSourceManagerBlock()) { |
| 1760 | case Success: |
| 1761 | break; |
| 1762 | |
| 1763 | case Failure: |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1764 | Error("Malformed source manager block"); |
| 1765 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1766 | |
| 1767 | case IgnorePCH: |
| 1768 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1769 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1770 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1771 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1772 | continue; |
| 1773 | } |
| 1774 | |
| 1775 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1776 | Stream.ReadAbbrevRecord(); |
| 1777 | continue; |
| 1778 | } |
| 1779 | |
| 1780 | // Read and process a record. |
| 1781 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1782 | const char *BlobStart = 0; |
| 1783 | unsigned BlobLen = 0; |
| 1784 | switch ((pch::PCHRecordTypes)Stream.ReadRecord(Code, Record, |
| 1785 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1786 | default: // Default behavior: ignore. |
| 1787 | break; |
| 1788 | |
| 1789 | case pch::TYPE_OFFSET: |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1790 | if (!TypesLoaded.empty()) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1791 | Error("Duplicate TYPE_OFFSET record in PCH file"); |
| 1792 | return Failure; |
| 1793 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1794 | TypeOffsets = (const uint64_t *)BlobStart; |
| 1795 | TypesLoaded.resize(Record[0]); |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1796 | break; |
| 1797 | |
| 1798 | case pch::DECL_OFFSET: |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1799 | if (!DeclsLoaded.empty()) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1800 | Error("Duplicate DECL_OFFSET record in PCH file"); |
| 1801 | return Failure; |
| 1802 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1803 | DeclOffsets = (const uint64_t *)BlobStart; |
| 1804 | DeclsLoaded.resize(Record[0]); |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1805 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1806 | |
| 1807 | case pch::LANGUAGE_OPTIONS: |
| 1808 | if (ParseLanguageOptions(Record)) |
| 1809 | return IgnorePCH; |
| 1810 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1811 | |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1812 | case pch::TARGET_TRIPLE: { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1813 | std::string TargetTriple(BlobStart, BlobLen); |
| 1814 | if (TargetTriple != Context.Target.getTargetTriple()) { |
| 1815 | Diag(diag::warn_pch_target_triple) |
| 1816 | << TargetTriple << Context.Target.getTargetTriple(); |
| 1817 | Diag(diag::note_ignoring_pch) << FileName; |
| 1818 | return IgnorePCH; |
| 1819 | } |
| 1820 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1821 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1822 | |
| 1823 | case pch::IDENTIFIER_TABLE: |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1824 | IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1825 | if (Record[0]) { |
| 1826 | IdentifierLookupTable |
| 1827 | = PCHIdentifierLookupTable::Create( |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1828 | (const unsigned char *)IdentifierTableData + Record[0], |
| 1829 | (const unsigned char *)IdentifierTableData, |
| 1830 | PCHIdentifierLookupTrait(*this)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1831 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 1832 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1833 | break; |
| 1834 | |
| 1835 | case pch::IDENTIFIER_OFFSET: |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1836 | if (!IdentifiersLoaded.empty()) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1837 | Error("Duplicate IDENTIFIER_OFFSET record in PCH file"); |
| 1838 | return Failure; |
| 1839 | } |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1840 | IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1841 | IdentifiersLoaded.resize(Record[0]); |
Douglas Gregor | 8c5a760 | 2009-04-25 23:30:02 +0000 | [diff] [blame] | 1842 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1843 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1844 | |
| 1845 | case pch::EXTERNAL_DEFINITIONS: |
| 1846 | if (!ExternalDefinitions.empty()) { |
| 1847 | Error("Duplicate EXTERNAL_DEFINITIONS record in PCH file"); |
| 1848 | return Failure; |
| 1849 | } |
| 1850 | ExternalDefinitions.swap(Record); |
| 1851 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1852 | |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1853 | case pch::SPECIAL_TYPES: |
| 1854 | SpecialTypes.swap(Record); |
| 1855 | break; |
| 1856 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1857 | case pch::STATISTICS: |
| 1858 | TotalNumStatements = Record[0]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1859 | TotalNumMacros = Record[1]; |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1860 | TotalLexicalDeclContexts = Record[2]; |
| 1861 | TotalVisibleDeclContexts = Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1862 | break; |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 1863 | case pch::TENTATIVE_DEFINITIONS: |
| 1864 | if (!TentativeDefinitions.empty()) { |
| 1865 | Error("Duplicate TENTATIVE_DEFINITIONS record in PCH file"); |
| 1866 | return Failure; |
| 1867 | } |
| 1868 | TentativeDefinitions.swap(Record); |
| 1869 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1870 | |
| 1871 | case pch::LOCALLY_SCOPED_EXTERNAL_DECLS: |
| 1872 | if (!LocallyScopedExternalDecls.empty()) { |
| 1873 | Error("Duplicate LOCALLY_SCOPED_EXTERNAL_DECLS record in PCH file"); |
| 1874 | return Failure; |
| 1875 | } |
| 1876 | LocallyScopedExternalDecls.swap(Record); |
| 1877 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1878 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1879 | case pch::SELECTOR_OFFSETS: |
| 1880 | SelectorOffsets = (const uint32_t *)BlobStart; |
| 1881 | TotalNumSelectors = Record[0]; |
| 1882 | SelectorsLoaded.resize(TotalNumSelectors); |
| 1883 | break; |
| 1884 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1885 | case pch::METHOD_POOL: |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1886 | MethodPoolLookupTableData = (const unsigned char *)BlobStart; |
| 1887 | if (Record[0]) |
| 1888 | MethodPoolLookupTable |
| 1889 | = PCHMethodPoolLookupTable::Create( |
| 1890 | MethodPoolLookupTableData + Record[0], |
| 1891 | MethodPoolLookupTableData, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1892 | PCHMethodPoolLookupTrait(*this)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1893 | TotalSelectorsInMethodPool = Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1894 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1895 | |
| 1896 | case pch::PP_COUNTER_VALUE: |
| 1897 | if (!Record.empty()) |
| 1898 | PP.setCounterValue(Record[0]); |
| 1899 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1900 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1901 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1902 | Error("Premature end of bitstream"); |
| 1903 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1906 | PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1907 | // Set the PCH file name. |
| 1908 | this->FileName = FileName; |
| 1909 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1910 | // Open the PCH file. |
| 1911 | std::string ErrStr; |
| 1912 | Buffer.reset(llvm::MemoryBuffer::getFile(FileName.c_str(), &ErrStr)); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1913 | if (!Buffer) { |
| 1914 | Error(ErrStr.c_str()); |
| 1915 | return IgnorePCH; |
| 1916 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1917 | |
| 1918 | // Initialize the stream |
| 1919 | Stream.init((const unsigned char *)Buffer->getBufferStart(), |
| 1920 | (const unsigned char *)Buffer->getBufferEnd()); |
| 1921 | |
| 1922 | // Sniff for the signature. |
| 1923 | if (Stream.Read(8) != 'C' || |
| 1924 | Stream.Read(8) != 'P' || |
| 1925 | Stream.Read(8) != 'C' || |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1926 | Stream.Read(8) != 'H') { |
| 1927 | Error("Not a PCH file"); |
| 1928 | return IgnorePCH; |
| 1929 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1930 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1931 | while (!Stream.AtEndOfStream()) { |
| 1932 | unsigned Code = Stream.ReadCode(); |
| 1933 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1934 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
| 1935 | Error("Invalid record at top-level"); |
| 1936 | return Failure; |
| 1937 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1938 | |
| 1939 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1940 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1941 | // We only know the PCH subblock ID. |
| 1942 | switch (BlockID) { |
| 1943 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1944 | if (Stream.ReadBlockInfoBlock()) { |
| 1945 | Error("Malformed BlockInfoBlock"); |
| 1946 | return Failure; |
| 1947 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1948 | break; |
| 1949 | case pch::PCH_BLOCK_ID: |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1950 | switch (ReadPCHBlock()) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1951 | case Success: |
| 1952 | break; |
| 1953 | |
| 1954 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1955 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1956 | |
| 1957 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1958 | // FIXME: We could consider reading through to the end of this |
| 1959 | // PCH block, skipping subblocks, to see if there are other |
| 1960 | // PCH blocks elsewhere. |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1961 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1962 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1963 | break; |
| 1964 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1965 | if (Stream.SkipBlock()) { |
| 1966 | Error("Malformed block record"); |
| 1967 | return Failure; |
| 1968 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1969 | break; |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | // Load the translation unit declaration |
| 1974 | ReadDeclRecord(DeclOffsets[0], 0); |
| 1975 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1976 | // Initialization of builtins and library builtins occurs before the |
| 1977 | // PCH file is read, so there may be some identifiers that were |
| 1978 | // loaded into the IdentifierTable before we intercepted the |
| 1979 | // creation of identifiers. Iterate through the list of known |
| 1980 | // identifiers and determine whether we have to establish |
| 1981 | // preprocessor definitions or top-level identifier declaration |
| 1982 | // chains for those identifiers. |
| 1983 | // |
| 1984 | // We copy the IdentifierInfo pointers to a small vector first, |
| 1985 | // since de-serializing declarations or macro definitions can add |
| 1986 | // new entries into the identifier table, invalidating the |
| 1987 | // iterators. |
| 1988 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 1989 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 1990 | IdEnd = PP.getIdentifierTable().end(); |
| 1991 | Id != IdEnd; ++Id) |
| 1992 | Identifiers.push_back(Id->second); |
| 1993 | PCHIdentifierLookupTable *IdTable |
| 1994 | = (PCHIdentifierLookupTable *)IdentifierLookupTable; |
| 1995 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 1996 | IdentifierInfo *II = Identifiers[I]; |
| 1997 | // Look in the on-disk hash table for an entry for |
| 1998 | PCHIdentifierLookupTrait Info(*this, II); |
| 1999 | std::pair<const char*, unsigned> Key(II->getName(), II->getLength()); |
| 2000 | PCHIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
| 2001 | if (Pos == IdTable->end()) |
| 2002 | continue; |
| 2003 | |
| 2004 | // Dereferencing the iterator has the effect of populating the |
| 2005 | // IdentifierInfo node with the various declarations it needs. |
| 2006 | (void)*Pos; |
| 2007 | } |
| 2008 | |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2009 | // Load the special types. |
| 2010 | Context.setBuiltinVaListType( |
| 2011 | GetType(SpecialTypes[pch::SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | 319ac89 | 2009-04-23 22:29:11 +0000 | [diff] [blame] | 2012 | if (unsigned Id = SpecialTypes[pch::SPECIAL_TYPE_OBJC_ID]) |
| 2013 | Context.setObjCIdType(GetType(Id)); |
| 2014 | if (unsigned Sel = SpecialTypes[pch::SPECIAL_TYPE_OBJC_SELECTOR]) |
| 2015 | Context.setObjCSelType(GetType(Sel)); |
| 2016 | if (unsigned Proto = SpecialTypes[pch::SPECIAL_TYPE_OBJC_PROTOCOL]) |
| 2017 | Context.setObjCProtoType(GetType(Proto)); |
| 2018 | if (unsigned Class = SpecialTypes[pch::SPECIAL_TYPE_OBJC_CLASS]) |
| 2019 | Context.setObjCClassType(GetType(Class)); |
| 2020 | if (unsigned String = SpecialTypes[pch::SPECIAL_TYPE_CF_CONSTANT_STRING]) |
| 2021 | Context.setCFConstantStringType(GetType(String)); |
| 2022 | if (unsigned FastEnum |
| 2023 | = SpecialTypes[pch::SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
| 2024 | Context.setObjCFastEnumerationStateType(GetType(FastEnum)); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2025 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2026 | return Success; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2029 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2030 | /// structure. |
| 2031 | /// |
| 2032 | /// This routine compares the language options used to generate the |
| 2033 | /// PCH file against the language options set for the current |
| 2034 | /// compilation. For each option, we classify differences between the |
| 2035 | /// two compiler states as either "benign" or "important". Benign |
| 2036 | /// differences don't matter, and we accept them without complaint |
| 2037 | /// (and without modifying the language options). Differences between |
| 2038 | /// the states for important options cause the PCH file to be |
| 2039 | /// unusable, so we emit a warning and return true to indicate that |
| 2040 | /// there was an error. |
| 2041 | /// |
| 2042 | /// \returns true if the PCH file is unacceptable, false otherwise. |
| 2043 | bool PCHReader::ParseLanguageOptions( |
| 2044 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
| 2045 | const LangOptions &LangOpts = Context.getLangOptions(); |
| 2046 | #define PARSE_LANGOPT_BENIGN(Option) ++Idx |
| 2047 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 2048 | if (Record[Idx] != LangOpts.Option) { \ |
| 2049 | Diag(DiagID) << (unsigned)Record[Idx] << LangOpts.Option; \ |
| 2050 | Diag(diag::note_ignoring_pch) << FileName; \ |
| 2051 | return true; \ |
| 2052 | } \ |
| 2053 | ++Idx |
| 2054 | |
| 2055 | unsigned Idx = 0; |
| 2056 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 2057 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 2058 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 2059 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 2060 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
| 2061 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 2062 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 2063 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 2064 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 2065 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
| 2066 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 2067 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 2068 | PARSE_LANGOPT_IMPORTANT(NoExtensions, diag::warn_pch_extensions); |
| 2069 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 2070 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 2071 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 2072 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
| 2073 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 2074 | PARSE_LANGOPT_BENIGN(Boolean); |
| 2075 | PARSE_LANGOPT_BENIGN(WritableStrings); |
| 2076 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
| 2077 | diag::warn_pch_lax_vector_conversions); |
| 2078 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
| 2079 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 2080 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 2081 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
| 2082 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
| 2083 | diag::warn_pch_thread_safe_statics); |
| 2084 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 2085 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 2086 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
| 2087 | PARSE_LANGOPT_IMPORTANT(OverflowChecking, diag::warn_pch_overflow_checking); |
| 2088 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
| 2089 | diag::warn_pch_heinous_extensions); |
| 2090 | // FIXME: Most of the options below are benign if the macro wasn't |
| 2091 | // used. Unfortunately, this means that a PCH compiled without |
| 2092 | // optimization can't be used with optimization turned on, even |
| 2093 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 2094 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 2095 | // doesn't matter. We could consider making this some special kind |
| 2096 | // of check. |
| 2097 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 2098 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 2099 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 2100 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 2101 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 2102 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 2103 | if ((LangOpts.getGCMode() != 0) != (Record[Idx] != 0)) { |
| 2104 | Diag(diag::warn_pch_gc_mode) |
| 2105 | << (unsigned)Record[Idx] << LangOpts.getGCMode(); |
| 2106 | Diag(diag::note_ignoring_pch) << FileName; |
| 2107 | return true; |
| 2108 | } |
| 2109 | ++Idx; |
| 2110 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
| 2111 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
| 2112 | #undef PARSE_LANGOPT_IRRELEVANT |
| 2113 | #undef PARSE_LANGOPT_BENIGN |
| 2114 | |
| 2115 | return false; |
| 2116 | } |
| 2117 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2118 | /// \brief Read and return the type at the given offset. |
| 2119 | /// |
| 2120 | /// This routine actually reads the record corresponding to the type |
| 2121 | /// at the given offset in the bitstream. It is a helper routine for |
| 2122 | /// GetType, which deals with reading type IDs. |
| 2123 | QualType PCHReader::ReadTypeRecord(uint64_t Offset) { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2124 | // Keep track of where we are in the stream, then jump back there |
| 2125 | // after reading this type. |
| 2126 | SavedStreamPosition SavedPosition(Stream); |
| 2127 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2128 | Stream.JumpToBit(Offset); |
| 2129 | RecordData Record; |
| 2130 | unsigned Code = Stream.ReadCode(); |
| 2131 | switch ((pch::TypeCode)Stream.ReadRecord(Code, Record)) { |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2132 | case pch::TYPE_EXT_QUAL: { |
| 2133 | assert(Record.size() == 3 && |
| 2134 | "Incorrect encoding of extended qualifier type"); |
| 2135 | QualType Base = GetType(Record[0]); |
| 2136 | QualType::GCAttrTypes GCAttr = (QualType::GCAttrTypes)Record[1]; |
| 2137 | unsigned AddressSpace = Record[2]; |
| 2138 | |
| 2139 | QualType T = Base; |
| 2140 | if (GCAttr != QualType::GCNone) |
| 2141 | T = Context.getObjCGCQualType(T, GCAttr); |
| 2142 | if (AddressSpace) |
| 2143 | T = Context.getAddrSpaceQualType(T, AddressSpace); |
| 2144 | return T; |
| 2145 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2146 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2147 | case pch::TYPE_FIXED_WIDTH_INT: { |
| 2148 | assert(Record.size() == 2 && "Incorrect encoding of fixed-width int type"); |
| 2149 | return Context.getFixedWidthIntType(Record[0], Record[1]); |
| 2150 | } |
| 2151 | |
| 2152 | case pch::TYPE_COMPLEX: { |
| 2153 | assert(Record.size() == 1 && "Incorrect encoding of complex type"); |
| 2154 | QualType ElemType = GetType(Record[0]); |
| 2155 | return Context.getComplexType(ElemType); |
| 2156 | } |
| 2157 | |
| 2158 | case pch::TYPE_POINTER: { |
| 2159 | assert(Record.size() == 1 && "Incorrect encoding of pointer type"); |
| 2160 | QualType PointeeType = GetType(Record[0]); |
| 2161 | return Context.getPointerType(PointeeType); |
| 2162 | } |
| 2163 | |
| 2164 | case pch::TYPE_BLOCK_POINTER: { |
| 2165 | assert(Record.size() == 1 && "Incorrect encoding of block pointer type"); |
| 2166 | QualType PointeeType = GetType(Record[0]); |
| 2167 | return Context.getBlockPointerType(PointeeType); |
| 2168 | } |
| 2169 | |
| 2170 | case pch::TYPE_LVALUE_REFERENCE: { |
| 2171 | assert(Record.size() == 1 && "Incorrect encoding of lvalue reference type"); |
| 2172 | QualType PointeeType = GetType(Record[0]); |
| 2173 | return Context.getLValueReferenceType(PointeeType); |
| 2174 | } |
| 2175 | |
| 2176 | case pch::TYPE_RVALUE_REFERENCE: { |
| 2177 | assert(Record.size() == 1 && "Incorrect encoding of rvalue reference type"); |
| 2178 | QualType PointeeType = GetType(Record[0]); |
| 2179 | return Context.getRValueReferenceType(PointeeType); |
| 2180 | } |
| 2181 | |
| 2182 | case pch::TYPE_MEMBER_POINTER: { |
| 2183 | assert(Record.size() == 1 && "Incorrect encoding of member pointer type"); |
| 2184 | QualType PointeeType = GetType(Record[0]); |
| 2185 | QualType ClassType = GetType(Record[1]); |
| 2186 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
| 2187 | } |
| 2188 | |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2189 | case pch::TYPE_CONSTANT_ARRAY: { |
| 2190 | QualType ElementType = GetType(Record[0]); |
| 2191 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2192 | unsigned IndexTypeQuals = Record[2]; |
| 2193 | unsigned Idx = 3; |
| 2194 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 2195 | return Context.getConstantArrayType(ElementType, Size, ASM, IndexTypeQuals); |
| 2196 | } |
| 2197 | |
| 2198 | case pch::TYPE_INCOMPLETE_ARRAY: { |
| 2199 | QualType ElementType = GetType(Record[0]); |
| 2200 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2201 | unsigned IndexTypeQuals = Record[2]; |
| 2202 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
| 2203 | } |
| 2204 | |
| 2205 | case pch::TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2206 | QualType ElementType = GetType(Record[0]); |
| 2207 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2208 | unsigned IndexTypeQuals = Record[2]; |
| 2209 | return Context.getVariableArrayType(ElementType, ReadExpr(), |
| 2210 | ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | case pch::TYPE_VECTOR: { |
| 2214 | if (Record.size() != 2) { |
| 2215 | Error("Incorrect encoding of vector type in PCH file"); |
| 2216 | return QualType(); |
| 2217 | } |
| 2218 | |
| 2219 | QualType ElementType = GetType(Record[0]); |
| 2220 | unsigned NumElements = Record[1]; |
| 2221 | return Context.getVectorType(ElementType, NumElements); |
| 2222 | } |
| 2223 | |
| 2224 | case pch::TYPE_EXT_VECTOR: { |
| 2225 | if (Record.size() != 2) { |
| 2226 | Error("Incorrect encoding of extended vector type in PCH file"); |
| 2227 | return QualType(); |
| 2228 | } |
| 2229 | |
| 2230 | QualType ElementType = GetType(Record[0]); |
| 2231 | unsigned NumElements = Record[1]; |
| 2232 | return Context.getExtVectorType(ElementType, NumElements); |
| 2233 | } |
| 2234 | |
| 2235 | case pch::TYPE_FUNCTION_NO_PROTO: { |
| 2236 | if (Record.size() != 1) { |
| 2237 | Error("Incorrect encoding of no-proto function type"); |
| 2238 | return QualType(); |
| 2239 | } |
| 2240 | QualType ResultType = GetType(Record[0]); |
| 2241 | return Context.getFunctionNoProtoType(ResultType); |
| 2242 | } |
| 2243 | |
| 2244 | case pch::TYPE_FUNCTION_PROTO: { |
| 2245 | QualType ResultType = GetType(Record[0]); |
| 2246 | unsigned Idx = 1; |
| 2247 | unsigned NumParams = Record[Idx++]; |
| 2248 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 2249 | for (unsigned I = 0; I != NumParams; ++I) |
| 2250 | ParamTypes.push_back(GetType(Record[Idx++])); |
| 2251 | bool isVariadic = Record[Idx++]; |
| 2252 | unsigned Quals = Record[Idx++]; |
| 2253 | return Context.getFunctionType(ResultType, &ParamTypes[0], NumParams, |
| 2254 | isVariadic, Quals); |
| 2255 | } |
| 2256 | |
| 2257 | case pch::TYPE_TYPEDEF: |
| 2258 | assert(Record.size() == 1 && "Incorrect encoding of typedef type"); |
| 2259 | return Context.getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0]))); |
| 2260 | |
| 2261 | case pch::TYPE_TYPEOF_EXPR: |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2262 | return Context.getTypeOfExprType(ReadExpr()); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2263 | |
| 2264 | case pch::TYPE_TYPEOF: { |
| 2265 | if (Record.size() != 1) { |
| 2266 | Error("Incorrect encoding of typeof(type) in PCH file"); |
| 2267 | return QualType(); |
| 2268 | } |
| 2269 | QualType UnderlyingType = GetType(Record[0]); |
| 2270 | return Context.getTypeOfType(UnderlyingType); |
| 2271 | } |
| 2272 | |
| 2273 | case pch::TYPE_RECORD: |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 2274 | assert(Record.size() == 1 && "Incorrect encoding of record type"); |
| 2275 | return Context.getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0]))); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2276 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2277 | case pch::TYPE_ENUM: |
| 2278 | assert(Record.size() == 1 && "Incorrect encoding of enum type"); |
| 2279 | return Context.getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0]))); |
| 2280 | |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2281 | case pch::TYPE_OBJC_INTERFACE: |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 2282 | assert(Record.size() == 1 && "Incorrect encoding of objc interface type"); |
| 2283 | return Context.getObjCInterfaceType( |
| 2284 | cast<ObjCInterfaceDecl>(GetDecl(Record[0]))); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2285 | |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2286 | case pch::TYPE_OBJC_QUALIFIED_INTERFACE: { |
| 2287 | unsigned Idx = 0; |
| 2288 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
| 2289 | unsigned NumProtos = Record[Idx++]; |
| 2290 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 2291 | for (unsigned I = 0; I != NumProtos; ++I) |
| 2292 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
| 2293 | return Context.getObjCQualifiedInterfaceType(ItfD, &Protos[0], NumProtos); |
| 2294 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2295 | |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2296 | case pch::TYPE_OBJC_QUALIFIED_ID: { |
| 2297 | unsigned Idx = 0; |
| 2298 | unsigned NumProtos = Record[Idx++]; |
| 2299 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 2300 | for (unsigned I = 0; I != NumProtos; ++I) |
| 2301 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
| 2302 | return Context.getObjCQualifiedIdType(&Protos[0], NumProtos); |
| 2303 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2304 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2305 | // Suppress a GCC warning |
| 2306 | return QualType(); |
| 2307 | } |
| 2308 | |
| 2309 | /// \brief Note that we have loaded the declaration with the given |
| 2310 | /// Index. |
| 2311 | /// |
| 2312 | /// This routine notes that this declaration has already been loaded, |
| 2313 | /// so that future GetDecl calls will return this declaration rather |
| 2314 | /// than trying to load a new declaration. |
| 2315 | inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) { |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2316 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 2317 | DeclsLoaded[Index] = D; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 2320 | /// \brief Determine whether the consumer will be interested in seeing |
| 2321 | /// this declaration (via HandleTopLevelDecl). |
| 2322 | /// |
| 2323 | /// This routine should return true for anything that might affect |
| 2324 | /// code generation, e.g., inline function definitions, Objective-C |
| 2325 | /// declarations with metadata, etc. |
| 2326 | static bool isConsumerInterestedIn(Decl *D) { |
| 2327 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) |
| 2328 | return Var->isFileVarDecl() && Var->getInit(); |
| 2329 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) |
| 2330 | return Func->isThisDeclarationADefinition(); |
| 2331 | return isa<ObjCProtocolDecl>(D); |
| 2332 | } |
| 2333 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2334 | /// \brief Read the declaration at the given offset from the PCH file. |
| 2335 | Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2336 | // Keep track of where we are in the stream, then jump back there |
| 2337 | // after reading this declaration. |
| 2338 | SavedStreamPosition SavedPosition(Stream); |
| 2339 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2340 | Decl *D = 0; |
| 2341 | Stream.JumpToBit(Offset); |
| 2342 | RecordData Record; |
| 2343 | unsigned Code = Stream.ReadCode(); |
| 2344 | unsigned Idx = 0; |
| 2345 | PCHDeclReader Reader(*this, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2346 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2347 | switch ((pch::DeclCode)Stream.ReadRecord(Code, Record)) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2348 | case pch::DECL_ATTR: |
| 2349 | case pch::DECL_CONTEXT_LEXICAL: |
| 2350 | case pch::DECL_CONTEXT_VISIBLE: |
| 2351 | assert(false && "Record cannot be de-serialized with ReadDeclRecord"); |
| 2352 | break; |
| 2353 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2354 | case pch::DECL_TRANSLATION_UNIT: |
| 2355 | assert(Index == 0 && "Translation unit must be at index 0"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2356 | D = Context.getTranslationUnitDecl(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2357 | break; |
| 2358 | |
| 2359 | case pch::DECL_TYPEDEF: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2360 | D = TypedefDecl::Create(Context, 0, SourceLocation(), 0, QualType()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2361 | break; |
| 2362 | } |
| 2363 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2364 | case pch::DECL_ENUM: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2365 | D = EnumDecl::Create(Context, 0, SourceLocation(), 0, 0); |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2366 | break; |
| 2367 | } |
| 2368 | |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 2369 | case pch::DECL_RECORD: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2370 | D = RecordDecl::Create(Context, TagDecl::TK_struct, 0, SourceLocation(), |
| 2371 | 0, 0); |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 2372 | break; |
| 2373 | } |
| 2374 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2375 | case pch::DECL_ENUM_CONSTANT: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2376 | D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(), |
| 2377 | 0, llvm::APSInt()); |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | } |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 2380 | |
| 2381 | case pch::DECL_FUNCTION: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2382 | D = FunctionDecl::Create(Context, 0, SourceLocation(), DeclarationName(), |
| 2383 | QualType()); |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 2384 | break; |
| 2385 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2386 | |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 2387 | case pch::DECL_OBJC_METHOD: { |
| 2388 | D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(), |
| 2389 | Selector(), QualType(), 0); |
| 2390 | break; |
| 2391 | } |
| 2392 | |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 2393 | case pch::DECL_OBJC_INTERFACE: { |
Steve Naroff | 33feeb0 | 2009-04-20 20:09:33 +0000 | [diff] [blame] | 2394 | D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0); |
| 2395 | break; |
| 2396 | } |
| 2397 | |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 2398 | case pch::DECL_OBJC_IVAR: { |
Steve Naroff | 33feeb0 | 2009-04-20 20:09:33 +0000 | [diff] [blame] | 2399 | D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), 0, QualType(), |
| 2400 | ObjCIvarDecl::None); |
| 2401 | break; |
| 2402 | } |
| 2403 | |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 2404 | case pch::DECL_OBJC_PROTOCOL: { |
| 2405 | D = ObjCProtocolDecl::Create(Context, 0, SourceLocation(), 0); |
| 2406 | break; |
| 2407 | } |
| 2408 | |
| 2409 | case pch::DECL_OBJC_AT_DEFS_FIELD: { |
| 2410 | D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(), 0, |
| 2411 | QualType(), 0); |
| 2412 | break; |
| 2413 | } |
| 2414 | |
| 2415 | case pch::DECL_OBJC_CLASS: { |
| 2416 | D = ObjCClassDecl::Create(Context, 0, SourceLocation()); |
| 2417 | break; |
| 2418 | } |
| 2419 | |
| 2420 | case pch::DECL_OBJC_FORWARD_PROTOCOL: { |
| 2421 | D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation()); |
| 2422 | break; |
| 2423 | } |
| 2424 | |
| 2425 | case pch::DECL_OBJC_CATEGORY: { |
| 2426 | D = ObjCCategoryDecl::Create(Context, 0, SourceLocation(), 0); |
| 2427 | break; |
| 2428 | } |
| 2429 | |
| 2430 | case pch::DECL_OBJC_CATEGORY_IMPL: { |
Douglas Gregor | 10b0e1f | 2009-04-23 02:53:57 +0000 | [diff] [blame] | 2431 | D = ObjCCategoryImplDecl::Create(Context, 0, SourceLocation(), 0, 0); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 2432 | break; |
| 2433 | } |
| 2434 | |
| 2435 | case pch::DECL_OBJC_IMPLEMENTATION: { |
Douglas Gregor | 8f36aba | 2009-04-23 03:23:08 +0000 | [diff] [blame] | 2436 | D = ObjCImplementationDecl::Create(Context, 0, SourceLocation(), 0, 0); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 2437 | break; |
| 2438 | } |
| 2439 | |
| 2440 | case pch::DECL_OBJC_COMPATIBLE_ALIAS: { |
Douglas Gregor | 17eee4a | 2009-04-23 03:51:49 +0000 | [diff] [blame] | 2441 | D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 2442 | break; |
| 2443 | } |
| 2444 | |
| 2445 | case pch::DECL_OBJC_PROPERTY: { |
Douglas Gregor | 70e5a14 | 2009-04-22 23:20:34 +0000 | [diff] [blame] | 2446 | D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, QualType()); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 2447 | break; |
| 2448 | } |
| 2449 | |
| 2450 | case pch::DECL_OBJC_PROPERTY_IMPL: { |
Douglas Gregor | 8818c4f | 2009-04-23 03:43:53 +0000 | [diff] [blame] | 2451 | D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(), |
| 2452 | SourceLocation(), 0, |
| 2453 | ObjCPropertyImplDecl::Dynamic, 0); |
Steve Naroff | 30833f8 | 2009-04-21 15:12:33 +0000 | [diff] [blame] | 2454 | break; |
| 2455 | } |
| 2456 | |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 2457 | case pch::DECL_FIELD: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2458 | D = FieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(), 0, |
| 2459 | false); |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 2460 | break; |
| 2461 | } |
| 2462 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2463 | case pch::DECL_VAR: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2464 | D = VarDecl::Create(Context, 0, SourceLocation(), 0, QualType(), |
| 2465 | VarDecl::None, SourceLocation()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2466 | break; |
| 2467 | } |
| 2468 | |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 2469 | case pch::DECL_PARM_VAR: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2470 | D = ParmVarDecl::Create(Context, 0, SourceLocation(), 0, QualType(), |
| 2471 | VarDecl::None, 0); |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | } |
| 2474 | |
| 2475 | case pch::DECL_ORIGINAL_PARM_VAR: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2476 | D = OriginalParmVarDecl::Create(Context, 0, SourceLocation(), 0, |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 2477 | QualType(), QualType(), VarDecl::None, |
| 2478 | 0); |
Douglas Gregor | 3a2f7e4 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 2479 | break; |
| 2480 | } |
| 2481 | |
Douglas Gregor | 1028bc6 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 2482 | case pch::DECL_FILE_SCOPE_ASM: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2483 | D = FileScopeAsmDecl::Create(Context, 0, SourceLocation(), 0); |
Douglas Gregor | 1028bc6 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 2484 | break; |
| 2485 | } |
| 2486 | |
| 2487 | case pch::DECL_BLOCK: { |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2488 | D = BlockDecl::Create(Context, 0, SourceLocation()); |
Douglas Gregor | 1028bc6 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 2489 | break; |
| 2490 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2493 | assert(D && "Unknown declaration reading PCH file"); |
Douglas Gregor | cb70bb2 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 2494 | if (D) { |
| 2495 | LoadedDecl(Index, D); |
| 2496 | Reader.Visit(D); |
| 2497 | } |
| 2498 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2499 | // If this declaration is also a declaration context, get the |
| 2500 | // offsets for its tables of lexical and visible declarations. |
| 2501 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 2502 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
| 2503 | if (Offsets.first || Offsets.second) { |
| 2504 | DC->setHasExternalLexicalStorage(Offsets.first != 0); |
| 2505 | DC->setHasExternalVisibleStorage(Offsets.second != 0); |
| 2506 | DeclContextOffsets[DC] = Offsets; |
| 2507 | } |
| 2508 | } |
| 2509 | assert(Idx == Record.size()); |
| 2510 | |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 2511 | // If we have deserialized a declaration that has a definition the |
| 2512 | // AST consumer might need to know about, notify the consumer |
| 2513 | // about that definition now or queue it for later. |
| 2514 | if (isConsumerInterestedIn(D)) { |
| 2515 | if (Consumer) { |
Douglas Gregor | ad38a85 | 2009-04-24 23:42:14 +0000 | [diff] [blame] | 2516 | DeclGroupRef DG(D); |
| 2517 | Consumer->HandleTopLevelDecl(DG); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 2518 | } else { |
| 2519 | InterestingDecls.push_back(D); |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 2520 | } |
| 2521 | } |
| 2522 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2523 | return D; |
| 2524 | } |
| 2525 | |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2526 | QualType PCHReader::GetType(pch::TypeID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2527 | unsigned Quals = ID & 0x07; |
| 2528 | unsigned Index = ID >> 3; |
| 2529 | |
| 2530 | if (Index < pch::NUM_PREDEF_TYPE_IDS) { |
| 2531 | QualType T; |
| 2532 | switch ((pch::PredefinedTypeIDs)Index) { |
| 2533 | case pch::PREDEF_TYPE_NULL_ID: return QualType(); |
| 2534 | case pch::PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 2535 | case pch::PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
| 2536 | |
| 2537 | case pch::PREDEF_TYPE_CHAR_U_ID: |
| 2538 | case pch::PREDEF_TYPE_CHAR_S_ID: |
| 2539 | // FIXME: Check that the signedness of CharTy is correct! |
| 2540 | T = Context.CharTy; |
| 2541 | break; |
| 2542 | |
| 2543 | case pch::PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 2544 | case pch::PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 2545 | case pch::PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 2546 | case pch::PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 2547 | case pch::PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 2548 | case pch::PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 2549 | case pch::PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 2550 | case pch::PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 2551 | case pch::PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 2552 | case pch::PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 2553 | case pch::PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 2554 | case pch::PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 2555 | case pch::PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 2556 | case pch::PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 2557 | case pch::PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 2558 | case pch::PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 2559 | } |
| 2560 | |
| 2561 | assert(!T.isNull() && "Unknown predefined type"); |
| 2562 | return T.getQualifiedType(Quals); |
| 2563 | } |
| 2564 | |
| 2565 | Index -= pch::NUM_PREDEF_TYPE_IDS; |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame^] | 2566 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2567 | if (!TypesLoaded[Index]) |
| 2568 | TypesLoaded[Index] = ReadTypeRecord(TypeOffsets[Index]).getTypePtr(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2569 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2570 | return QualType(TypesLoaded[Index], Quals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2573 | Decl *PCHReader::GetDecl(pch::DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2574 | if (ID == 0) |
| 2575 | return 0; |
| 2576 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2577 | if (ID > DeclsLoaded.size()) { |
| 2578 | Error("Declaration ID out-of-range for PCH file"); |
| 2579 | return 0; |
| 2580 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2582 | unsigned Index = ID - 1; |
| 2583 | if (!DeclsLoaded[Index]) |
| 2584 | ReadDeclRecord(DeclOffsets[Index], Index); |
| 2585 | |
| 2586 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 2589 | Stmt *PCHReader::GetStmt(uint64_t Offset) { |
| 2590 | // Keep track of where we are in the stream, then jump back there |
| 2591 | // after reading this declaration. |
| 2592 | SavedStreamPosition SavedPosition(Stream); |
| 2593 | |
| 2594 | Stream.JumpToBit(Offset); |
| 2595 | return ReadStmt(); |
| 2596 | } |
| 2597 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2598 | bool PCHReader::ReadDeclsLexicallyInContext(DeclContext *DC, |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2599 | llvm::SmallVectorImpl<pch::DeclID> &Decls) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2600 | assert(DC->hasExternalLexicalStorage() && |
| 2601 | "DeclContext has no lexical decls in storage"); |
| 2602 | uint64_t Offset = DeclContextOffsets[DC].first; |
| 2603 | assert(Offset && "DeclContext has no lexical decls in storage"); |
| 2604 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2605 | // Keep track of where we are in the stream, then jump back there |
| 2606 | // after reading this context. |
| 2607 | SavedStreamPosition SavedPosition(Stream); |
| 2608 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2609 | // Load the record containing all of the declarations lexically in |
| 2610 | // this context. |
| 2611 | Stream.JumpToBit(Offset); |
| 2612 | RecordData Record; |
| 2613 | unsigned Code = Stream.ReadCode(); |
| 2614 | unsigned RecCode = Stream.ReadRecord(Code, Record); |
Douglas Gregor | 6a2bfb2 | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 2615 | (void)RecCode; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2616 | assert(RecCode == pch::DECL_CONTEXT_LEXICAL && "Expected lexical block"); |
| 2617 | |
| 2618 | // Load all of the declaration IDs |
| 2619 | Decls.clear(); |
| 2620 | Decls.insert(Decls.end(), Record.begin(), Record.end()); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2621 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2622 | return false; |
| 2623 | } |
| 2624 | |
| 2625 | bool PCHReader::ReadDeclsVisibleInContext(DeclContext *DC, |
| 2626 | llvm::SmallVectorImpl<VisibleDeclaration> & Decls) { |
| 2627 | assert(DC->hasExternalVisibleStorage() && |
| 2628 | "DeclContext has no visible decls in storage"); |
| 2629 | uint64_t Offset = DeclContextOffsets[DC].second; |
| 2630 | assert(Offset && "DeclContext has no visible decls in storage"); |
| 2631 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2632 | // Keep track of where we are in the stream, then jump back there |
| 2633 | // after reading this context. |
| 2634 | SavedStreamPosition SavedPosition(Stream); |
| 2635 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2636 | // Load the record containing all of the declarations visible in |
| 2637 | // this context. |
| 2638 | Stream.JumpToBit(Offset); |
| 2639 | RecordData Record; |
| 2640 | unsigned Code = Stream.ReadCode(); |
| 2641 | unsigned RecCode = Stream.ReadRecord(Code, Record); |
Douglas Gregor | 6a2bfb2 | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 2642 | (void)RecCode; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2643 | assert(RecCode == pch::DECL_CONTEXT_VISIBLE && "Expected visible block"); |
| 2644 | if (Record.size() == 0) |
| 2645 | return false; |
| 2646 | |
| 2647 | Decls.clear(); |
| 2648 | |
| 2649 | unsigned Idx = 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2650 | while (Idx < Record.size()) { |
| 2651 | Decls.push_back(VisibleDeclaration()); |
| 2652 | Decls.back().Name = ReadDeclarationName(Record, Idx); |
| 2653 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2654 | unsigned Size = Record[Idx++]; |
| 2655 | llvm::SmallVector<unsigned, 4> & LoadedDecls |
| 2656 | = Decls.back().Declarations; |
| 2657 | LoadedDecls.reserve(Size); |
| 2658 | for (unsigned I = 0; I < Size; ++I) |
| 2659 | LoadedDecls.push_back(Record[Idx++]); |
| 2660 | } |
| 2661 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2662 | ++NumVisibleDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2663 | return false; |
| 2664 | } |
| 2665 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2666 | void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 2667 | this->Consumer = Consumer; |
| 2668 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2669 | if (!Consumer) |
| 2670 | return; |
| 2671 | |
| 2672 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
| 2673 | Decl *D = GetDecl(ExternalDefinitions[I]); |
| 2674 | DeclGroupRef DG(D); |
| 2675 | Consumer->HandleTopLevelDecl(DG); |
| 2676 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 2677 | |
| 2678 | for (unsigned I = 0, N = InterestingDecls.size(); I != N; ++I) { |
| 2679 | DeclGroupRef DG(InterestingDecls[I]); |
| 2680 | Consumer->HandleTopLevelDecl(DG); |
| 2681 | } |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2684 | void PCHReader::PrintStats() { |
| 2685 | std::fprintf(stderr, "*** PCH Statistics:\n"); |
| 2686 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2687 | unsigned NumTypesLoaded |
| 2688 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 2689 | (Type *)0); |
| 2690 | unsigned NumDeclsLoaded |
| 2691 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 2692 | (Decl *)0); |
| 2693 | unsigned NumIdentifiersLoaded |
| 2694 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 2695 | IdentifiersLoaded.end(), |
| 2696 | (IdentifierInfo *)0); |
| 2697 | unsigned NumSelectorsLoaded |
| 2698 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 2699 | SelectorsLoaded.end(), |
| 2700 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 2701 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2702 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2703 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2704 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 2705 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 2706 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2707 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2708 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 2709 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2710 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2711 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2712 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 2713 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2714 | if (TotalNumSelectors) |
| 2715 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 2716 | NumSelectorsLoaded, TotalNumSelectors, |
| 2717 | ((float)NumSelectorsLoaded/TotalNumSelectors * 100)); |
| 2718 | if (TotalNumStatements) |
| 2719 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 2720 | NumStatementsRead, TotalNumStatements, |
| 2721 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 2722 | if (TotalNumMacros) |
| 2723 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 2724 | NumMacrosRead, TotalNumMacros, |
| 2725 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 2726 | if (TotalLexicalDeclContexts) |
| 2727 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 2728 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 2729 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 2730 | * 100)); |
| 2731 | if (TotalVisibleDeclContexts) |
| 2732 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 2733 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 2734 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 2735 | * 100)); |
| 2736 | if (TotalSelectorsInMethodPool) { |
| 2737 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 2738 | NumMethodPoolSelectorsRead, TotalSelectorsInMethodPool, |
| 2739 | ((float)NumMethodPoolSelectorsRead/TotalSelectorsInMethodPool |
| 2740 | * 100)); |
| 2741 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
| 2742 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2743 | std::fprintf(stderr, "\n"); |
| 2744 | } |
| 2745 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2746 | void PCHReader::InitializeSema(Sema &S) { |
| 2747 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2748 | S.ExternalSource = this; |
| 2749 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 2750 | // Makes sure any declarations that were deserialized "too early" |
| 2751 | // still get added to the identifier's declaration chains. |
| 2752 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 2753 | SemaObj->TUScope->AddDecl(Action::DeclPtrTy::make(PreloadedDecls[I])); |
| 2754 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2755 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 2756 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2757 | |
| 2758 | // If there were any tentative definitions, deserialize them and add |
| 2759 | // them to Sema's table of tentative definitions. |
| 2760 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 2761 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 2762 | SemaObj->TentativeDefinitions[Var->getDeclName()] = Var; |
| 2763 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2764 | |
| 2765 | // If there were any locally-scoped external declarations, |
| 2766 | // deserialize them and add them to Sema's table of locally-scoped |
| 2767 | // external declarations. |
| 2768 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 2769 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 2770 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 2771 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | IdentifierInfo* PCHReader::get(const char *NameStart, const char *NameEnd) { |
| 2775 | // Try to find this name within our on-disk hash table |
| 2776 | PCHIdentifierLookupTable *IdTable |
| 2777 | = (PCHIdentifierLookupTable *)IdentifierLookupTable; |
| 2778 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
| 2779 | PCHIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 2780 | if (Pos == IdTable->end()) |
| 2781 | return 0; |
| 2782 | |
| 2783 | // Dereferencing the iterator has the effect of building the |
| 2784 | // IdentifierInfo node and populating it with the various |
| 2785 | // declarations it needs. |
| 2786 | return *Pos; |
| 2787 | } |
| 2788 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2789 | std::pair<ObjCMethodList, ObjCMethodList> |
| 2790 | PCHReader::ReadMethodPool(Selector Sel) { |
| 2791 | if (!MethodPoolLookupTable) |
| 2792 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
| 2793 | |
| 2794 | // Try to find this selector within our on-disk hash table. |
| 2795 | PCHMethodPoolLookupTable *PoolTable |
| 2796 | = (PCHMethodPoolLookupTable*)MethodPoolLookupTable; |
| 2797 | PCHMethodPoolLookupTable::iterator Pos = PoolTable->find(Sel); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2798 | if (Pos == PoolTable->end()) { |
| 2799 | ++NumMethodPoolMisses; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2800 | return std::pair<ObjCMethodList, ObjCMethodList>();; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2801 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2802 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2803 | ++NumMethodPoolSelectorsRead; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2804 | return *Pos; |
| 2805 | } |
| 2806 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2807 | void PCHReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2808 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2809 | assert(ID <= IdentifiersLoaded.size() && "Identifier ID out of range"); |
| 2810 | IdentifiersLoaded[ID - 1] = II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2813 | IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2814 | if (ID == 0) |
| 2815 | return 0; |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2816 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2817 | if (!IdentifierTableData || IdentifiersLoaded.empty()) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2818 | Error("No identifier table in PCH file"); |
| 2819 | return 0; |
| 2820 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2821 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2822 | if (!IdentifiersLoaded[ID - 1]) { |
| 2823 | uint32_t Offset = IdentifierOffsets[ID - 1]; |
Douglas Gregor | 17e1c5e | 2009-04-25 21:21:38 +0000 | [diff] [blame] | 2824 | const char *Str = IdentifierTableData + Offset; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2825 | |
| 2826 | // If there is an identifier lookup table, but the offset of this |
| 2827 | // string is after the identifier table itself, then we know that |
| 2828 | // this string is not in the on-disk hash table. Therefore, |
| 2829 | // disable lookup into the hash table when looking for this |
| 2830 | // identifier. |
| 2831 | PCHIdentifierLookupTable *IdTable |
| 2832 | = (PCHIdentifierLookupTable *)IdentifierLookupTable; |
Douglas Gregor | 17e1c5e | 2009-04-25 21:21:38 +0000 | [diff] [blame] | 2833 | if (!IdTable || |
| 2834 | Offset >= uint32_t(IdTable->getBuckets() - IdTable->getBase())) { |
| 2835 | // Turn off lookup into the on-disk hash table. We know that |
| 2836 | // this identifier is not there. |
| 2837 | if (IdTable) |
| 2838 | PP.getIdentifierTable().setExternalIdentifierLookup(0); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2839 | |
Douglas Gregor | 17e1c5e | 2009-04-25 21:21:38 +0000 | [diff] [blame] | 2840 | // All of the strings in the PCH file are preceded by a 16-bit |
| 2841 | // length. Extract that 16-bit length to avoid having to execute |
| 2842 | // strlen(). |
| 2843 | const char *StrLenPtr = Str - 2; |
| 2844 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 2845 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
| 2846 | IdentifiersLoaded[ID - 1] = &Context.Idents.get(Str, Str + StrLen); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2847 | |
Douglas Gregor | 17e1c5e | 2009-04-25 21:21:38 +0000 | [diff] [blame] | 2848 | // Turn on lookup into the on-disk hash table, if we have an |
| 2849 | // on-disk hash table. |
| 2850 | if (IdTable) |
| 2851 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 2852 | } else { |
| 2853 | // The identifier is a key in our on-disk hash table. Since we |
| 2854 | // know where the hash table entry starts, just read in this |
| 2855 | // (key, value) pair. |
| 2856 | PCHIdentifierLookupTrait Trait(const_cast<PCHReader &>(*this)); |
| 2857 | const unsigned char *Pos = (const unsigned char *)Str - 4; |
| 2858 | std::pair<unsigned, unsigned> KeyDataLengths |
| 2859 | = Trait.ReadKeyDataLength(Pos); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2860 | |
Douglas Gregor | 17e1c5e | 2009-04-25 21:21:38 +0000 | [diff] [blame] | 2861 | PCHIdentifierLookupTrait::internal_key_type InternalKey |
| 2862 | = Trait.ReadKey(Pos, KeyDataLengths.first); |
| 2863 | Pos = (const unsigned char *)Str + KeyDataLengths.first; |
| 2864 | IdentifiersLoaded[ID - 1] = Trait.ReadData(InternalKey, Pos, |
| 2865 | KeyDataLengths.second); |
| 2866 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2867 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2868 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2869 | return IdentifiersLoaded[ID - 1]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2872 | Selector PCHReader::DecodeSelector(unsigned ID) { |
| 2873 | if (ID == 0) |
| 2874 | return Selector(); |
| 2875 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2876 | if (!MethodPoolLookupTableData) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2877 | Error("No selector table in PCH file"); |
| 2878 | return Selector(); |
| 2879 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2880 | |
| 2881 | if (ID > TotalNumSelectors) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2882 | Error("Selector ID out of range"); |
| 2883 | return Selector(); |
| 2884 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2885 | |
| 2886 | unsigned Index = ID - 1; |
| 2887 | if (SelectorsLoaded[Index].getAsOpaquePtr() == 0) { |
| 2888 | // Load this selector from the selector table. |
| 2889 | // FIXME: endianness portability issues with SelectorOffsets table |
| 2890 | PCHMethodPoolLookupTrait Trait(*this); |
| 2891 | SelectorsLoaded[Index] |
| 2892 | = Trait.ReadKey(MethodPoolLookupTableData + SelectorOffsets[Index], 0); |
| 2893 | } |
| 2894 | |
| 2895 | return SelectorsLoaded[Index]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2896 | } |
| 2897 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2898 | DeclarationName |
| 2899 | PCHReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
| 2900 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 2901 | switch (Kind) { |
| 2902 | case DeclarationName::Identifier: |
| 2903 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 2904 | |
| 2905 | case DeclarationName::ObjCZeroArgSelector: |
| 2906 | case DeclarationName::ObjCOneArgSelector: |
| 2907 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 2908 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2909 | |
| 2910 | case DeclarationName::CXXConstructorName: |
| 2911 | return Context.DeclarationNames.getCXXConstructorName( |
| 2912 | GetType(Record[Idx++])); |
| 2913 | |
| 2914 | case DeclarationName::CXXDestructorName: |
| 2915 | return Context.DeclarationNames.getCXXDestructorName( |
| 2916 | GetType(Record[Idx++])); |
| 2917 | |
| 2918 | case DeclarationName::CXXConversionFunctionName: |
| 2919 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 2920 | GetType(Record[Idx++])); |
| 2921 | |
| 2922 | case DeclarationName::CXXOperatorName: |
| 2923 | return Context.DeclarationNames.getCXXOperatorName( |
| 2924 | (OverloadedOperatorKind)Record[Idx++]); |
| 2925 | |
| 2926 | case DeclarationName::CXXUsingDirective: |
| 2927 | return DeclarationName::getUsingDirectiveName(); |
| 2928 | } |
| 2929 | |
| 2930 | // Required to silence GCC warning |
| 2931 | return DeclarationName(); |
| 2932 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2933 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2934 | /// \brief Read an integral value |
| 2935 | llvm::APInt PCHReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 2936 | unsigned BitWidth = Record[Idx++]; |
| 2937 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 2938 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 2939 | Idx += NumWords; |
| 2940 | return Result; |
| 2941 | } |
| 2942 | |
| 2943 | /// \brief Read a signed integral value |
| 2944 | llvm::APSInt PCHReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 2945 | bool isUnsigned = Record[Idx++]; |
| 2946 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 2947 | } |
| 2948 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2949 | /// \brief Read a floating-point value |
| 2950 | llvm::APFloat PCHReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2951 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 2952 | } |
| 2953 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2954 | // \brief Read a string |
| 2955 | std::string PCHReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 2956 | unsigned Len = Record[Idx++]; |
| 2957 | std::string Result(&Record[Idx], &Record[Idx] + Len); |
| 2958 | Idx += Len; |
| 2959 | return Result; |
| 2960 | } |
| 2961 | |
| 2962 | /// \brief Reads attributes from the current stream position. |
| 2963 | Attr *PCHReader::ReadAttributes() { |
| 2964 | unsigned Code = Stream.ReadCode(); |
| 2965 | assert(Code == llvm::bitc::UNABBREV_RECORD && |
| 2966 | "Expected unabbreviated record"); (void)Code; |
| 2967 | |
| 2968 | RecordData Record; |
| 2969 | unsigned Idx = 0; |
| 2970 | unsigned RecCode = Stream.ReadRecord(Code, Record); |
| 2971 | assert(RecCode == pch::DECL_ATTR && "Expected attribute record"); |
| 2972 | (void)RecCode; |
| 2973 | |
| 2974 | #define SIMPLE_ATTR(Name) \ |
| 2975 | case Attr::Name: \ |
| 2976 | New = ::new (Context) Name##Attr(); \ |
| 2977 | break |
| 2978 | |
| 2979 | #define STRING_ATTR(Name) \ |
| 2980 | case Attr::Name: \ |
| 2981 | New = ::new (Context) Name##Attr(ReadString(Record, Idx)); \ |
| 2982 | break |
| 2983 | |
| 2984 | #define UNSIGNED_ATTR(Name) \ |
| 2985 | case Attr::Name: \ |
| 2986 | New = ::new (Context) Name##Attr(Record[Idx++]); \ |
| 2987 | break |
| 2988 | |
| 2989 | Attr *Attrs = 0; |
| 2990 | while (Idx < Record.size()) { |
| 2991 | Attr *New = 0; |
| 2992 | Attr::Kind Kind = (Attr::Kind)Record[Idx++]; |
| 2993 | bool IsInherited = Record[Idx++]; |
| 2994 | |
| 2995 | switch (Kind) { |
| 2996 | STRING_ATTR(Alias); |
| 2997 | UNSIGNED_ATTR(Aligned); |
| 2998 | SIMPLE_ATTR(AlwaysInline); |
| 2999 | SIMPLE_ATTR(AnalyzerNoReturn); |
| 3000 | STRING_ATTR(Annotate); |
| 3001 | STRING_ATTR(AsmLabel); |
| 3002 | |
| 3003 | case Attr::Blocks: |
| 3004 | New = ::new (Context) BlocksAttr( |
| 3005 | (BlocksAttr::BlocksAttrTypes)Record[Idx++]); |
| 3006 | break; |
| 3007 | |
| 3008 | case Attr::Cleanup: |
| 3009 | New = ::new (Context) CleanupAttr( |
| 3010 | cast<FunctionDecl>(GetDecl(Record[Idx++]))); |
| 3011 | break; |
| 3012 | |
| 3013 | SIMPLE_ATTR(Const); |
| 3014 | UNSIGNED_ATTR(Constructor); |
| 3015 | SIMPLE_ATTR(DLLExport); |
| 3016 | SIMPLE_ATTR(DLLImport); |
| 3017 | SIMPLE_ATTR(Deprecated); |
| 3018 | UNSIGNED_ATTR(Destructor); |
| 3019 | SIMPLE_ATTR(FastCall); |
| 3020 | |
| 3021 | case Attr::Format: { |
| 3022 | std::string Type = ReadString(Record, Idx); |
| 3023 | unsigned FormatIdx = Record[Idx++]; |
| 3024 | unsigned FirstArg = Record[Idx++]; |
| 3025 | New = ::new (Context) FormatAttr(Type, FormatIdx, FirstArg); |
| 3026 | break; |
| 3027 | } |
| 3028 | |
Chris Lattner | cf2a721 | 2009-04-20 19:12:28 +0000 | [diff] [blame] | 3029 | SIMPLE_ATTR(GNUInline); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3030 | |
| 3031 | case Attr::IBOutletKind: |
| 3032 | New = ::new (Context) IBOutletAttr(); |
| 3033 | break; |
| 3034 | |
| 3035 | SIMPLE_ATTR(NoReturn); |
| 3036 | SIMPLE_ATTR(NoThrow); |
| 3037 | SIMPLE_ATTR(Nodebug); |
| 3038 | SIMPLE_ATTR(Noinline); |
| 3039 | |
| 3040 | case Attr::NonNull: { |
| 3041 | unsigned Size = Record[Idx++]; |
| 3042 | llvm::SmallVector<unsigned, 16> ArgNums; |
| 3043 | ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size); |
| 3044 | Idx += Size; |
| 3045 | New = ::new (Context) NonNullAttr(&ArgNums[0], Size); |
| 3046 | break; |
| 3047 | } |
| 3048 | |
| 3049 | SIMPLE_ATTR(ObjCException); |
| 3050 | SIMPLE_ATTR(ObjCNSObject); |
Ted Kremenek | de9a81b | 2009-04-25 00:17:17 +0000 | [diff] [blame] | 3051 | SIMPLE_ATTR(ObjCOwnershipRetain); |
Ted Kremenek | 0fc169e | 2009-04-24 23:09:54 +0000 | [diff] [blame] | 3052 | SIMPLE_ATTR(ObjCOwnershipReturns); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3053 | SIMPLE_ATTR(Overloadable); |
| 3054 | UNSIGNED_ATTR(Packed); |
| 3055 | SIMPLE_ATTR(Pure); |
| 3056 | UNSIGNED_ATTR(Regparm); |
| 3057 | STRING_ATTR(Section); |
| 3058 | SIMPLE_ATTR(StdCall); |
| 3059 | SIMPLE_ATTR(TransparentUnion); |
| 3060 | SIMPLE_ATTR(Unavailable); |
| 3061 | SIMPLE_ATTR(Unused); |
| 3062 | SIMPLE_ATTR(Used); |
| 3063 | |
| 3064 | case Attr::Visibility: |
| 3065 | New = ::new (Context) VisibilityAttr( |
| 3066 | (VisibilityAttr::VisibilityTypes)Record[Idx++]); |
| 3067 | break; |
| 3068 | |
| 3069 | SIMPLE_ATTR(WarnUnusedResult); |
| 3070 | SIMPLE_ATTR(Weak); |
| 3071 | SIMPLE_ATTR(WeakImport); |
| 3072 | } |
| 3073 | |
| 3074 | assert(New && "Unable to decode attribute?"); |
| 3075 | New->setInherited(IsInherited); |
| 3076 | New->setNext(Attrs); |
| 3077 | Attrs = New; |
| 3078 | } |
| 3079 | #undef UNSIGNED_ATTR |
| 3080 | #undef STRING_ATTR |
| 3081 | #undef SIMPLE_ATTR |
| 3082 | |
| 3083 | // The list of attributes was built backwards. Reverse the list |
| 3084 | // before returning it. |
| 3085 | Attr *PrevAttr = 0, *NextAttr = 0; |
| 3086 | while (Attrs) { |
| 3087 | NextAttr = Attrs->getNext(); |
| 3088 | Attrs->setNext(PrevAttr); |
| 3089 | PrevAttr = Attrs; |
| 3090 | Attrs = NextAttr; |
| 3091 | } |
| 3092 | |
| 3093 | return PrevAttr; |
| 3094 | } |
| 3095 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3096 | Stmt *PCHReader::ReadStmt() { |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3097 | // Within the bitstream, expressions are stored in Reverse Polish |
| 3098 | // Notation, with each of the subexpressions preceding the |
| 3099 | // expression they are stored in. To evaluate expressions, we |
| 3100 | // continue reading expressions and placing them on the stack, with |
| 3101 | // expressions having operands removing those operands from the |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3102 | // stack. Evaluation terminates when we see a STMT_STOP record, and |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3103 | // the single remaining expression on the stack is our result. |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3104 | RecordData Record; |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3105 | unsigned Idx; |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3106 | llvm::SmallVector<Stmt *, 16> StmtStack; |
| 3107 | PCHStmtReader Reader(*this, Record, Idx, StmtStack); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3108 | Stmt::EmptyShell Empty; |
| 3109 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3110 | while (true) { |
| 3111 | unsigned Code = Stream.ReadCode(); |
| 3112 | if (Code == llvm::bitc::END_BLOCK) { |
| 3113 | if (Stream.ReadBlockEnd()) { |
| 3114 | Error("Error at end of Source Manager block"); |
| 3115 | return 0; |
| 3116 | } |
| 3117 | break; |
| 3118 | } |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3119 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3120 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3121 | // No known subblocks, always skip them. |
| 3122 | Stream.ReadSubBlockID(); |
| 3123 | if (Stream.SkipBlock()) { |
| 3124 | Error("Malformed block record"); |
| 3125 | return 0; |
| 3126 | } |
| 3127 | continue; |
| 3128 | } |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 3129 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3130 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3131 | Stream.ReadAbbrevRecord(); |
| 3132 | continue; |
| 3133 | } |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3134 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3135 | Stmt *S = 0; |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3136 | Idx = 0; |
| 3137 | Record.clear(); |
| 3138 | bool Finished = false; |
| 3139 | switch ((pch::StmtCode)Stream.ReadRecord(Code, Record)) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3140 | case pch::STMT_STOP: |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3141 | Finished = true; |
| 3142 | break; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3143 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3144 | case pch::STMT_NULL_PTR: |
| 3145 | S = 0; |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3146 | break; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3147 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 3148 | case pch::STMT_NULL: |
| 3149 | S = new (Context) NullStmt(Empty); |
| 3150 | break; |
| 3151 | |
| 3152 | case pch::STMT_COMPOUND: |
| 3153 | S = new (Context) CompoundStmt(Empty); |
| 3154 | break; |
| 3155 | |
| 3156 | case pch::STMT_CASE: |
| 3157 | S = new (Context) CaseStmt(Empty); |
| 3158 | break; |
| 3159 | |
| 3160 | case pch::STMT_DEFAULT: |
| 3161 | S = new (Context) DefaultStmt(Empty); |
| 3162 | break; |
| 3163 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 3164 | case pch::STMT_LABEL: |
| 3165 | S = new (Context) LabelStmt(Empty); |
| 3166 | break; |
| 3167 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 3168 | case pch::STMT_IF: |
| 3169 | S = new (Context) IfStmt(Empty); |
| 3170 | break; |
| 3171 | |
| 3172 | case pch::STMT_SWITCH: |
| 3173 | S = new (Context) SwitchStmt(Empty); |
| 3174 | break; |
| 3175 | |
Douglas Gregor | d921cf9 | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 3176 | case pch::STMT_WHILE: |
| 3177 | S = new (Context) WhileStmt(Empty); |
| 3178 | break; |
| 3179 | |
Douglas Gregor | 67d8249 | 2009-04-17 00:29:51 +0000 | [diff] [blame] | 3180 | case pch::STMT_DO: |
| 3181 | S = new (Context) DoStmt(Empty); |
| 3182 | break; |
| 3183 | |
| 3184 | case pch::STMT_FOR: |
| 3185 | S = new (Context) ForStmt(Empty); |
| 3186 | break; |
| 3187 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 3188 | case pch::STMT_GOTO: |
| 3189 | S = new (Context) GotoStmt(Empty); |
| 3190 | break; |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 3191 | |
| 3192 | case pch::STMT_INDIRECT_GOTO: |
| 3193 | S = new (Context) IndirectGotoStmt(Empty); |
| 3194 | break; |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 3195 | |
Douglas Gregor | d921cf9 | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 3196 | case pch::STMT_CONTINUE: |
| 3197 | S = new (Context) ContinueStmt(Empty); |
| 3198 | break; |
| 3199 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 3200 | case pch::STMT_BREAK: |
| 3201 | S = new (Context) BreakStmt(Empty); |
| 3202 | break; |
| 3203 | |
Douglas Gregor | 0de9d88 | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 3204 | case pch::STMT_RETURN: |
| 3205 | S = new (Context) ReturnStmt(Empty); |
| 3206 | break; |
| 3207 | |
Douglas Gregor | 84f2170 | 2009-04-17 16:55:36 +0000 | [diff] [blame] | 3208 | case pch::STMT_DECL: |
| 3209 | S = new (Context) DeclStmt(Empty); |
| 3210 | break; |
| 3211 | |
Douglas Gregor | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 3212 | case pch::STMT_ASM: |
| 3213 | S = new (Context) AsmStmt(Empty); |
| 3214 | break; |
| 3215 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3216 | case pch::EXPR_PREDEFINED: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3217 | S = new (Context) PredefinedExpr(Empty); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3218 | break; |
| 3219 | |
| 3220 | case pch::EXPR_DECL_REF: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3221 | S = new (Context) DeclRefExpr(Empty); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3222 | break; |
| 3223 | |
| 3224 | case pch::EXPR_INTEGER_LITERAL: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3225 | S = new (Context) IntegerLiteral(Empty); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3226 | break; |
| 3227 | |
| 3228 | case pch::EXPR_FLOATING_LITERAL: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3229 | S = new (Context) FloatingLiteral(Empty); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3230 | break; |
| 3231 | |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 3232 | case pch::EXPR_IMAGINARY_LITERAL: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3233 | S = new (Context) ImaginaryLiteral(Empty); |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 3234 | break; |
| 3235 | |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 3236 | case pch::EXPR_STRING_LITERAL: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3237 | S = StringLiteral::CreateEmpty(Context, |
Douglas Gregor | 673ecd6 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 3238 | Record[PCHStmtReader::NumExprFields + 1]); |
| 3239 | break; |
| 3240 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3241 | case pch::EXPR_CHARACTER_LITERAL: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3242 | S = new (Context) CharacterLiteral(Empty); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3243 | break; |
| 3244 | |
Douglas Gregor | c04db4f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 3245 | case pch::EXPR_PAREN: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3246 | S = new (Context) ParenExpr(Empty); |
Douglas Gregor | c04db4f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 3247 | break; |
| 3248 | |
Douglas Gregor | 0b0b77f | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 3249 | case pch::EXPR_UNARY_OPERATOR: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3250 | S = new (Context) UnaryOperator(Empty); |
Douglas Gregor | 0b0b77f | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 3251 | break; |
| 3252 | |
| 3253 | case pch::EXPR_SIZEOF_ALIGN_OF: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3254 | S = new (Context) SizeOfAlignOfExpr(Empty); |
Douglas Gregor | 0b0b77f | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 3255 | break; |
| 3256 | |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 3257 | case pch::EXPR_ARRAY_SUBSCRIPT: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3258 | S = new (Context) ArraySubscriptExpr(Empty); |
Douglas Gregor | cb2ca73 | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 3259 | break; |
| 3260 | |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 3261 | case pch::EXPR_CALL: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3262 | S = new (Context) CallExpr(Context, Empty); |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 3263 | break; |
| 3264 | |
| 3265 | case pch::EXPR_MEMBER: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3266 | S = new (Context) MemberExpr(Empty); |
Douglas Gregor | 1f0d013 | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 3267 | break; |
| 3268 | |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 3269 | case pch::EXPR_BINARY_OPERATOR: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3270 | S = new (Context) BinaryOperator(Empty); |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 3271 | break; |
| 3272 | |
Douglas Gregor | ad90e96 | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 3273 | case pch::EXPR_COMPOUND_ASSIGN_OPERATOR: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3274 | S = new (Context) CompoundAssignOperator(Empty); |
Douglas Gregor | ad90e96 | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 3275 | break; |
| 3276 | |
| 3277 | case pch::EXPR_CONDITIONAL_OPERATOR: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3278 | S = new (Context) ConditionalOperator(Empty); |
Douglas Gregor | ad90e96 | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 3279 | break; |
| 3280 | |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3281 | case pch::EXPR_IMPLICIT_CAST: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3282 | S = new (Context) ImplicitCastExpr(Empty); |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3283 | break; |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 3284 | |
| 3285 | case pch::EXPR_CSTYLE_CAST: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3286 | S = new (Context) CStyleCastExpr(Empty); |
Douglas Gregor | db600c3 | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 3287 | break; |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 3288 | |
Douglas Gregor | ba6d7e7 | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 3289 | case pch::EXPR_COMPOUND_LITERAL: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3290 | S = new (Context) CompoundLiteralExpr(Empty); |
Douglas Gregor | ba6d7e7 | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 3291 | break; |
| 3292 | |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 3293 | case pch::EXPR_EXT_VECTOR_ELEMENT: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3294 | S = new (Context) ExtVectorElementExpr(Empty); |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 3295 | break; |
| 3296 | |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 3297 | case pch::EXPR_INIT_LIST: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3298 | S = new (Context) InitListExpr(Empty); |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 3299 | break; |
| 3300 | |
| 3301 | case pch::EXPR_DESIGNATED_INIT: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3302 | S = DesignatedInitExpr::CreateEmpty(Context, |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 3303 | Record[PCHStmtReader::NumExprFields] - 1); |
| 3304 | |
| 3305 | break; |
| 3306 | |
| 3307 | case pch::EXPR_IMPLICIT_VALUE_INIT: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3308 | S = new (Context) ImplicitValueInitExpr(Empty); |
Douglas Gregor | d077d75 | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 3309 | break; |
| 3310 | |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 3311 | case pch::EXPR_VA_ARG: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3312 | S = new (Context) VAArgExpr(Empty); |
Douglas Gregor | d3c98a0 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 3313 | break; |
Douglas Gregor | 44cae0c | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 3314 | |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 3315 | case pch::EXPR_ADDR_LABEL: |
| 3316 | S = new (Context) AddrLabelExpr(Empty); |
| 3317 | break; |
| 3318 | |
Douglas Gregor | 6a2dd55 | 2009-04-17 19:05:30 +0000 | [diff] [blame] | 3319 | case pch::EXPR_STMT: |
| 3320 | S = new (Context) StmtExpr(Empty); |
| 3321 | break; |
| 3322 | |
Douglas Gregor | 44cae0c | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 3323 | case pch::EXPR_TYPES_COMPATIBLE: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3324 | S = new (Context) TypesCompatibleExpr(Empty); |
Douglas Gregor | 44cae0c | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 3325 | break; |
| 3326 | |
| 3327 | case pch::EXPR_CHOOSE: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3328 | S = new (Context) ChooseExpr(Empty); |
Douglas Gregor | 44cae0c | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 3329 | break; |
| 3330 | |
| 3331 | case pch::EXPR_GNU_NULL: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3332 | S = new (Context) GNUNullExpr(Empty); |
Douglas Gregor | 44cae0c | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 3333 | break; |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 3334 | |
| 3335 | case pch::EXPR_SHUFFLE_VECTOR: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3336 | S = new (Context) ShuffleVectorExpr(Empty); |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 3337 | break; |
| 3338 | |
Douglas Gregor | 84af7c2 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 3339 | case pch::EXPR_BLOCK: |
| 3340 | S = new (Context) BlockExpr(Empty); |
| 3341 | break; |
| 3342 | |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 3343 | case pch::EXPR_BLOCK_DECL_REF: |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3344 | S = new (Context) BlockDeclRefExpr(Empty); |
Douglas Gregor | 94cd5d1 | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 3345 | break; |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 3346 | |
Chris Lattner | 3a57a37 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 3347 | case pch::EXPR_OBJC_STRING_LITERAL: |
| 3348 | S = new (Context) ObjCStringLiteral(Empty); |
| 3349 | break; |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 3350 | case pch::EXPR_OBJC_ENCODE: |
| 3351 | S = new (Context) ObjCEncodeExpr(Empty); |
| 3352 | break; |
Chris Lattner | 3a57a37 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 3353 | case pch::EXPR_OBJC_SELECTOR_EXPR: |
| 3354 | S = new (Context) ObjCSelectorExpr(Empty); |
| 3355 | break; |
| 3356 | case pch::EXPR_OBJC_PROTOCOL_EXPR: |
| 3357 | S = new (Context) ObjCProtocolExpr(Empty); |
| 3358 | break; |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 3359 | case pch::EXPR_OBJC_IVAR_REF_EXPR: |
| 3360 | S = new (Context) ObjCIvarRefExpr(Empty); |
| 3361 | break; |
| 3362 | case pch::EXPR_OBJC_PROPERTY_REF_EXPR: |
| 3363 | S = new (Context) ObjCPropertyRefExpr(Empty); |
| 3364 | break; |
| 3365 | case pch::EXPR_OBJC_KVC_REF_EXPR: |
| 3366 | S = new (Context) ObjCKVCRefExpr(Empty); |
| 3367 | break; |
Steve Naroff | c4f0bbd | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 3368 | case pch::EXPR_OBJC_MESSAGE_EXPR: |
| 3369 | S = new (Context) ObjCMessageExpr(Empty); |
| 3370 | break; |
Chris Lattner | 0389e6b | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 3371 | case pch::EXPR_OBJC_SUPER_EXPR: |
| 3372 | S = new (Context) ObjCSuperExpr(Empty); |
| 3373 | break; |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3376 | // We hit a STMT_STOP, so we're done with this expression. |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3377 | if (Finished) |
| 3378 | break; |
| 3379 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3380 | ++NumStatementsRead; |
| 3381 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3382 | if (S) { |
| 3383 | unsigned NumSubStmts = Reader.Visit(S); |
| 3384 | while (NumSubStmts > 0) { |
| 3385 | StmtStack.pop_back(); |
| 3386 | --NumSubStmts; |
Douglas Gregor | 087fd53 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 3387 | } |
| 3388 | } |
| 3389 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 3390 | assert(Idx == Record.size() && "Invalid deserialization of statement"); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3391 | StmtStack.push_back(S); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3392 | } |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3393 | assert(StmtStack.size() == 1 && "Extra expressions on stack!"); |
Douglas Gregor | 0de9d88 | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 3394 | SwitchCaseStmts.clear(); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3395 | return StmtStack.back(); |
| 3396 | } |
| 3397 | |
| 3398 | Expr *PCHReader::ReadExpr() { |
| 3399 | return dyn_cast_or_null<Expr>(ReadStmt()); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3400 | } |
| 3401 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3402 | DiagnosticBuilder PCHReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 3403 | return Diag(SourceLocation(), DiagID); |
| 3404 | } |
| 3405 | |
| 3406 | DiagnosticBuilder PCHReader::Diag(SourceLocation Loc, unsigned DiagID) { |
| 3407 | return PP.getDiagnostics().Report(FullSourceLoc(Loc, |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3408 | Context.getSourceManager()), |
| 3409 | DiagID); |
| 3410 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 3411 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3412 | /// \brief Retrieve the identifier table associated with the |
| 3413 | /// preprocessor. |
| 3414 | IdentifierTable &PCHReader::getIdentifierTable() { |
| 3415 | return PP.getIdentifierTable(); |
| 3416 | } |
| 3417 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 3418 | /// \brief Record that the given ID maps to the given switch-case |
| 3419 | /// statement. |
| 3420 | void PCHReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
| 3421 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 3422 | SwitchCaseStmts[ID] = SC; |
| 3423 | } |
| 3424 | |
| 3425 | /// \brief Retrieve the switch-case statement with the given ID. |
| 3426 | SwitchCase *PCHReader::getSwitchCaseWithID(unsigned ID) { |
| 3427 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 3428 | return SwitchCaseStmts[ID]; |
| 3429 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 3430 | |
| 3431 | /// \brief Record that the given label statement has been |
| 3432 | /// deserialized and has the given ID. |
| 3433 | void PCHReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
| 3434 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
| 3435 | "Deserialized label twice"); |
| 3436 | LabelStmts[ID] = S; |
| 3437 | |
| 3438 | // If we've already seen any goto statements that point to this |
| 3439 | // label, resolve them now. |
| 3440 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 3441 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 3442 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 3443 | Goto->second->setLabel(S); |
| 3444 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 3445 | |
| 3446 | // If we've already seen any address-label statements that point to |
| 3447 | // this label, resolve them now. |
| 3448 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
| 3449 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
| 3450 | = UnresolvedAddrLabelExprs.equal_range(ID); |
| 3451 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
| 3452 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 3453 | AddrLabel->second->setLabel(S); |
| 3454 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | /// \brief Set the label of the given statement to the label |
| 3458 | /// identified by ID. |
| 3459 | /// |
| 3460 | /// Depending on the order in which the label and other statements |
| 3461 | /// referencing that label occur, this operation may complete |
| 3462 | /// immediately (updating the statement) or it may queue the |
| 3463 | /// statement to be back-patched later. |
| 3464 | void PCHReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
| 3465 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 3466 | if (Label != LabelStmts.end()) { |
| 3467 | // We've already seen this label, so set the label of the goto and |
| 3468 | // we're done. |
| 3469 | S->setLabel(Label->second); |
| 3470 | } else { |
| 3471 | // We haven't seen this label yet, so add this goto to the set of |
| 3472 | // unresolved goto statements. |
| 3473 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 3474 | } |
| 3475 | } |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 3476 | |
| 3477 | /// \brief Set the label of the given expression to the label |
| 3478 | /// identified by ID. |
| 3479 | /// |
| 3480 | /// Depending on the order in which the label and other statements |
| 3481 | /// referencing that label occur, this operation may complete |
| 3482 | /// immediately (updating the statement) or it may queue the |
| 3483 | /// statement to be back-patched later. |
| 3484 | void PCHReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
| 3485 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 3486 | if (Label != LabelStmts.end()) { |
| 3487 | // We've already seen this label, so set the label of the |
| 3488 | // label-address expression and we're done. |
| 3489 | S->setLabel(Label->second); |
| 3490 | } else { |
| 3491 | // We haven't seen this label yet, so add this label-address |
| 3492 | // expression to the set of unresolved label-address expressions. |
| 3493 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 3494 | } |
| 3495 | } |