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