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