Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1 | //===--- PCHReader.cpp - Precompiled Headers Reader -------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the PCHReader class, which reads a precompiled header. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #include "clang/Frontend/PCHReader.h" |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/FrontendDiagnostic.h" |
Douglas Gregor | 631f6c6 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/AST/Decl.h" |
Douglas Gregor | 631f6c6 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclGroup.h" |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclVisitor.h" |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
| 21 | #include "clang/AST/StmtVisitor.h" |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/Type.h" |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 23 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 24 | #include "clang/Lex/Preprocessor.h" |
| 25 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 26 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 27 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 28 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 29 | #include "llvm/Bitcode/BitstreamReader.h" |
| 30 | #include "llvm/Support/Compiler.h" |
| 31 | #include "llvm/Support/MemoryBuffer.h" |
| 32 | #include <algorithm> |
| 33 | #include <cstdio> |
| 34 | |
| 35 | using namespace clang; |
| 36 | |
| 37 | //===----------------------------------------------------------------------===// |
| 38 | // Declaration deserialization |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | namespace { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 41 | class VISIBILITY_HIDDEN PCHDeclReader |
| 42 | : public DeclVisitor<PCHDeclReader, void> { |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | PCHReader &Reader; |
| 44 | const PCHReader::RecordData &Record; |
| 45 | unsigned &Idx; |
| 46 | |
| 47 | public: |
| 48 | PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record, |
| 49 | unsigned &Idx) |
| 50 | : Reader(Reader), Record(Record), Idx(Idx) { } |
| 51 | |
| 52 | void VisitDecl(Decl *D); |
| 53 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 54 | void VisitNamedDecl(NamedDecl *ND); |
| 55 | void VisitTypeDecl(TypeDecl *TD); |
| 56 | void VisitTypedefDecl(TypedefDecl *TD); |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 57 | void VisitTagDecl(TagDecl *TD); |
| 58 | void VisitEnumDecl(EnumDecl *ED); |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 59 | void VisitRecordDecl(RecordDecl *RD); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 60 | void VisitValueDecl(ValueDecl *VD); |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 61 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 62 | void VisitFunctionDecl(FunctionDecl *FD); |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 63 | void VisitFieldDecl(FieldDecl *FD); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 64 | void VisitVarDecl(VarDecl *VD); |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 65 | void VisitParmVarDecl(ParmVarDecl *PD); |
| 66 | void VisitOriginalParmVarDecl(OriginalParmVarDecl *PD); |
Douglas Gregor | 2a49179 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 67 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
| 68 | void VisitBlockDecl(BlockDecl *BD); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 69 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Steve Naroff | 79ea0e0 | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 70 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
Steve Naroff | 7333b49 | 2009-04-20 20:09:33 +0000 | [diff] [blame^] | 71 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 72 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 73 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 74 | }; |
| 75 | } |
| 76 | |
| 77 | void PCHDeclReader::VisitDecl(Decl *D) { |
| 78 | D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 79 | D->setLexicalDeclContext( |
| 80 | cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]))); |
| 81 | D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 82 | D->setInvalidDecl(Record[Idx++]); |
Douglas Gregor | 1c50788 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 83 | if (Record[Idx++]) |
| 84 | D->addAttr(Reader.ReadAttributes()); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 85 | D->setImplicit(Record[Idx++]); |
| 86 | D->setAccess((AccessSpecifier)Record[Idx++]); |
| 87 | } |
| 88 | |
| 89 | void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
| 90 | VisitDecl(TU); |
| 91 | } |
| 92 | |
| 93 | void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) { |
| 94 | VisitDecl(ND); |
| 95 | ND->setDeclName(Reader.ReadDeclarationName(Record, Idx)); |
| 96 | } |
| 97 | |
| 98 | void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) { |
| 99 | VisitNamedDecl(TD); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 100 | TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
| 101 | } |
| 102 | |
| 103 | void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Douglas Gregor | 88fd09d | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 104 | // Note that we cannot use VisitTypeDecl here, because we need to |
| 105 | // set the underlying type of the typedef *before* we try to read |
| 106 | // the type associated with the TypedefDecl. |
| 107 | VisitNamedDecl(TD); |
| 108 | TD->setUnderlyingType(Reader.GetType(Record[Idx + 1])); |
| 109 | TD->setTypeForDecl(Reader.GetType(Record[Idx]).getTypePtr()); |
| 110 | Idx += 2; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 113 | void PCHDeclReader::VisitTagDecl(TagDecl *TD) { |
| 114 | VisitTypeDecl(TD); |
| 115 | TD->setTagKind((TagDecl::TagKind)Record[Idx++]); |
| 116 | TD->setDefinition(Record[Idx++]); |
| 117 | TD->setTypedefForAnonDecl( |
| 118 | cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++]))); |
| 119 | } |
| 120 | |
| 121 | void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) { |
| 122 | VisitTagDecl(ED); |
| 123 | ED->setIntegerType(Reader.GetType(Record[Idx++])); |
| 124 | } |
| 125 | |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 126 | void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) { |
| 127 | VisitTagDecl(RD); |
| 128 | RD->setHasFlexibleArrayMember(Record[Idx++]); |
| 129 | RD->setAnonymousStructOrUnion(Record[Idx++]); |
| 130 | } |
| 131 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 132 | void PCHDeclReader::VisitValueDecl(ValueDecl *VD) { |
| 133 | VisitNamedDecl(VD); |
| 134 | VD->setType(Reader.GetType(Record[Idx++])); |
| 135 | } |
| 136 | |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 137 | void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
| 138 | VisitValueDecl(ECD); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 139 | if (Record[Idx++]) |
| 140 | ECD->setInitExpr(Reader.ReadExpr()); |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 141 | ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); |
| 142 | } |
| 143 | |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 144 | void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
| 145 | VisitValueDecl(FD); |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 146 | if (Record[Idx++]) |
Douglas Gregor | 3b9a7c8 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 147 | FD->setLazyBody(Reader.getStream().GetCurrentBitNo()); |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 148 | FD->setPreviousDeclaration( |
| 149 | cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]))); |
| 150 | FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]); |
| 151 | FD->setInline(Record[Idx++]); |
| 152 | FD->setVirtual(Record[Idx++]); |
| 153 | FD->setPure(Record[Idx++]); |
| 154 | FD->setInheritedPrototype(Record[Idx++]); |
| 155 | FD->setHasPrototype(Record[Idx++]); |
| 156 | FD->setDeleted(Record[Idx++]); |
| 157 | FD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 158 | unsigned NumParams = Record[Idx++]; |
| 159 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 160 | Params.reserve(NumParams); |
| 161 | for (unsigned I = 0; I != NumParams; ++I) |
| 162 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 163 | FD->setParams(Reader.getContext(), &Params[0], NumParams); |
| 164 | } |
| 165 | |
Steve Naroff | 79ea0e0 | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 166 | void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
| 167 | VisitNamedDecl(MD); |
| 168 | if (Record[Idx++]) { |
| 169 | // In practice, this won't be executed (since method definitions |
| 170 | // don't occur in header files). |
| 171 | MD->setBody(cast<CompoundStmt>(Reader.GetStmt(Record[Idx++]))); |
| 172 | MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 173 | MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++]))); |
| 174 | } |
| 175 | MD->setInstanceMethod(Record[Idx++]); |
| 176 | MD->setVariadic(Record[Idx++]); |
| 177 | MD->setSynthesized(Record[Idx++]); |
| 178 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); |
| 179 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
| 180 | MD->setResultType(Reader.GetType(Record[Idx++])); |
| 181 | MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 182 | unsigned NumParams = Record[Idx++]; |
| 183 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 184 | Params.reserve(NumParams); |
| 185 | for (unsigned I = 0; I != NumParams; ++I) |
| 186 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 187 | MD->setMethodParams(Reader.getContext(), &Params[0], NumParams); |
| 188 | } |
| 189 | |
Steve Naroff | 7333b49 | 2009-04-20 20:09:33 +0000 | [diff] [blame^] | 190 | void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
| 191 | VisitNamedDecl(CD); |
| 192 | CD->setAtEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 193 | } |
| 194 | |
| 195 | void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
| 196 | VisitObjCContainerDecl(ID); |
| 197 | ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); |
| 198 | ID->setSuperClass(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++]))); |
| 199 | unsigned NumIvars = Record[Idx++]; |
| 200 | llvm::SmallVector<ObjCIvarDecl *, 16> IVars; |
| 201 | IVars.reserve(NumIvars); |
| 202 | for (unsigned I = 0; I != NumIvars; ++I) |
| 203 | IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 204 | ID->setIVarList(&IVars[0], NumIvars, Reader.getContext()); |
| 205 | |
| 206 | ID->setForwardDecl(Record[Idx++]); |
| 207 | ID->setImplicitInterfaceDecl(Record[Idx++]); |
| 208 | ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 209 | ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 210 | ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 211 | // FIXME: add protocols, categories. |
| 212 | } |
| 213 | |
| 214 | void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
| 215 | VisitFieldDecl(IVD); |
| 216 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); |
| 217 | } |
| 218 | |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 219 | void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) { |
| 220 | VisitValueDecl(FD); |
| 221 | FD->setMutable(Record[Idx++]); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 222 | if (Record[Idx++]) |
| 223 | FD->setBitWidth(Reader.ReadExpr()); |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 226 | void PCHDeclReader::VisitVarDecl(VarDecl *VD) { |
| 227 | VisitValueDecl(VD); |
| 228 | VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]); |
| 229 | VD->setThreadSpecified(Record[Idx++]); |
| 230 | VD->setCXXDirectInitializer(Record[Idx++]); |
| 231 | VD->setDeclaredInCondition(Record[Idx++]); |
| 232 | VD->setPreviousDeclaration( |
| 233 | cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 234 | VD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 235 | if (Record[Idx++]) |
| 236 | VD->setInit(Reader.ReadExpr()); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 239 | void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
| 240 | VisitVarDecl(PD); |
| 241 | PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 242 | // FIXME: default argument (C++ only) |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) { |
| 246 | VisitParmVarDecl(PD); |
| 247 | PD->setOriginalType(Reader.GetType(Record[Idx++])); |
| 248 | } |
| 249 | |
Douglas Gregor | 2a49179 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 250 | void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
| 251 | VisitDecl(AD); |
Douglas Gregor | 3c8ff3e | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 252 | AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr())); |
Douglas Gregor | 2a49179 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) { |
| 256 | VisitDecl(BD); |
Douglas Gregor | e246b74 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 257 | BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt())); |
Douglas Gregor | 2a49179 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 258 | unsigned NumParams = Record[Idx++]; |
| 259 | llvm::SmallVector<ParmVarDecl *, 16> Params; |
| 260 | Params.reserve(NumParams); |
| 261 | for (unsigned I = 0; I != NumParams; ++I) |
| 262 | Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
| 263 | BD->setParams(Reader.getContext(), &Params[0], NumParams); |
| 264 | } |
| 265 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 266 | std::pair<uint64_t, uint64_t> |
| 267 | PCHDeclReader::VisitDeclContext(DeclContext *DC) { |
| 268 | uint64_t LexicalOffset = Record[Idx++]; |
| 269 | uint64_t VisibleOffset = 0; |
| 270 | if (DC->getPrimaryContext() == DC) |
| 271 | VisibleOffset = Record[Idx++]; |
| 272 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 273 | } |
| 274 | |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 275 | //===----------------------------------------------------------------------===// |
| 276 | // Statement/expression deserialization |
| 277 | //===----------------------------------------------------------------------===// |
| 278 | namespace { |
| 279 | class VISIBILITY_HIDDEN PCHStmtReader |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 280 | : public StmtVisitor<PCHStmtReader, unsigned> { |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 281 | PCHReader &Reader; |
| 282 | const PCHReader::RecordData &Record; |
| 283 | unsigned &Idx; |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 284 | llvm::SmallVectorImpl<Stmt *> &StmtStack; |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 285 | |
| 286 | public: |
| 287 | PCHStmtReader(PCHReader &Reader, const PCHReader::RecordData &Record, |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 288 | unsigned &Idx, llvm::SmallVectorImpl<Stmt *> &StmtStack) |
| 289 | : Reader(Reader), Record(Record), Idx(Idx), StmtStack(StmtStack) { } |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 290 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 291 | /// \brief The number of record fields required for the Stmt class |
| 292 | /// itself. |
| 293 | static const unsigned NumStmtFields = 0; |
| 294 | |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 295 | /// \brief The number of record fields required for the Expr class |
| 296 | /// itself. |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 297 | static const unsigned NumExprFields = NumStmtFields + 3; |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 298 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 299 | // Each of the Visit* functions reads in part of the expression |
| 300 | // from the given record and the current expression stack, then |
| 301 | // return the total number of operands that it read from the |
| 302 | // expression stack. |
| 303 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 304 | unsigned VisitStmt(Stmt *S); |
| 305 | unsigned VisitNullStmt(NullStmt *S); |
| 306 | unsigned VisitCompoundStmt(CompoundStmt *S); |
| 307 | unsigned VisitSwitchCase(SwitchCase *S); |
| 308 | unsigned VisitCaseStmt(CaseStmt *S); |
| 309 | unsigned VisitDefaultStmt(DefaultStmt *S); |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 310 | unsigned VisitLabelStmt(LabelStmt *S); |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 311 | unsigned VisitIfStmt(IfStmt *S); |
| 312 | unsigned VisitSwitchStmt(SwitchStmt *S); |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 313 | unsigned VisitWhileStmt(WhileStmt *S); |
Douglas Gregor | fb5f25b | 2009-04-17 00:29:51 +0000 | [diff] [blame] | 314 | unsigned VisitDoStmt(DoStmt *S); |
| 315 | unsigned VisitForStmt(ForStmt *S); |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 316 | unsigned VisitGotoStmt(GotoStmt *S); |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 317 | unsigned VisitIndirectGotoStmt(IndirectGotoStmt *S); |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 318 | unsigned VisitContinueStmt(ContinueStmt *S); |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 319 | unsigned VisitBreakStmt(BreakStmt *S); |
Douglas Gregor | 22d2dcd | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 320 | unsigned VisitReturnStmt(ReturnStmt *S); |
Douglas Gregor | 78ff29f | 2009-04-17 16:55:36 +0000 | [diff] [blame] | 321 | unsigned VisitDeclStmt(DeclStmt *S); |
Douglas Gregor | 3e1f9fb | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 322 | unsigned VisitAsmStmt(AsmStmt *S); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 323 | unsigned VisitExpr(Expr *E); |
| 324 | unsigned VisitPredefinedExpr(PredefinedExpr *E); |
| 325 | unsigned VisitDeclRefExpr(DeclRefExpr *E); |
| 326 | unsigned VisitIntegerLiteral(IntegerLiteral *E); |
| 327 | unsigned VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 328 | unsigned VisitImaginaryLiteral(ImaginaryLiteral *E); |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 329 | unsigned VisitStringLiteral(StringLiteral *E); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 330 | unsigned VisitCharacterLiteral(CharacterLiteral *E); |
Douglas Gregor | 4ea0b1f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 331 | unsigned VisitParenExpr(ParenExpr *E); |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 332 | unsigned VisitUnaryOperator(UnaryOperator *E); |
| 333 | unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 334 | unsigned VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 335 | unsigned VisitCallExpr(CallExpr *E); |
| 336 | unsigned VisitMemberExpr(MemberExpr *E); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 337 | unsigned VisitCastExpr(CastExpr *E); |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 338 | unsigned VisitBinaryOperator(BinaryOperator *E); |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 339 | unsigned VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 340 | unsigned VisitConditionalOperator(ConditionalOperator *E); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 341 | unsigned VisitImplicitCastExpr(ImplicitCastExpr *E); |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 342 | unsigned VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 343 | unsigned VisitCStyleCastExpr(CStyleCastExpr *E); |
Douglas Gregor | b70b48f | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 344 | unsigned VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 345 | unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E); |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 346 | unsigned VisitInitListExpr(InitListExpr *E); |
| 347 | unsigned VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 348 | unsigned VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 349 | unsigned VisitVAArgExpr(VAArgExpr *E); |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 350 | unsigned VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | eca12f6 | 2009-04-17 19:05:30 +0000 | [diff] [blame] | 351 | unsigned VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 352 | unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E); |
| 353 | unsigned VisitChooseExpr(ChooseExpr *E); |
| 354 | unsigned VisitGNUNullExpr(GNUNullExpr *E); |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 355 | unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E); |
Douglas Gregor | e246b74 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 356 | unsigned VisitBlockExpr(BlockExpr *E); |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 357 | unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 358 | }; |
| 359 | } |
| 360 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 361 | unsigned PCHStmtReader::VisitStmt(Stmt *S) { |
| 362 | assert(Idx == NumStmtFields && "Incorrect statement field count"); |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | unsigned PCHStmtReader::VisitNullStmt(NullStmt *S) { |
| 367 | VisitStmt(S); |
| 368 | S->setSemiLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | unsigned PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) { |
| 373 | VisitStmt(S); |
| 374 | unsigned NumStmts = Record[Idx++]; |
| 375 | S->setStmts(Reader.getContext(), |
| 376 | &StmtStack[StmtStack.size() - NumStmts], NumStmts); |
| 377 | S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 378 | S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 379 | return NumStmts; |
| 380 | } |
| 381 | |
| 382 | unsigned PCHStmtReader::VisitSwitchCase(SwitchCase *S) { |
| 383 | VisitStmt(S); |
| 384 | Reader.RecordSwitchCaseID(S, Record[Idx++]); |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | unsigned PCHStmtReader::VisitCaseStmt(CaseStmt *S) { |
| 389 | VisitSwitchCase(S); |
| 390 | S->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 391 | S->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 392 | S->setSubStmt(StmtStack.back()); |
| 393 | S->setCaseLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 394 | return 3; |
| 395 | } |
| 396 | |
| 397 | unsigned PCHStmtReader::VisitDefaultStmt(DefaultStmt *S) { |
| 398 | VisitSwitchCase(S); |
| 399 | S->setSubStmt(StmtStack.back()); |
| 400 | S->setDefaultLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 401 | return 1; |
| 402 | } |
| 403 | |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 404 | unsigned PCHStmtReader::VisitLabelStmt(LabelStmt *S) { |
| 405 | VisitStmt(S); |
| 406 | S->setID(Reader.GetIdentifierInfo(Record, Idx)); |
| 407 | S->setSubStmt(StmtStack.back()); |
| 408 | S->setIdentLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 409 | Reader.RecordLabelStmt(S, Record[Idx++]); |
| 410 | return 1; |
| 411 | } |
| 412 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 413 | unsigned PCHStmtReader::VisitIfStmt(IfStmt *S) { |
| 414 | VisitStmt(S); |
| 415 | S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 416 | S->setThen(StmtStack[StmtStack.size() - 2]); |
| 417 | S->setElse(StmtStack[StmtStack.size() - 1]); |
| 418 | S->setIfLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 419 | return 3; |
| 420 | } |
| 421 | |
| 422 | unsigned PCHStmtReader::VisitSwitchStmt(SwitchStmt *S) { |
| 423 | VisitStmt(S); |
| 424 | S->setCond(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
| 425 | S->setBody(StmtStack.back()); |
| 426 | S->setSwitchLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 427 | SwitchCase *PrevSC = 0; |
| 428 | for (unsigned N = Record.size(); Idx != N; ++Idx) { |
| 429 | SwitchCase *SC = Reader.getSwitchCaseWithID(Record[Idx]); |
| 430 | if (PrevSC) |
| 431 | PrevSC->setNextSwitchCase(SC); |
| 432 | else |
| 433 | S->setSwitchCaseList(SC); |
| 434 | PrevSC = SC; |
| 435 | } |
| 436 | return 2; |
| 437 | } |
| 438 | |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 439 | unsigned PCHStmtReader::VisitWhileStmt(WhileStmt *S) { |
| 440 | VisitStmt(S); |
| 441 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 442 | S->setBody(StmtStack.back()); |
| 443 | S->setWhileLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 444 | return 2; |
| 445 | } |
| 446 | |
Douglas Gregor | fb5f25b | 2009-04-17 00:29:51 +0000 | [diff] [blame] | 447 | unsigned PCHStmtReader::VisitDoStmt(DoStmt *S) { |
| 448 | VisitStmt(S); |
| 449 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 450 | S->setBody(StmtStack.back()); |
| 451 | S->setDoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 452 | return 2; |
| 453 | } |
| 454 | |
| 455 | unsigned PCHStmtReader::VisitForStmt(ForStmt *S) { |
| 456 | VisitStmt(S); |
| 457 | S->setInit(StmtStack[StmtStack.size() - 4]); |
| 458 | S->setCond(cast_or_null<Expr>(StmtStack[StmtStack.size() - 3])); |
| 459 | S->setInc(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 460 | S->setBody(StmtStack.back()); |
| 461 | S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 462 | return 4; |
| 463 | } |
| 464 | |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 465 | unsigned PCHStmtReader::VisitGotoStmt(GotoStmt *S) { |
| 466 | VisitStmt(S); |
| 467 | Reader.SetLabelOf(S, Record[Idx++]); |
| 468 | S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 469 | S->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 470 | return 0; |
| 471 | } |
| 472 | |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 473 | unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 474 | VisitStmt(S); |
Chris Lattner | 9ef9c28 | 2009-04-19 01:04:21 +0000 | [diff] [blame] | 475 | S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 476 | S->setTarget(cast_or_null<Expr>(StmtStack.back())); |
| 477 | return 1; |
| 478 | } |
| 479 | |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 480 | unsigned PCHStmtReader::VisitContinueStmt(ContinueStmt *S) { |
| 481 | VisitStmt(S); |
| 482 | S->setContinueLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 483 | return 0; |
| 484 | } |
| 485 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 486 | unsigned PCHStmtReader::VisitBreakStmt(BreakStmt *S) { |
| 487 | VisitStmt(S); |
| 488 | S->setBreakLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 489 | return 0; |
| 490 | } |
| 491 | |
Douglas Gregor | 22d2dcd | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 492 | unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) { |
| 493 | VisitStmt(S); |
| 494 | S->setRetValue(cast_or_null<Expr>(StmtStack.back())); |
| 495 | S->setReturnLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 496 | return 1; |
| 497 | } |
| 498 | |
Douglas Gregor | 78ff29f | 2009-04-17 16:55:36 +0000 | [diff] [blame] | 499 | unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) { |
| 500 | VisitStmt(S); |
| 501 | S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 502 | S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 503 | |
| 504 | if (Idx + 1 == Record.size()) { |
| 505 | // Single declaration |
| 506 | S->setDeclGroup(DeclGroupRef(Reader.GetDecl(Record[Idx++]))); |
| 507 | } else { |
| 508 | llvm::SmallVector<Decl *, 16> Decls; |
| 509 | Decls.reserve(Record.size() - Idx); |
| 510 | for (unsigned N = Record.size(); Idx != N; ++Idx) |
| 511 | Decls.push_back(Reader.GetDecl(Record[Idx])); |
| 512 | S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(), |
| 513 | &Decls[0], Decls.size()))); |
| 514 | } |
| 515 | return 0; |
| 516 | } |
| 517 | |
Douglas Gregor | 3e1f9fb | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 518 | unsigned PCHStmtReader::VisitAsmStmt(AsmStmt *S) { |
| 519 | VisitStmt(S); |
| 520 | unsigned NumOutputs = Record[Idx++]; |
| 521 | unsigned NumInputs = Record[Idx++]; |
| 522 | unsigned NumClobbers = Record[Idx++]; |
| 523 | S->setAsmLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 524 | S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 525 | S->setVolatile(Record[Idx++]); |
| 526 | S->setSimple(Record[Idx++]); |
| 527 | |
| 528 | unsigned StackIdx |
| 529 | = StmtStack.size() - (NumOutputs*2 + NumInputs*2 + NumClobbers + 1); |
| 530 | S->setAsmString(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 531 | |
| 532 | // Outputs and inputs |
| 533 | llvm::SmallVector<std::string, 16> Names; |
| 534 | llvm::SmallVector<StringLiteral*, 16> Constraints; |
| 535 | llvm::SmallVector<Stmt*, 16> Exprs; |
| 536 | for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) { |
| 537 | Names.push_back(Reader.ReadString(Record, Idx)); |
| 538 | Constraints.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 539 | Exprs.push_back(StmtStack[StackIdx++]); |
| 540 | } |
| 541 | S->setOutputsAndInputs(NumOutputs, NumInputs, |
| 542 | &Names[0], &Constraints[0], &Exprs[0]); |
| 543 | |
| 544 | // Constraints |
| 545 | llvm::SmallVector<StringLiteral*, 16> Clobbers; |
| 546 | for (unsigned I = 0; I != NumClobbers; ++I) |
| 547 | Clobbers.push_back(cast_or_null<StringLiteral>(StmtStack[StackIdx++])); |
| 548 | S->setClobbers(&Clobbers[0], NumClobbers); |
| 549 | |
| 550 | assert(StackIdx == StmtStack.size() && "Error deserializing AsmStmt"); |
| 551 | return NumOutputs*2 + NumInputs*2 + NumClobbers + 1; |
| 552 | } |
| 553 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 554 | unsigned PCHStmtReader::VisitExpr(Expr *E) { |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 555 | VisitStmt(E); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 556 | E->setType(Reader.GetType(Record[Idx++])); |
| 557 | E->setTypeDependent(Record[Idx++]); |
| 558 | E->setValueDependent(Record[Idx++]); |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 559 | assert(Idx == NumExprFields && "Incorrect expression field count"); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 560 | return 0; |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 563 | unsigned PCHStmtReader::VisitPredefinedExpr(PredefinedExpr *E) { |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 564 | VisitExpr(E); |
| 565 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 566 | E->setIdentType((PredefinedExpr::IdentType)Record[Idx++]); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 567 | return 0; |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 570 | unsigned PCHStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 571 | VisitExpr(E); |
| 572 | E->setDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 573 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 574 | return 0; |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 577 | unsigned PCHStmtReader::VisitIntegerLiteral(IntegerLiteral *E) { |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 578 | VisitExpr(E); |
| 579 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 580 | E->setValue(Reader.ReadAPInt(Record, Idx)); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 581 | return 0; |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 584 | unsigned PCHStmtReader::VisitFloatingLiteral(FloatingLiteral *E) { |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 585 | VisitExpr(E); |
| 586 | E->setValue(Reader.ReadAPFloat(Record, Idx)); |
| 587 | E->setExact(Record[Idx++]); |
| 588 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 589 | return 0; |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 592 | unsigned PCHStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 593 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 594 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 595 | return 1; |
| 596 | } |
| 597 | |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 598 | unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) { |
| 599 | VisitExpr(E); |
| 600 | unsigned Len = Record[Idx++]; |
| 601 | assert(Record[Idx] == E->getNumConcatenated() && |
| 602 | "Wrong number of concatenated tokens!"); |
| 603 | ++Idx; |
| 604 | E->setWide(Record[Idx++]); |
| 605 | |
| 606 | // Read string data |
| 607 | llvm::SmallVector<char, 16> Str(&Record[Idx], &Record[Idx] + Len); |
| 608 | E->setStrData(Reader.getContext(), &Str[0], Len); |
| 609 | Idx += Len; |
| 610 | |
| 611 | // Read source locations |
| 612 | for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) |
| 613 | E->setStrTokenLoc(I, SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 618 | unsigned PCHStmtReader::VisitCharacterLiteral(CharacterLiteral *E) { |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 619 | VisitExpr(E); |
| 620 | E->setValue(Record[Idx++]); |
| 621 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 622 | E->setWide(Record[Idx++]); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 623 | return 0; |
| 624 | } |
| 625 | |
Douglas Gregor | 4ea0b1f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 626 | unsigned PCHStmtReader::VisitParenExpr(ParenExpr *E) { |
| 627 | VisitExpr(E); |
| 628 | E->setLParen(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 629 | E->setRParen(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 630 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 4ea0b1f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 631 | return 1; |
| 632 | } |
| 633 | |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 634 | unsigned PCHStmtReader::VisitUnaryOperator(UnaryOperator *E) { |
| 635 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 636 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 637 | E->setOpcode((UnaryOperator::Opcode)Record[Idx++]); |
| 638 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 639 | return 1; |
| 640 | } |
| 641 | |
| 642 | unsigned PCHStmtReader::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
| 643 | VisitExpr(E); |
| 644 | E->setSizeof(Record[Idx++]); |
| 645 | if (Record[Idx] == 0) { |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 646 | E->setArgument(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 647 | ++Idx; |
| 648 | } else { |
| 649 | E->setArgument(Reader.GetType(Record[Idx++])); |
| 650 | } |
| 651 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 652 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 653 | return E->isArgumentType()? 0 : 1; |
| 654 | } |
| 655 | |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 656 | unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 657 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 658 | E->setLHS(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
| 659 | E->setRHS(cast<Expr>(StmtStack[StmtStack.size() - 2])); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 660 | E->setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 661 | return 2; |
| 662 | } |
| 663 | |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 664 | unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) { |
| 665 | VisitExpr(E); |
| 666 | E->setNumArgs(Reader.getContext(), Record[Idx++]); |
| 667 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 668 | E->setCallee(cast<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1])); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 669 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 670 | E->setArg(I, cast<Expr>(StmtStack[StmtStack.size() - N + I])); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 671 | return E->getNumArgs() + 1; |
| 672 | } |
| 673 | |
| 674 | unsigned PCHStmtReader::VisitMemberExpr(MemberExpr *E) { |
| 675 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 676 | E->setBase(cast<Expr>(StmtStack.back())); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 677 | E->setMemberDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++]))); |
| 678 | E->setMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 679 | E->setArrow(Record[Idx++]); |
| 680 | return 1; |
| 681 | } |
| 682 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 683 | unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) { |
| 684 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 685 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 686 | return 1; |
| 687 | } |
| 688 | |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 689 | unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) { |
| 690 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 691 | E->setLHS(cast<Expr>(StmtStack.end()[-2])); |
| 692 | E->setRHS(cast<Expr>(StmtStack.end()[-1])); |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 693 | E->setOpcode((BinaryOperator::Opcode)Record[Idx++]); |
| 694 | E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 695 | return 2; |
| 696 | } |
| 697 | |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 698 | unsigned PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 699 | VisitBinaryOperator(E); |
| 700 | E->setComputationLHSType(Reader.GetType(Record[Idx++])); |
| 701 | E->setComputationResultType(Reader.GetType(Record[Idx++])); |
| 702 | return 2; |
| 703 | } |
| 704 | |
| 705 | unsigned PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) { |
| 706 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 707 | E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 708 | E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 709 | E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1])); |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 710 | return 3; |
| 711 | } |
| 712 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 713 | unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 714 | VisitCastExpr(E); |
| 715 | E->setLvalueCast(Record[Idx++]); |
| 716 | return 1; |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 717 | } |
| 718 | |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 719 | unsigned PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 720 | VisitCastExpr(E); |
| 721 | E->setTypeAsWritten(Reader.GetType(Record[Idx++])); |
| 722 | return 1; |
| 723 | } |
| 724 | |
| 725 | unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) { |
| 726 | VisitExplicitCastExpr(E); |
| 727 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 728 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 729 | return 1; |
| 730 | } |
| 731 | |
Douglas Gregor | b70b48f | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 732 | unsigned PCHStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 733 | VisitExpr(E); |
| 734 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 735 | E->setInitializer(cast<Expr>(StmtStack.back())); |
Douglas Gregor | b70b48f | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 736 | E->setFileScope(Record[Idx++]); |
| 737 | return 1; |
| 738 | } |
| 739 | |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 740 | unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { |
| 741 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 742 | E->setBase(cast<Expr>(StmtStack.back())); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 743 | E->setAccessor(Reader.GetIdentifierInfo(Record, Idx)); |
| 744 | E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 745 | return 1; |
| 746 | } |
| 747 | |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 748 | unsigned PCHStmtReader::VisitInitListExpr(InitListExpr *E) { |
| 749 | VisitExpr(E); |
| 750 | unsigned NumInits = Record[Idx++]; |
| 751 | E->reserveInits(NumInits); |
| 752 | for (unsigned I = 0; I != NumInits; ++I) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 753 | E->updateInit(I, |
| 754 | cast<Expr>(StmtStack[StmtStack.size() - NumInits - 1 + I])); |
| 755 | E->setSyntacticForm(cast_or_null<InitListExpr>(StmtStack.back())); |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 756 | E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 757 | E->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 758 | E->setInitializedFieldInUnion( |
| 759 | cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]))); |
| 760 | E->sawArrayRangeDesignator(Record[Idx++]); |
| 761 | return NumInits + 1; |
| 762 | } |
| 763 | |
| 764 | unsigned PCHStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 765 | typedef DesignatedInitExpr::Designator Designator; |
| 766 | |
| 767 | VisitExpr(E); |
| 768 | unsigned NumSubExprs = Record[Idx++]; |
| 769 | assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs"); |
| 770 | for (unsigned I = 0; I != NumSubExprs; ++I) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 771 | E->setSubExpr(I, cast<Expr>(StmtStack[StmtStack.size() - NumSubExprs + I])); |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 772 | E->setEqualOrColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 773 | E->setGNUSyntax(Record[Idx++]); |
| 774 | |
| 775 | llvm::SmallVector<Designator, 4> Designators; |
| 776 | while (Idx < Record.size()) { |
| 777 | switch ((pch::DesignatorTypes)Record[Idx++]) { |
| 778 | case pch::DESIG_FIELD_DECL: { |
| 779 | FieldDecl *Field = cast<FieldDecl>(Reader.GetDecl(Record[Idx++])); |
| 780 | SourceLocation DotLoc |
| 781 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 782 | SourceLocation FieldLoc |
| 783 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 784 | Designators.push_back(Designator(Field->getIdentifier(), DotLoc, |
| 785 | FieldLoc)); |
| 786 | Designators.back().setField(Field); |
| 787 | break; |
| 788 | } |
| 789 | |
| 790 | case pch::DESIG_FIELD_NAME: { |
| 791 | const IdentifierInfo *Name = Reader.GetIdentifierInfo(Record, Idx); |
| 792 | SourceLocation DotLoc |
| 793 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 794 | SourceLocation FieldLoc |
| 795 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 796 | Designators.push_back(Designator(Name, DotLoc, FieldLoc)); |
| 797 | break; |
| 798 | } |
| 799 | |
| 800 | case pch::DESIG_ARRAY: { |
| 801 | unsigned Index = Record[Idx++]; |
| 802 | SourceLocation LBracketLoc |
| 803 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 804 | SourceLocation RBracketLoc |
| 805 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 806 | Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc)); |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | case pch::DESIG_ARRAY_RANGE: { |
| 811 | unsigned Index = Record[Idx++]; |
| 812 | SourceLocation LBracketLoc |
| 813 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 814 | SourceLocation EllipsisLoc |
| 815 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 816 | SourceLocation RBracketLoc |
| 817 | = SourceLocation::getFromRawEncoding(Record[Idx++]); |
| 818 | Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc, |
| 819 | RBracketLoc)); |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | E->setDesignators(&Designators[0], Designators.size()); |
| 825 | |
| 826 | return NumSubExprs; |
| 827 | } |
| 828 | |
| 829 | unsigned PCHStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 830 | VisitExpr(E); |
| 831 | return 0; |
| 832 | } |
| 833 | |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 834 | unsigned PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) { |
| 835 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 836 | E->setSubExpr(cast<Expr>(StmtStack.back())); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 837 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 838 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 839 | return 1; |
| 840 | } |
| 841 | |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 842 | unsigned PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 843 | VisitExpr(E); |
| 844 | E->setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 845 | E->setLabelLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 846 | Reader.SetLabelOf(E, Record[Idx++]); |
| 847 | return 0; |
| 848 | } |
| 849 | |
Douglas Gregor | eca12f6 | 2009-04-17 19:05:30 +0000 | [diff] [blame] | 850 | unsigned PCHStmtReader::VisitStmtExpr(StmtExpr *E) { |
| 851 | VisitExpr(E); |
| 852 | E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 853 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 854 | E->setSubStmt(cast_or_null<CompoundStmt>(StmtStack.back())); |
| 855 | return 1; |
| 856 | } |
| 857 | |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 858 | unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { |
| 859 | VisitExpr(E); |
| 860 | E->setArgType1(Reader.GetType(Record[Idx++])); |
| 861 | E->setArgType2(Reader.GetType(Record[Idx++])); |
| 862 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 863 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | unsigned PCHStmtReader::VisitChooseExpr(ChooseExpr *E) { |
| 868 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 869 | E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3])); |
| 870 | E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2])); |
| 871 | E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1])); |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 872 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 873 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 874 | return 3; |
| 875 | } |
| 876 | |
| 877 | unsigned PCHStmtReader::VisitGNUNullExpr(GNUNullExpr *E) { |
| 878 | VisitExpr(E); |
| 879 | E->setTokenLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 880 | return 0; |
| 881 | } |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 882 | |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 883 | unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { |
| 884 | VisitExpr(E); |
| 885 | unsigned NumExprs = Record[Idx++]; |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 886 | E->setExprs((Expr **)&StmtStack[StmtStack.size() - NumExprs], NumExprs); |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 887 | E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 888 | E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 889 | return NumExprs; |
| 890 | } |
| 891 | |
Douglas Gregor | e246b74 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 892 | unsigned PCHStmtReader::VisitBlockExpr(BlockExpr *E) { |
| 893 | VisitExpr(E); |
| 894 | E->setBlockDecl(cast_or_null<BlockDecl>(Reader.GetDecl(Record[Idx++]))); |
| 895 | E->setHasBlockDeclRefExprs(Record[Idx++]); |
| 896 | return 0; |
| 897 | } |
| 898 | |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 899 | unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { |
| 900 | VisitExpr(E); |
| 901 | E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++]))); |
| 902 | E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); |
| 903 | E->setByRef(Record[Idx++]); |
| 904 | return 0; |
| 905 | } |
| 906 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 907 | // FIXME: use the diagnostics machinery |
| 908 | static bool Error(const char *Str) { |
| 909 | std::fprintf(stderr, "%s\n", Str); |
| 910 | return true; |
| 911 | } |
| 912 | |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 913 | /// \brief Check the contents of the predefines buffer against the |
| 914 | /// contents of the predefines buffer used to build the PCH file. |
| 915 | /// |
| 916 | /// The contents of the two predefines buffers should be the same. If |
| 917 | /// not, then some command-line option changed the preprocessor state |
| 918 | /// and we must reject the PCH file. |
| 919 | /// |
| 920 | /// \param PCHPredef The start of the predefines buffer in the PCH |
| 921 | /// file. |
| 922 | /// |
| 923 | /// \param PCHPredefLen The length of the predefines buffer in the PCH |
| 924 | /// file. |
| 925 | /// |
| 926 | /// \param PCHBufferID The FileID for the PCH predefines buffer. |
| 927 | /// |
| 928 | /// \returns true if there was a mismatch (in which case the PCH file |
| 929 | /// should be ignored), or false otherwise. |
| 930 | bool PCHReader::CheckPredefinesBuffer(const char *PCHPredef, |
| 931 | unsigned PCHPredefLen, |
| 932 | FileID PCHBufferID) { |
| 933 | const char *Predef = PP.getPredefines().c_str(); |
| 934 | unsigned PredefLen = PP.getPredefines().size(); |
| 935 | |
| 936 | // If the two predefines buffers compare equal, we're done!. |
| 937 | if (PredefLen == PCHPredefLen && |
| 938 | strncmp(Predef, PCHPredef, PCHPredefLen) == 0) |
| 939 | return false; |
| 940 | |
| 941 | // The predefines buffers are different. Produce a reasonable |
| 942 | // diagnostic showing where they are different. |
| 943 | |
| 944 | // The source locations (potentially in the two different predefines |
| 945 | // buffers) |
| 946 | SourceLocation Loc1, Loc2; |
| 947 | SourceManager &SourceMgr = PP.getSourceManager(); |
| 948 | |
| 949 | // Create a source buffer for our predefines string, so |
| 950 | // that we can build a diagnostic that points into that |
| 951 | // source buffer. |
| 952 | FileID BufferID; |
| 953 | if (Predef && Predef[0]) { |
| 954 | llvm::MemoryBuffer *Buffer |
| 955 | = llvm::MemoryBuffer::getMemBuffer(Predef, Predef + PredefLen, |
| 956 | "<built-in>"); |
| 957 | BufferID = SourceMgr.createFileIDForMemBuffer(Buffer); |
| 958 | } |
| 959 | |
| 960 | unsigned MinLen = std::min(PredefLen, PCHPredefLen); |
| 961 | std::pair<const char *, const char *> Locations |
| 962 | = std::mismatch(Predef, Predef + MinLen, PCHPredef); |
| 963 | |
| 964 | if (Locations.first != Predef + MinLen) { |
| 965 | // We found the location in the two buffers where there is a |
| 966 | // difference. Form source locations to point there (in both |
| 967 | // buffers). |
| 968 | unsigned Offset = Locations.first - Predef; |
| 969 | Loc1 = SourceMgr.getLocForStartOfFile(BufferID) |
| 970 | .getFileLocWithOffset(Offset); |
| 971 | Loc2 = SourceMgr.getLocForStartOfFile(PCHBufferID) |
| 972 | .getFileLocWithOffset(Offset); |
| 973 | } else if (PredefLen > PCHPredefLen) { |
| 974 | Loc1 = SourceMgr.getLocForStartOfFile(BufferID) |
| 975 | .getFileLocWithOffset(MinLen); |
| 976 | } else { |
| 977 | Loc1 = SourceMgr.getLocForStartOfFile(PCHBufferID) |
| 978 | .getFileLocWithOffset(MinLen); |
| 979 | } |
| 980 | |
| 981 | Diag(Loc1, diag::warn_pch_preprocessor); |
| 982 | if (Loc2.isValid()) |
| 983 | Diag(Loc2, diag::note_predef_in_pch); |
| 984 | Diag(diag::note_ignoring_pch) << FileName; |
| 985 | return true; |
| 986 | } |
| 987 | |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 988 | /// \brief Read the line table in the source manager block. |
| 989 | /// \returns true if ther was an error. |
| 990 | static bool ParseLineTable(SourceManager &SourceMgr, |
| 991 | llvm::SmallVectorImpl<uint64_t> &Record) { |
| 992 | unsigned Idx = 0; |
| 993 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 994 | |
| 995 | // Parse the file names |
Douglas Gregor | 183ad60 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 996 | std::map<int, int> FileIDs; |
| 997 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 998 | // Extract the file name |
| 999 | unsigned FilenameLen = Record[Idx++]; |
| 1000 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 1001 | Idx += FilenameLen; |
Douglas Gregor | 183ad60 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1002 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
| 1003 | Filename.size()); |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | // Parse the line entries |
| 1007 | std::vector<LineEntry> Entries; |
| 1008 | while (Idx < Record.size()) { |
Douglas Gregor | 183ad60 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1009 | int FID = FileIDs[Record[Idx++]]; |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1010 | |
| 1011 | // Extract the line entries |
| 1012 | unsigned NumEntries = Record[Idx++]; |
| 1013 | Entries.clear(); |
| 1014 | Entries.reserve(NumEntries); |
| 1015 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1016 | unsigned FileOffset = Record[Idx++]; |
| 1017 | unsigned LineNo = Record[Idx++]; |
| 1018 | int FilenameID = Record[Idx++]; |
| 1019 | SrcMgr::CharacteristicKind FileKind |
| 1020 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1021 | unsigned IncludeOffset = Record[Idx++]; |
| 1022 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1023 | FileKind, IncludeOffset)); |
| 1024 | } |
| 1025 | LineTable.AddEntry(FID, Entries); |
| 1026 | } |
| 1027 | |
| 1028 | return false; |
| 1029 | } |
| 1030 | |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1031 | /// \brief Read the source manager block |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1032 | PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock() { |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1033 | using namespace SrcMgr; |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1034 | if (Stream.EnterSubBlock(pch::SOURCE_MANAGER_BLOCK_ID)) { |
| 1035 | Error("Malformed source manager block record"); |
| 1036 | return Failure; |
| 1037 | } |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1038 | |
| 1039 | SourceManager &SourceMgr = Context.getSourceManager(); |
| 1040 | RecordData Record; |
| 1041 | while (true) { |
| 1042 | unsigned Code = Stream.ReadCode(); |
| 1043 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1044 | if (Stream.ReadBlockEnd()) { |
| 1045 | Error("Error at end of Source Manager block"); |
| 1046 | return Failure; |
| 1047 | } |
| 1048 | |
| 1049 | return Success; |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1053 | // No known subblocks, always skip them. |
| 1054 | Stream.ReadSubBlockID(); |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1055 | if (Stream.SkipBlock()) { |
| 1056 | Error("Malformed block record"); |
| 1057 | return Failure; |
| 1058 | } |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1059 | continue; |
| 1060 | } |
| 1061 | |
| 1062 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1063 | Stream.ReadAbbrevRecord(); |
| 1064 | continue; |
| 1065 | } |
| 1066 | |
| 1067 | // Read a record. |
| 1068 | const char *BlobStart; |
| 1069 | unsigned BlobLen; |
| 1070 | Record.clear(); |
| 1071 | switch (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1072 | default: // Default behavior: ignore. |
| 1073 | break; |
| 1074 | |
| 1075 | case pch::SM_SLOC_FILE_ENTRY: { |
| 1076 | // FIXME: We would really like to delay the creation of this |
| 1077 | // FileEntry until it is actually required, e.g., when producing |
| 1078 | // a diagnostic with a source location in this file. |
| 1079 | const FileEntry *File |
| 1080 | = PP.getFileManager().getFile(BlobStart, BlobStart + BlobLen); |
| 1081 | // FIXME: Error recovery if file cannot be found. |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1082 | FileID ID = SourceMgr.createFileID(File, |
| 1083 | SourceLocation::getFromRawEncoding(Record[1]), |
| 1084 | (CharacteristicKind)Record[2]); |
| 1085 | if (Record[3]) |
| 1086 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(ID).getFile()) |
| 1087 | .setHasLineDirectives(); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1088 | break; |
| 1089 | } |
| 1090 | |
| 1091 | case pch::SM_SLOC_BUFFER_ENTRY: { |
| 1092 | const char *Name = BlobStart; |
| 1093 | unsigned Code = Stream.ReadCode(); |
| 1094 | Record.clear(); |
| 1095 | unsigned RecCode = Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 1096 | assert(RecCode == pch::SM_SLOC_BUFFER_BLOB && "Ill-formed PCH file"); |
Douglas Gregor | 3c8ff3e | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 1097 | (void)RecCode; |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1098 | llvm::MemoryBuffer *Buffer |
| 1099 | = llvm::MemoryBuffer::getMemBuffer(BlobStart, |
| 1100 | BlobStart + BlobLen - 1, |
| 1101 | Name); |
| 1102 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer); |
| 1103 | |
| 1104 | if (strcmp(Name, "<built-in>") == 0 |
| 1105 | && CheckPredefinesBuffer(BlobStart, BlobLen - 1, BufferID)) |
| 1106 | return IgnorePCH; |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | case pch::SM_SLOC_INSTANTIATION_ENTRY: { |
| 1111 | SourceLocation SpellingLoc |
| 1112 | = SourceLocation::getFromRawEncoding(Record[1]); |
| 1113 | SourceMgr.createInstantiationLoc( |
| 1114 | SpellingLoc, |
| 1115 | SourceLocation::getFromRawEncoding(Record[2]), |
| 1116 | SourceLocation::getFromRawEncoding(Record[3]), |
Douglas Gregor | 364e580 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1117 | Record[4]); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1118 | break; |
| 1119 | } |
| 1120 | |
Chris Lattner | e1be602 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1121 | case pch::SM_LINE_TABLE: |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1122 | if (ParseLineTable(SourceMgr, Record)) |
| 1123 | return Failure; |
Chris Lattner | e1be602 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1124 | break; |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | } |
| 1128 | |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1129 | bool PCHReader::ReadPreprocessorBlock() { |
| 1130 | if (Stream.EnterSubBlock(pch::PREPROCESSOR_BLOCK_ID)) |
| 1131 | return Error("Malformed preprocessor block record"); |
| 1132 | |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1133 | RecordData Record; |
| 1134 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1135 | MacroInfo *LastMacro = 0; |
| 1136 | |
| 1137 | while (true) { |
| 1138 | unsigned Code = Stream.ReadCode(); |
| 1139 | switch (Code) { |
| 1140 | case llvm::bitc::END_BLOCK: |
| 1141 | if (Stream.ReadBlockEnd()) |
| 1142 | return Error("Error at end of preprocessor block"); |
| 1143 | return false; |
| 1144 | |
| 1145 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1146 | // No known subblocks, always skip them. |
| 1147 | Stream.ReadSubBlockID(); |
| 1148 | if (Stream.SkipBlock()) |
| 1149 | return Error("Malformed block record"); |
| 1150 | continue; |
| 1151 | |
| 1152 | case llvm::bitc::DEFINE_ABBREV: |
| 1153 | Stream.ReadAbbrevRecord(); |
| 1154 | continue; |
| 1155 | default: break; |
| 1156 | } |
| 1157 | |
| 1158 | // Read a record. |
| 1159 | Record.clear(); |
| 1160 | pch::PreprocessorRecordTypes RecType = |
| 1161 | (pch::PreprocessorRecordTypes)Stream.ReadRecord(Code, Record); |
| 1162 | switch (RecType) { |
| 1163 | default: // Default behavior: ignore unknown records. |
| 1164 | break; |
Chris Lattner | 4b21c20 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1165 | case pch::PP_COUNTER_VALUE: |
| 1166 | if (!Record.empty()) |
| 1167 | PP.setCounterValue(Record[0]); |
| 1168 | break; |
| 1169 | |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1170 | case pch::PP_MACRO_OBJECT_LIKE: |
| 1171 | case pch::PP_MACRO_FUNCTION_LIKE: { |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1172 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1173 | if (II == 0) |
| 1174 | return Error("Macro must have a name"); |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1175 | SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[1]); |
| 1176 | bool isUsed = Record[2]; |
| 1177 | |
| 1178 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
| 1179 | MI->setIsUsed(isUsed); |
| 1180 | |
| 1181 | if (RecType == pch::PP_MACRO_FUNCTION_LIKE) { |
| 1182 | // Decode function-like macro info. |
| 1183 | bool isC99VarArgs = Record[3]; |
| 1184 | bool isGNUVarArgs = Record[4]; |
| 1185 | MacroArgs.clear(); |
| 1186 | unsigned NumArgs = Record[5]; |
| 1187 | for (unsigned i = 0; i != NumArgs; ++i) |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1188 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1189 | |
| 1190 | // Install function-like macro info. |
| 1191 | MI->setIsFunctionLike(); |
| 1192 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1193 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1194 | MI->setArgumentList(&MacroArgs[0], MacroArgs.size(), |
| 1195 | PP.getPreprocessorAllocator()); |
| 1196 | } |
| 1197 | |
| 1198 | // Finally, install the macro. |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1199 | PP.setMacroInfo(II, MI); |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1200 | |
| 1201 | // Remember that we saw this macro last so that we add the tokens that |
| 1202 | // form its body to it. |
| 1203 | LastMacro = MI; |
| 1204 | break; |
| 1205 | } |
| 1206 | |
| 1207 | case pch::PP_TOKEN: { |
| 1208 | // If we see a TOKEN before a PP_MACRO_*, then the file is eroneous, just |
| 1209 | // pretend we didn't see this. |
| 1210 | if (LastMacro == 0) break; |
| 1211 | |
| 1212 | Token Tok; |
| 1213 | Tok.startToken(); |
| 1214 | Tok.setLocation(SourceLocation::getFromRawEncoding(Record[0])); |
| 1215 | Tok.setLength(Record[1]); |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1216 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1217 | Tok.setIdentifierInfo(II); |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1218 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1219 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1220 | LastMacro->AddTokenToBody(Tok); |
| 1221 | break; |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1227 | PCHReader::PCHReadResult PCHReader::ReadPCHBlock() { |
| 1228 | if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) { |
| 1229 | Error("Malformed block record"); |
| 1230 | return Failure; |
| 1231 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1232 | |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1233 | uint64_t PreprocessorBlockBit = 0; |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1234 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1235 | // Read all of the records and blocks for the PCH file. |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1236 | RecordData Record; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1237 | while (!Stream.AtEndOfStream()) { |
| 1238 | unsigned Code = Stream.ReadCode(); |
| 1239 | if (Code == llvm::bitc::END_BLOCK) { |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1240 | // If we saw the preprocessor block, read it now. |
| 1241 | if (PreprocessorBlockBit) { |
| 1242 | uint64_t SavedPos = Stream.GetCurrentBitNo(); |
| 1243 | Stream.JumpToBit(PreprocessorBlockBit); |
| 1244 | if (ReadPreprocessorBlock()) { |
| 1245 | Error("Malformed preprocessor block"); |
| 1246 | return Failure; |
| 1247 | } |
| 1248 | Stream.JumpToBit(SavedPos); |
| 1249 | } |
| 1250 | |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1251 | if (Stream.ReadBlockEnd()) { |
| 1252 | Error("Error at end of module block"); |
| 1253 | return Failure; |
| 1254 | } |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1255 | |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1256 | return Success; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1260 | switch (Stream.ReadSubBlockID()) { |
| 1261 | case pch::DECLS_BLOCK_ID: // Skip decls block (lazily loaded) |
| 1262 | case pch::TYPES_BLOCK_ID: // Skip types block (lazily loaded) |
| 1263 | default: // Skip unknown content. |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1264 | if (Stream.SkipBlock()) { |
| 1265 | Error("Malformed block record"); |
| 1266 | return Failure; |
| 1267 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1268 | break; |
| 1269 | |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1270 | case pch::PREPROCESSOR_BLOCK_ID: |
| 1271 | // Skip the preprocessor block for now, but remember where it is. We |
| 1272 | // want to read it in after the identifier table. |
| 1273 | if (PreprocessorBlockBit) { |
| 1274 | Error("Multiple preprocessor blocks found."); |
| 1275 | return Failure; |
| 1276 | } |
| 1277 | PreprocessorBlockBit = Stream.GetCurrentBitNo(); |
| 1278 | if (Stream.SkipBlock()) { |
| 1279 | Error("Malformed block record"); |
| 1280 | return Failure; |
| 1281 | } |
| 1282 | break; |
| 1283 | |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1284 | case pch::SOURCE_MANAGER_BLOCK_ID: |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1285 | switch (ReadSourceManagerBlock()) { |
| 1286 | case Success: |
| 1287 | break; |
| 1288 | |
| 1289 | case Failure: |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1290 | Error("Malformed source manager block"); |
| 1291 | return Failure; |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1292 | |
| 1293 | case IgnorePCH: |
| 1294 | return IgnorePCH; |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1295 | } |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1296 | break; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1297 | } |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1298 | continue; |
| 1299 | } |
| 1300 | |
| 1301 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1302 | Stream.ReadAbbrevRecord(); |
| 1303 | continue; |
| 1304 | } |
| 1305 | |
| 1306 | // Read and process a record. |
| 1307 | Record.clear(); |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1308 | const char *BlobStart = 0; |
| 1309 | unsigned BlobLen = 0; |
| 1310 | switch ((pch::PCHRecordTypes)Stream.ReadRecord(Code, Record, |
| 1311 | &BlobStart, &BlobLen)) { |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1312 | default: // Default behavior: ignore. |
| 1313 | break; |
| 1314 | |
| 1315 | case pch::TYPE_OFFSET: |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1316 | if (!TypeOffsets.empty()) { |
| 1317 | Error("Duplicate TYPE_OFFSET record in PCH file"); |
| 1318 | return Failure; |
| 1319 | } |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1320 | TypeOffsets.swap(Record); |
| 1321 | TypeAlreadyLoaded.resize(TypeOffsets.size(), false); |
| 1322 | break; |
| 1323 | |
| 1324 | case pch::DECL_OFFSET: |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1325 | if (!DeclOffsets.empty()) { |
| 1326 | Error("Duplicate DECL_OFFSET record in PCH file"); |
| 1327 | return Failure; |
| 1328 | } |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1329 | DeclOffsets.swap(Record); |
| 1330 | DeclAlreadyLoaded.resize(DeclOffsets.size(), false); |
| 1331 | break; |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1332 | |
| 1333 | case pch::LANGUAGE_OPTIONS: |
| 1334 | if (ParseLanguageOptions(Record)) |
| 1335 | return IgnorePCH; |
| 1336 | break; |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1337 | |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1338 | case pch::TARGET_TRIPLE: { |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1339 | std::string TargetTriple(BlobStart, BlobLen); |
| 1340 | if (TargetTriple != Context.Target.getTargetTriple()) { |
| 1341 | Diag(diag::warn_pch_target_triple) |
| 1342 | << TargetTriple << Context.Target.getTargetTriple(); |
| 1343 | Diag(diag::note_ignoring_pch) << FileName; |
| 1344 | return IgnorePCH; |
| 1345 | } |
| 1346 | break; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1347 | } |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1348 | |
| 1349 | case pch::IDENTIFIER_TABLE: |
| 1350 | IdentifierTable = BlobStart; |
| 1351 | break; |
| 1352 | |
| 1353 | case pch::IDENTIFIER_OFFSET: |
| 1354 | if (!IdentifierData.empty()) { |
| 1355 | Error("Duplicate IDENTIFIER_OFFSET record in PCH file"); |
| 1356 | return Failure; |
| 1357 | } |
| 1358 | IdentifierData.swap(Record); |
| 1359 | #ifndef NDEBUG |
| 1360 | for (unsigned I = 0, N = IdentifierData.size(); I != N; ++I) { |
| 1361 | if ((IdentifierData[I] & 0x01) == 0) { |
| 1362 | Error("Malformed identifier table in the precompiled header"); |
| 1363 | return Failure; |
| 1364 | } |
| 1365 | } |
| 1366 | #endif |
| 1367 | break; |
Douglas Gregor | 631f6c6 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1368 | |
| 1369 | case pch::EXTERNAL_DEFINITIONS: |
| 1370 | if (!ExternalDefinitions.empty()) { |
| 1371 | Error("Duplicate EXTERNAL_DEFINITIONS record in PCH file"); |
| 1372 | return Failure; |
| 1373 | } |
| 1374 | ExternalDefinitions.swap(Record); |
| 1375 | break; |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1376 | |
Douglas Gregor | e01ad44 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1377 | case pch::SPECIAL_TYPES: |
| 1378 | SpecialTypes.swap(Record); |
| 1379 | break; |
| 1380 | |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1381 | case pch::STATISTICS: |
| 1382 | TotalNumStatements = Record[0]; |
| 1383 | break; |
| 1384 | |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1385 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1388 | Error("Premature end of bitstream"); |
| 1389 | return Failure; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1392 | PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) { |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1393 | // Set the PCH file name. |
| 1394 | this->FileName = FileName; |
| 1395 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1396 | // Open the PCH file. |
| 1397 | std::string ErrStr; |
| 1398 | Buffer.reset(llvm::MemoryBuffer::getFile(FileName.c_str(), &ErrStr)); |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1399 | if (!Buffer) { |
| 1400 | Error(ErrStr.c_str()); |
| 1401 | return IgnorePCH; |
| 1402 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1403 | |
| 1404 | // Initialize the stream |
| 1405 | Stream.init((const unsigned char *)Buffer->getBufferStart(), |
| 1406 | (const unsigned char *)Buffer->getBufferEnd()); |
| 1407 | |
| 1408 | // Sniff for the signature. |
| 1409 | if (Stream.Read(8) != 'C' || |
| 1410 | Stream.Read(8) != 'P' || |
| 1411 | Stream.Read(8) != 'C' || |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1412 | Stream.Read(8) != 'H') { |
| 1413 | Error("Not a PCH file"); |
| 1414 | return IgnorePCH; |
| 1415 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1416 | |
| 1417 | // We expect a number of well-defined blocks, though we don't necessarily |
| 1418 | // need to understand them all. |
| 1419 | while (!Stream.AtEndOfStream()) { |
| 1420 | unsigned Code = Stream.ReadCode(); |
| 1421 | |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1422 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
| 1423 | Error("Invalid record at top-level"); |
| 1424 | return Failure; |
| 1425 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1426 | |
| 1427 | unsigned BlockID = Stream.ReadSubBlockID(); |
| 1428 | |
| 1429 | // We only know the PCH subblock ID. |
| 1430 | switch (BlockID) { |
| 1431 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1432 | if (Stream.ReadBlockInfoBlock()) { |
| 1433 | Error("Malformed BlockInfoBlock"); |
| 1434 | return Failure; |
| 1435 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1436 | break; |
| 1437 | case pch::PCH_BLOCK_ID: |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1438 | switch (ReadPCHBlock()) { |
| 1439 | case Success: |
| 1440 | break; |
| 1441 | |
| 1442 | case Failure: |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1443 | return Failure; |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1444 | |
| 1445 | case IgnorePCH: |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1446 | // FIXME: We could consider reading through to the end of this |
| 1447 | // PCH block, skipping subblocks, to see if there are other |
| 1448 | // PCH blocks elsewhere. |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1449 | return IgnorePCH; |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1450 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1451 | break; |
| 1452 | default: |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1453 | if (Stream.SkipBlock()) { |
| 1454 | Error("Malformed block record"); |
| 1455 | return Failure; |
| 1456 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1457 | break; |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | // Load the translation unit declaration |
| 1462 | ReadDeclRecord(DeclOffsets[0], 0); |
| 1463 | |
Douglas Gregor | e01ad44 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1464 | // Load the special types. |
| 1465 | Context.setBuiltinVaListType( |
| 1466 | GetType(SpecialTypes[pch::SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 1467 | |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1468 | return Success; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1471 | namespace { |
| 1472 | /// \brief Helper class that saves the current stream position and |
| 1473 | /// then restores it when destroyed. |
| 1474 | struct VISIBILITY_HIDDEN SavedStreamPosition { |
| 1475 | explicit SavedStreamPosition(llvm::BitstreamReader &Stream) |
Douglas Gregor | 6dc849b | 2009-04-15 04:54:29 +0000 | [diff] [blame] | 1476 | : Stream(Stream), Offset(Stream.GetCurrentBitNo()) { } |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1477 | |
| 1478 | ~SavedStreamPosition() { |
Douglas Gregor | 6dc849b | 2009-04-15 04:54:29 +0000 | [diff] [blame] | 1479 | Stream.JumpToBit(Offset); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | private: |
| 1483 | llvm::BitstreamReader &Stream; |
| 1484 | uint64_t Offset; |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1485 | }; |
| 1486 | } |
| 1487 | |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1488 | /// \brief Parse the record that corresponds to a LangOptions data |
| 1489 | /// structure. |
| 1490 | /// |
| 1491 | /// This routine compares the language options used to generate the |
| 1492 | /// PCH file against the language options set for the current |
| 1493 | /// compilation. For each option, we classify differences between the |
| 1494 | /// two compiler states as either "benign" or "important". Benign |
| 1495 | /// differences don't matter, and we accept them without complaint |
| 1496 | /// (and without modifying the language options). Differences between |
| 1497 | /// the states for important options cause the PCH file to be |
| 1498 | /// unusable, so we emit a warning and return true to indicate that |
| 1499 | /// there was an error. |
| 1500 | /// |
| 1501 | /// \returns true if the PCH file is unacceptable, false otherwise. |
| 1502 | bool PCHReader::ParseLanguageOptions( |
| 1503 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
| 1504 | const LangOptions &LangOpts = Context.getLangOptions(); |
| 1505 | #define PARSE_LANGOPT_BENIGN(Option) ++Idx |
| 1506 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 1507 | if (Record[Idx] != LangOpts.Option) { \ |
| 1508 | Diag(DiagID) << (unsigned)Record[Idx] << LangOpts.Option; \ |
| 1509 | Diag(diag::note_ignoring_pch) << FileName; \ |
| 1510 | return true; \ |
| 1511 | } \ |
| 1512 | ++Idx |
| 1513 | |
| 1514 | unsigned Idx = 0; |
| 1515 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 1516 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 1517 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 1518 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 1519 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
| 1520 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 1521 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 1522 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 1523 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 1524 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
| 1525 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 1526 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 1527 | PARSE_LANGOPT_IMPORTANT(NoExtensions, diag::warn_pch_extensions); |
| 1528 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 1529 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 1530 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 1531 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
| 1532 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 1533 | PARSE_LANGOPT_BENIGN(Boolean); |
| 1534 | PARSE_LANGOPT_BENIGN(WritableStrings); |
| 1535 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
| 1536 | diag::warn_pch_lax_vector_conversions); |
| 1537 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
| 1538 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 1539 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 1540 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
| 1541 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
| 1542 | diag::warn_pch_thread_safe_statics); |
| 1543 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 1544 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 1545 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
| 1546 | PARSE_LANGOPT_IMPORTANT(OverflowChecking, diag::warn_pch_overflow_checking); |
| 1547 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
| 1548 | diag::warn_pch_heinous_extensions); |
| 1549 | // FIXME: Most of the options below are benign if the macro wasn't |
| 1550 | // used. Unfortunately, this means that a PCH compiled without |
| 1551 | // optimization can't be used with optimization turned on, even |
| 1552 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 1553 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 1554 | // doesn't matter. We could consider making this some special kind |
| 1555 | // of check. |
| 1556 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 1557 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 1558 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 1559 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 1560 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 1561 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 1562 | if ((LangOpts.getGCMode() != 0) != (Record[Idx] != 0)) { |
| 1563 | Diag(diag::warn_pch_gc_mode) |
| 1564 | << (unsigned)Record[Idx] << LangOpts.getGCMode(); |
| 1565 | Diag(diag::note_ignoring_pch) << FileName; |
| 1566 | return true; |
| 1567 | } |
| 1568 | ++Idx; |
| 1569 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
| 1570 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
| 1571 | #undef PARSE_LANGOPT_IRRELEVANT |
| 1572 | #undef PARSE_LANGOPT_BENIGN |
| 1573 | |
| 1574 | return false; |
| 1575 | } |
| 1576 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1577 | /// \brief Read and return the type at the given offset. |
| 1578 | /// |
| 1579 | /// This routine actually reads the record corresponding to the type |
| 1580 | /// at the given offset in the bitstream. It is a helper routine for |
| 1581 | /// GetType, which deals with reading type IDs. |
| 1582 | QualType PCHReader::ReadTypeRecord(uint64_t Offset) { |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1583 | // Keep track of where we are in the stream, then jump back there |
| 1584 | // after reading this type. |
| 1585 | SavedStreamPosition SavedPosition(Stream); |
| 1586 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1587 | Stream.JumpToBit(Offset); |
| 1588 | RecordData Record; |
| 1589 | unsigned Code = Stream.ReadCode(); |
| 1590 | switch ((pch::TypeCode)Stream.ReadRecord(Code, Record)) { |
Douglas Gregor | bdd4ba5 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 1591 | case pch::TYPE_EXT_QUAL: { |
| 1592 | assert(Record.size() == 3 && |
| 1593 | "Incorrect encoding of extended qualifier type"); |
| 1594 | QualType Base = GetType(Record[0]); |
| 1595 | QualType::GCAttrTypes GCAttr = (QualType::GCAttrTypes)Record[1]; |
| 1596 | unsigned AddressSpace = Record[2]; |
| 1597 | |
| 1598 | QualType T = Base; |
| 1599 | if (GCAttr != QualType::GCNone) |
| 1600 | T = Context.getObjCGCQualType(T, GCAttr); |
| 1601 | if (AddressSpace) |
| 1602 | T = Context.getAddrSpaceQualType(T, AddressSpace); |
| 1603 | return T; |
| 1604 | } |
Douglas Gregor | 88fd09d | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1605 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1606 | case pch::TYPE_FIXED_WIDTH_INT: { |
| 1607 | assert(Record.size() == 2 && "Incorrect encoding of fixed-width int type"); |
| 1608 | return Context.getFixedWidthIntType(Record[0], Record[1]); |
| 1609 | } |
| 1610 | |
| 1611 | case pch::TYPE_COMPLEX: { |
| 1612 | assert(Record.size() == 1 && "Incorrect encoding of complex type"); |
| 1613 | QualType ElemType = GetType(Record[0]); |
| 1614 | return Context.getComplexType(ElemType); |
| 1615 | } |
| 1616 | |
| 1617 | case pch::TYPE_POINTER: { |
| 1618 | assert(Record.size() == 1 && "Incorrect encoding of pointer type"); |
| 1619 | QualType PointeeType = GetType(Record[0]); |
| 1620 | return Context.getPointerType(PointeeType); |
| 1621 | } |
| 1622 | |
| 1623 | case pch::TYPE_BLOCK_POINTER: { |
| 1624 | assert(Record.size() == 1 && "Incorrect encoding of block pointer type"); |
| 1625 | QualType PointeeType = GetType(Record[0]); |
| 1626 | return Context.getBlockPointerType(PointeeType); |
| 1627 | } |
| 1628 | |
| 1629 | case pch::TYPE_LVALUE_REFERENCE: { |
| 1630 | assert(Record.size() == 1 && "Incorrect encoding of lvalue reference type"); |
| 1631 | QualType PointeeType = GetType(Record[0]); |
| 1632 | return Context.getLValueReferenceType(PointeeType); |
| 1633 | } |
| 1634 | |
| 1635 | case pch::TYPE_RVALUE_REFERENCE: { |
| 1636 | assert(Record.size() == 1 && "Incorrect encoding of rvalue reference type"); |
| 1637 | QualType PointeeType = GetType(Record[0]); |
| 1638 | return Context.getRValueReferenceType(PointeeType); |
| 1639 | } |
| 1640 | |
| 1641 | case pch::TYPE_MEMBER_POINTER: { |
| 1642 | assert(Record.size() == 1 && "Incorrect encoding of member pointer type"); |
| 1643 | QualType PointeeType = GetType(Record[0]); |
| 1644 | QualType ClassType = GetType(Record[1]); |
| 1645 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
| 1646 | } |
| 1647 | |
Douglas Gregor | 88fd09d | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1648 | case pch::TYPE_CONSTANT_ARRAY: { |
| 1649 | QualType ElementType = GetType(Record[0]); |
| 1650 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 1651 | unsigned IndexTypeQuals = Record[2]; |
| 1652 | unsigned Idx = 3; |
| 1653 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 1654 | return Context.getConstantArrayType(ElementType, Size, ASM, IndexTypeQuals); |
| 1655 | } |
| 1656 | |
| 1657 | case pch::TYPE_INCOMPLETE_ARRAY: { |
| 1658 | QualType ElementType = GetType(Record[0]); |
| 1659 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 1660 | unsigned IndexTypeQuals = Record[2]; |
| 1661 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
| 1662 | } |
| 1663 | |
| 1664 | case pch::TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1665 | QualType ElementType = GetType(Record[0]); |
| 1666 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 1667 | unsigned IndexTypeQuals = Record[2]; |
| 1668 | return Context.getVariableArrayType(ElementType, ReadExpr(), |
| 1669 | ASM, IndexTypeQuals); |
Douglas Gregor | 88fd09d | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | case pch::TYPE_VECTOR: { |
| 1673 | if (Record.size() != 2) { |
| 1674 | Error("Incorrect encoding of vector type in PCH file"); |
| 1675 | return QualType(); |
| 1676 | } |
| 1677 | |
| 1678 | QualType ElementType = GetType(Record[0]); |
| 1679 | unsigned NumElements = Record[1]; |
| 1680 | return Context.getVectorType(ElementType, NumElements); |
| 1681 | } |
| 1682 | |
| 1683 | case pch::TYPE_EXT_VECTOR: { |
| 1684 | if (Record.size() != 2) { |
| 1685 | Error("Incorrect encoding of extended vector type in PCH file"); |
| 1686 | return QualType(); |
| 1687 | } |
| 1688 | |
| 1689 | QualType ElementType = GetType(Record[0]); |
| 1690 | unsigned NumElements = Record[1]; |
| 1691 | return Context.getExtVectorType(ElementType, NumElements); |
| 1692 | } |
| 1693 | |
| 1694 | case pch::TYPE_FUNCTION_NO_PROTO: { |
| 1695 | if (Record.size() != 1) { |
| 1696 | Error("Incorrect encoding of no-proto function type"); |
| 1697 | return QualType(); |
| 1698 | } |
| 1699 | QualType ResultType = GetType(Record[0]); |
| 1700 | return Context.getFunctionNoProtoType(ResultType); |
| 1701 | } |
| 1702 | |
| 1703 | case pch::TYPE_FUNCTION_PROTO: { |
| 1704 | QualType ResultType = GetType(Record[0]); |
| 1705 | unsigned Idx = 1; |
| 1706 | unsigned NumParams = Record[Idx++]; |
| 1707 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 1708 | for (unsigned I = 0; I != NumParams; ++I) |
| 1709 | ParamTypes.push_back(GetType(Record[Idx++])); |
| 1710 | bool isVariadic = Record[Idx++]; |
| 1711 | unsigned Quals = Record[Idx++]; |
| 1712 | return Context.getFunctionType(ResultType, &ParamTypes[0], NumParams, |
| 1713 | isVariadic, Quals); |
| 1714 | } |
| 1715 | |
| 1716 | case pch::TYPE_TYPEDEF: |
| 1717 | assert(Record.size() == 1 && "Incorrect encoding of typedef type"); |
| 1718 | return Context.getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0]))); |
| 1719 | |
| 1720 | case pch::TYPE_TYPEOF_EXPR: |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1721 | return Context.getTypeOfExprType(ReadExpr()); |
Douglas Gregor | 88fd09d | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1722 | |
| 1723 | case pch::TYPE_TYPEOF: { |
| 1724 | if (Record.size() != 1) { |
| 1725 | Error("Incorrect encoding of typeof(type) in PCH file"); |
| 1726 | return QualType(); |
| 1727 | } |
| 1728 | QualType UnderlyingType = GetType(Record[0]); |
| 1729 | return Context.getTypeOfType(UnderlyingType); |
| 1730 | } |
| 1731 | |
| 1732 | case pch::TYPE_RECORD: |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 1733 | assert(Record.size() == 1 && "Incorrect encoding of record type"); |
| 1734 | return Context.getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0]))); |
Douglas Gregor | 88fd09d | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1735 | |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 1736 | case pch::TYPE_ENUM: |
| 1737 | assert(Record.size() == 1 && "Incorrect encoding of enum type"); |
| 1738 | return Context.getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0]))); |
| 1739 | |
Douglas Gregor | 88fd09d | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1740 | case pch::TYPE_OBJC_INTERFACE: |
| 1741 | // FIXME: Deserialize ObjCInterfaceType |
| 1742 | assert(false && "Cannot de-serialize ObjC interface types yet"); |
| 1743 | return QualType(); |
| 1744 | |
| 1745 | case pch::TYPE_OBJC_QUALIFIED_INTERFACE: |
| 1746 | // FIXME: Deserialize ObjCQualifiedInterfaceType |
| 1747 | assert(false && "Cannot de-serialize ObjC qualified interface types yet"); |
| 1748 | return QualType(); |
| 1749 | |
| 1750 | case pch::TYPE_OBJC_QUALIFIED_ID: |
| 1751 | // FIXME: Deserialize ObjCQualifiedIdType |
| 1752 | assert(false && "Cannot de-serialize ObjC qualified id types yet"); |
| 1753 | return QualType(); |
| 1754 | |
| 1755 | case pch::TYPE_OBJC_QUALIFIED_CLASS: |
| 1756 | // FIXME: Deserialize ObjCQualifiedClassType |
| 1757 | assert(false && "Cannot de-serialize ObjC qualified class types yet"); |
| 1758 | return QualType(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | // Suppress a GCC warning |
| 1762 | return QualType(); |
| 1763 | } |
| 1764 | |
| 1765 | /// \brief Note that we have loaded the declaration with the given |
| 1766 | /// Index. |
| 1767 | /// |
| 1768 | /// This routine notes that this declaration has already been loaded, |
| 1769 | /// so that future GetDecl calls will return this declaration rather |
| 1770 | /// than trying to load a new declaration. |
| 1771 | inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) { |
| 1772 | assert(!DeclAlreadyLoaded[Index] && "Decl loaded twice?"); |
| 1773 | DeclAlreadyLoaded[Index] = true; |
| 1774 | DeclOffsets[Index] = reinterpret_cast<uint64_t>(D); |
| 1775 | } |
| 1776 | |
| 1777 | /// \brief Read the declaration at the given offset from the PCH file. |
| 1778 | Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1779 | // Keep track of where we are in the stream, then jump back there |
| 1780 | // after reading this declaration. |
| 1781 | SavedStreamPosition SavedPosition(Stream); |
| 1782 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1783 | Decl *D = 0; |
| 1784 | Stream.JumpToBit(Offset); |
| 1785 | RecordData Record; |
| 1786 | unsigned Code = Stream.ReadCode(); |
| 1787 | unsigned Idx = 0; |
| 1788 | PCHDeclReader Reader(*this, Record, Idx); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1789 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1790 | switch ((pch::DeclCode)Stream.ReadRecord(Code, Record)) { |
Douglas Gregor | 1c50788 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1791 | case pch::DECL_ATTR: |
| 1792 | case pch::DECL_CONTEXT_LEXICAL: |
| 1793 | case pch::DECL_CONTEXT_VISIBLE: |
| 1794 | assert(false && "Record cannot be de-serialized with ReadDeclRecord"); |
| 1795 | break; |
| 1796 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1797 | case pch::DECL_TRANSLATION_UNIT: |
| 1798 | assert(Index == 0 && "Translation unit must be at index 0"); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1799 | D = Context.getTranslationUnitDecl(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1800 | break; |
| 1801 | |
| 1802 | case pch::DECL_TYPEDEF: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1803 | D = TypedefDecl::Create(Context, 0, SourceLocation(), 0, QualType()); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1804 | break; |
| 1805 | } |
| 1806 | |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 1807 | case pch::DECL_ENUM: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1808 | D = EnumDecl::Create(Context, 0, SourceLocation(), 0, 0); |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 1809 | break; |
| 1810 | } |
| 1811 | |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 1812 | case pch::DECL_RECORD: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1813 | D = RecordDecl::Create(Context, TagDecl::TK_struct, 0, SourceLocation(), |
| 1814 | 0, 0); |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 1815 | break; |
| 1816 | } |
| 1817 | |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 1818 | case pch::DECL_ENUM_CONSTANT: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1819 | D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(), |
| 1820 | 0, llvm::APSInt()); |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 1821 | break; |
| 1822 | } |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 1823 | |
| 1824 | case pch::DECL_FUNCTION: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1825 | D = FunctionDecl::Create(Context, 0, SourceLocation(), DeclarationName(), |
| 1826 | QualType()); |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 1827 | break; |
| 1828 | } |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 1829 | |
Steve Naroff | 79ea0e0 | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 1830 | case pch::DECL_OBJC_METHOD: { |
| 1831 | D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(), |
| 1832 | Selector(), QualType(), 0); |
| 1833 | break; |
| 1834 | } |
| 1835 | |
Steve Naroff | 7333b49 | 2009-04-20 20:09:33 +0000 | [diff] [blame^] | 1836 | case pch::DECL_OBJC_INTERFACE_DECL: { |
| 1837 | D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0); |
| 1838 | break; |
| 1839 | } |
| 1840 | |
| 1841 | case pch::DECL_OBJC_IVAR_DECL: { |
| 1842 | D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), 0, QualType(), |
| 1843 | ObjCIvarDecl::None); |
| 1844 | break; |
| 1845 | } |
| 1846 | |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 1847 | case pch::DECL_FIELD: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1848 | D = FieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(), 0, |
| 1849 | false); |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 1850 | break; |
| 1851 | } |
| 1852 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1853 | case pch::DECL_VAR: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1854 | D = VarDecl::Create(Context, 0, SourceLocation(), 0, QualType(), |
| 1855 | VarDecl::None, SourceLocation()); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1856 | break; |
| 1857 | } |
| 1858 | |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 1859 | case pch::DECL_PARM_VAR: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1860 | D = ParmVarDecl::Create(Context, 0, SourceLocation(), 0, QualType(), |
| 1861 | VarDecl::None, 0); |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 1862 | break; |
| 1863 | } |
| 1864 | |
| 1865 | case pch::DECL_ORIGINAL_PARM_VAR: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1866 | D = OriginalParmVarDecl::Create(Context, 0, SourceLocation(), 0, |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 1867 | QualType(), QualType(), VarDecl::None, |
| 1868 | 0); |
Douglas Gregor | 23ce3a5 | 2009-04-13 22:18:37 +0000 | [diff] [blame] | 1869 | break; |
| 1870 | } |
| 1871 | |
Douglas Gregor | 2a49179 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 1872 | case pch::DECL_FILE_SCOPE_ASM: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1873 | D = FileScopeAsmDecl::Create(Context, 0, SourceLocation(), 0); |
Douglas Gregor | 2a49179 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 1874 | break; |
| 1875 | } |
| 1876 | |
| 1877 | case pch::DECL_BLOCK: { |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1878 | D = BlockDecl::Create(Context, 0, SourceLocation()); |
Douglas Gregor | 2a49179 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 1879 | break; |
| 1880 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
Douglas Gregor | ddf4d09 | 2009-04-16 22:29:51 +0000 | [diff] [blame] | 1883 | assert(D && "Unknown declaration creating PCH file"); |
| 1884 | if (D) { |
| 1885 | LoadedDecl(Index, D); |
| 1886 | Reader.Visit(D); |
| 1887 | } |
| 1888 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1889 | // If this declaration is also a declaration context, get the |
| 1890 | // offsets for its tables of lexical and visible declarations. |
| 1891 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 1892 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
| 1893 | if (Offsets.first || Offsets.second) { |
| 1894 | DC->setHasExternalLexicalStorage(Offsets.first != 0); |
| 1895 | DC->setHasExternalVisibleStorage(Offsets.second != 0); |
| 1896 | DeclContextOffsets[DC] = Offsets; |
| 1897 | } |
| 1898 | } |
| 1899 | assert(Idx == Record.size()); |
| 1900 | |
| 1901 | return D; |
| 1902 | } |
| 1903 | |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1904 | QualType PCHReader::GetType(pch::TypeID ID) { |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1905 | unsigned Quals = ID & 0x07; |
| 1906 | unsigned Index = ID >> 3; |
| 1907 | |
| 1908 | if (Index < pch::NUM_PREDEF_TYPE_IDS) { |
| 1909 | QualType T; |
| 1910 | switch ((pch::PredefinedTypeIDs)Index) { |
| 1911 | case pch::PREDEF_TYPE_NULL_ID: return QualType(); |
| 1912 | case pch::PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 1913 | case pch::PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
| 1914 | |
| 1915 | case pch::PREDEF_TYPE_CHAR_U_ID: |
| 1916 | case pch::PREDEF_TYPE_CHAR_S_ID: |
| 1917 | // FIXME: Check that the signedness of CharTy is correct! |
| 1918 | T = Context.CharTy; |
| 1919 | break; |
| 1920 | |
| 1921 | case pch::PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 1922 | case pch::PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 1923 | case pch::PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 1924 | case pch::PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 1925 | case pch::PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 1926 | case pch::PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 1927 | case pch::PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 1928 | case pch::PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 1929 | case pch::PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 1930 | case pch::PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 1931 | case pch::PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 1932 | case pch::PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 1933 | case pch::PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 1934 | case pch::PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 1935 | case pch::PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 1936 | case pch::PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 1937 | } |
| 1938 | |
| 1939 | assert(!T.isNull() && "Unknown predefined type"); |
| 1940 | return T.getQualifiedType(Quals); |
| 1941 | } |
| 1942 | |
| 1943 | Index -= pch::NUM_PREDEF_TYPE_IDS; |
| 1944 | if (!TypeAlreadyLoaded[Index]) { |
| 1945 | // Load the type from the PCH file. |
| 1946 | TypeOffsets[Index] = reinterpret_cast<uint64_t>( |
| 1947 | ReadTypeRecord(TypeOffsets[Index]).getTypePtr()); |
| 1948 | TypeAlreadyLoaded[Index] = true; |
| 1949 | } |
| 1950 | |
| 1951 | return QualType(reinterpret_cast<Type *>(TypeOffsets[Index]), Quals); |
| 1952 | } |
| 1953 | |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1954 | Decl *PCHReader::GetDecl(pch::DeclID ID) { |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1955 | if (ID == 0) |
| 1956 | return 0; |
| 1957 | |
| 1958 | unsigned Index = ID - 1; |
| 1959 | if (DeclAlreadyLoaded[Index]) |
| 1960 | return reinterpret_cast<Decl *>(DeclOffsets[Index]); |
| 1961 | |
| 1962 | // Load the declaration from the PCH file. |
| 1963 | return ReadDeclRecord(DeclOffsets[Index], Index); |
| 1964 | } |
| 1965 | |
Douglas Gregor | 3b9a7c8 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 1966 | Stmt *PCHReader::GetStmt(uint64_t Offset) { |
| 1967 | // Keep track of where we are in the stream, then jump back there |
| 1968 | // after reading this declaration. |
| 1969 | SavedStreamPosition SavedPosition(Stream); |
| 1970 | |
| 1971 | Stream.JumpToBit(Offset); |
| 1972 | return ReadStmt(); |
| 1973 | } |
| 1974 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1975 | bool PCHReader::ReadDeclsLexicallyInContext(DeclContext *DC, |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1976 | llvm::SmallVectorImpl<pch::DeclID> &Decls) { |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1977 | assert(DC->hasExternalLexicalStorage() && |
| 1978 | "DeclContext has no lexical decls in storage"); |
| 1979 | uint64_t Offset = DeclContextOffsets[DC].first; |
| 1980 | assert(Offset && "DeclContext has no lexical decls in storage"); |
| 1981 | |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1982 | // Keep track of where we are in the stream, then jump back there |
| 1983 | // after reading this context. |
| 1984 | SavedStreamPosition SavedPosition(Stream); |
| 1985 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1986 | // Load the record containing all of the declarations lexically in |
| 1987 | // this context. |
| 1988 | Stream.JumpToBit(Offset); |
| 1989 | RecordData Record; |
| 1990 | unsigned Code = Stream.ReadCode(); |
| 1991 | unsigned RecCode = Stream.ReadRecord(Code, Record); |
Douglas Gregor | 3c8ff3e | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 1992 | (void)RecCode; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1993 | assert(RecCode == pch::DECL_CONTEXT_LEXICAL && "Expected lexical block"); |
| 1994 | |
| 1995 | // Load all of the declaration IDs |
| 1996 | Decls.clear(); |
| 1997 | Decls.insert(Decls.end(), Record.begin(), Record.end()); |
| 1998 | return false; |
| 1999 | } |
| 2000 | |
| 2001 | bool PCHReader::ReadDeclsVisibleInContext(DeclContext *DC, |
| 2002 | llvm::SmallVectorImpl<VisibleDeclaration> & Decls) { |
| 2003 | assert(DC->hasExternalVisibleStorage() && |
| 2004 | "DeclContext has no visible decls in storage"); |
| 2005 | uint64_t Offset = DeclContextOffsets[DC].second; |
| 2006 | assert(Offset && "DeclContext has no visible decls in storage"); |
| 2007 | |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2008 | // Keep track of where we are in the stream, then jump back there |
| 2009 | // after reading this context. |
| 2010 | SavedStreamPosition SavedPosition(Stream); |
| 2011 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2012 | // Load the record containing all of the declarations visible in |
| 2013 | // this context. |
| 2014 | Stream.JumpToBit(Offset); |
| 2015 | RecordData Record; |
| 2016 | unsigned Code = Stream.ReadCode(); |
| 2017 | unsigned RecCode = Stream.ReadRecord(Code, Record); |
Douglas Gregor | 3c8ff3e | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 2018 | (void)RecCode; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2019 | assert(RecCode == pch::DECL_CONTEXT_VISIBLE && "Expected visible block"); |
| 2020 | if (Record.size() == 0) |
| 2021 | return false; |
| 2022 | |
| 2023 | Decls.clear(); |
| 2024 | |
| 2025 | unsigned Idx = 0; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2026 | while (Idx < Record.size()) { |
| 2027 | Decls.push_back(VisibleDeclaration()); |
| 2028 | Decls.back().Name = ReadDeclarationName(Record, Idx); |
| 2029 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2030 | unsigned Size = Record[Idx++]; |
| 2031 | llvm::SmallVector<unsigned, 4> & LoadedDecls |
| 2032 | = Decls.back().Declarations; |
| 2033 | LoadedDecls.reserve(Size); |
| 2034 | for (unsigned I = 0; I < Size; ++I) |
| 2035 | LoadedDecls.push_back(Record[Idx++]); |
| 2036 | } |
| 2037 | |
| 2038 | return false; |
| 2039 | } |
| 2040 | |
Douglas Gregor | 631f6c6 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2041 | void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) { |
| 2042 | if (!Consumer) |
| 2043 | return; |
| 2044 | |
| 2045 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
| 2046 | Decl *D = GetDecl(ExternalDefinitions[I]); |
| 2047 | DeclGroupRef DG(D); |
| 2048 | Consumer->HandleTopLevelDecl(DG); |
| 2049 | } |
| 2050 | } |
| 2051 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2052 | void PCHReader::PrintStats() { |
| 2053 | std::fprintf(stderr, "*** PCH Statistics:\n"); |
| 2054 | |
| 2055 | unsigned NumTypesLoaded = std::count(TypeAlreadyLoaded.begin(), |
| 2056 | TypeAlreadyLoaded.end(), |
| 2057 | true); |
| 2058 | unsigned NumDeclsLoaded = std::count(DeclAlreadyLoaded.begin(), |
| 2059 | DeclAlreadyLoaded.end(), |
| 2060 | true); |
Douglas Gregor | 9cf4742 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 2061 | unsigned NumIdentifiersLoaded = 0; |
| 2062 | for (unsigned I = 0; I < IdentifierData.size(); ++I) { |
| 2063 | if ((IdentifierData[I] & 0x01) == 0) |
| 2064 | ++NumIdentifiersLoaded; |
| 2065 | } |
| 2066 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2067 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
| 2068 | NumTypesLoaded, (unsigned)TypeAlreadyLoaded.size(), |
Douglas Gregor | 9cf4742 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 2069 | ((float)NumTypesLoaded/TypeAlreadyLoaded.size() * 100)); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2070 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
| 2071 | NumDeclsLoaded, (unsigned)DeclAlreadyLoaded.size(), |
Douglas Gregor | 9cf4742 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 2072 | ((float)NumDeclsLoaded/DeclAlreadyLoaded.size() * 100)); |
| 2073 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
| 2074 | NumIdentifiersLoaded, (unsigned)IdentifierData.size(), |
| 2075 | ((float)NumIdentifiersLoaded/IdentifierData.size() * 100)); |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2076 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 2077 | NumStatementsRead, TotalNumStatements, |
| 2078 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2079 | std::fprintf(stderr, "\n"); |
| 2080 | } |
| 2081 | |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2082 | IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2083 | if (ID == 0) |
| 2084 | return 0; |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2085 | |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2086 | if (!IdentifierTable || IdentifierData.empty()) { |
| 2087 | Error("No identifier table in PCH file"); |
| 2088 | return 0; |
| 2089 | } |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2090 | |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2091 | if (IdentifierData[ID - 1] & 0x01) { |
| 2092 | uint64_t Offset = IdentifierData[ID - 1]; |
| 2093 | IdentifierData[ID - 1] = reinterpret_cast<uint64_t>( |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2094 | &Context.Idents.get(IdentifierTable + Offset)); |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2095 | } |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2096 | |
| 2097 | return reinterpret_cast<IdentifierInfo *>(IdentifierData[ID - 1]); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | DeclarationName |
| 2101 | PCHReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
| 2102 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 2103 | switch (Kind) { |
| 2104 | case DeclarationName::Identifier: |
| 2105 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 2106 | |
| 2107 | case DeclarationName::ObjCZeroArgSelector: |
| 2108 | case DeclarationName::ObjCOneArgSelector: |
| 2109 | case DeclarationName::ObjCMultiArgSelector: |
| 2110 | assert(false && "Unable to de-serialize Objective-C selectors"); |
| 2111 | break; |
| 2112 | |
| 2113 | case DeclarationName::CXXConstructorName: |
| 2114 | return Context.DeclarationNames.getCXXConstructorName( |
| 2115 | GetType(Record[Idx++])); |
| 2116 | |
| 2117 | case DeclarationName::CXXDestructorName: |
| 2118 | return Context.DeclarationNames.getCXXDestructorName( |
| 2119 | GetType(Record[Idx++])); |
| 2120 | |
| 2121 | case DeclarationName::CXXConversionFunctionName: |
| 2122 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 2123 | GetType(Record[Idx++])); |
| 2124 | |
| 2125 | case DeclarationName::CXXOperatorName: |
| 2126 | return Context.DeclarationNames.getCXXOperatorName( |
| 2127 | (OverloadedOperatorKind)Record[Idx++]); |
| 2128 | |
| 2129 | case DeclarationName::CXXUsingDirective: |
| 2130 | return DeclarationName::getUsingDirectiveName(); |
| 2131 | } |
| 2132 | |
| 2133 | // Required to silence GCC warning |
| 2134 | return DeclarationName(); |
| 2135 | } |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2136 | |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2137 | /// \brief Read an integral value |
| 2138 | llvm::APInt PCHReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 2139 | unsigned BitWidth = Record[Idx++]; |
| 2140 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 2141 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 2142 | Idx += NumWords; |
| 2143 | return Result; |
| 2144 | } |
| 2145 | |
| 2146 | /// \brief Read a signed integral value |
| 2147 | llvm::APSInt PCHReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 2148 | bool isUnsigned = Record[Idx++]; |
| 2149 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 2150 | } |
| 2151 | |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2152 | /// \brief Read a floating-point value |
| 2153 | llvm::APFloat PCHReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2154 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 2155 | } |
| 2156 | |
Douglas Gregor | 1c50788 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2157 | // \brief Read a string |
| 2158 | std::string PCHReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 2159 | unsigned Len = Record[Idx++]; |
| 2160 | std::string Result(&Record[Idx], &Record[Idx] + Len); |
| 2161 | Idx += Len; |
| 2162 | return Result; |
| 2163 | } |
| 2164 | |
| 2165 | /// \brief Reads attributes from the current stream position. |
| 2166 | Attr *PCHReader::ReadAttributes() { |
| 2167 | unsigned Code = Stream.ReadCode(); |
| 2168 | assert(Code == llvm::bitc::UNABBREV_RECORD && |
| 2169 | "Expected unabbreviated record"); (void)Code; |
| 2170 | |
| 2171 | RecordData Record; |
| 2172 | unsigned Idx = 0; |
| 2173 | unsigned RecCode = Stream.ReadRecord(Code, Record); |
| 2174 | assert(RecCode == pch::DECL_ATTR && "Expected attribute record"); |
| 2175 | (void)RecCode; |
| 2176 | |
| 2177 | #define SIMPLE_ATTR(Name) \ |
| 2178 | case Attr::Name: \ |
| 2179 | New = ::new (Context) Name##Attr(); \ |
| 2180 | break |
| 2181 | |
| 2182 | #define STRING_ATTR(Name) \ |
| 2183 | case Attr::Name: \ |
| 2184 | New = ::new (Context) Name##Attr(ReadString(Record, Idx)); \ |
| 2185 | break |
| 2186 | |
| 2187 | #define UNSIGNED_ATTR(Name) \ |
| 2188 | case Attr::Name: \ |
| 2189 | New = ::new (Context) Name##Attr(Record[Idx++]); \ |
| 2190 | break |
| 2191 | |
| 2192 | Attr *Attrs = 0; |
| 2193 | while (Idx < Record.size()) { |
| 2194 | Attr *New = 0; |
| 2195 | Attr::Kind Kind = (Attr::Kind)Record[Idx++]; |
| 2196 | bool IsInherited = Record[Idx++]; |
| 2197 | |
| 2198 | switch (Kind) { |
| 2199 | STRING_ATTR(Alias); |
| 2200 | UNSIGNED_ATTR(Aligned); |
| 2201 | SIMPLE_ATTR(AlwaysInline); |
| 2202 | SIMPLE_ATTR(AnalyzerNoReturn); |
| 2203 | STRING_ATTR(Annotate); |
| 2204 | STRING_ATTR(AsmLabel); |
| 2205 | |
| 2206 | case Attr::Blocks: |
| 2207 | New = ::new (Context) BlocksAttr( |
| 2208 | (BlocksAttr::BlocksAttrTypes)Record[Idx++]); |
| 2209 | break; |
| 2210 | |
| 2211 | case Attr::Cleanup: |
| 2212 | New = ::new (Context) CleanupAttr( |
| 2213 | cast<FunctionDecl>(GetDecl(Record[Idx++]))); |
| 2214 | break; |
| 2215 | |
| 2216 | SIMPLE_ATTR(Const); |
| 2217 | UNSIGNED_ATTR(Constructor); |
| 2218 | SIMPLE_ATTR(DLLExport); |
| 2219 | SIMPLE_ATTR(DLLImport); |
| 2220 | SIMPLE_ATTR(Deprecated); |
| 2221 | UNSIGNED_ATTR(Destructor); |
| 2222 | SIMPLE_ATTR(FastCall); |
| 2223 | |
| 2224 | case Attr::Format: { |
| 2225 | std::string Type = ReadString(Record, Idx); |
| 2226 | unsigned FormatIdx = Record[Idx++]; |
| 2227 | unsigned FirstArg = Record[Idx++]; |
| 2228 | New = ::new (Context) FormatAttr(Type, FormatIdx, FirstArg); |
| 2229 | break; |
| 2230 | } |
| 2231 | |
Chris Lattner | 15ce6cc | 2009-04-20 19:12:28 +0000 | [diff] [blame] | 2232 | SIMPLE_ATTR(GNUInline); |
Douglas Gregor | 1c50788 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2233 | |
| 2234 | case Attr::IBOutletKind: |
| 2235 | New = ::new (Context) IBOutletAttr(); |
| 2236 | break; |
| 2237 | |
| 2238 | SIMPLE_ATTR(NoReturn); |
| 2239 | SIMPLE_ATTR(NoThrow); |
| 2240 | SIMPLE_ATTR(Nodebug); |
| 2241 | SIMPLE_ATTR(Noinline); |
| 2242 | |
| 2243 | case Attr::NonNull: { |
| 2244 | unsigned Size = Record[Idx++]; |
| 2245 | llvm::SmallVector<unsigned, 16> ArgNums; |
| 2246 | ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size); |
| 2247 | Idx += Size; |
| 2248 | New = ::new (Context) NonNullAttr(&ArgNums[0], Size); |
| 2249 | break; |
| 2250 | } |
| 2251 | |
| 2252 | SIMPLE_ATTR(ObjCException); |
| 2253 | SIMPLE_ATTR(ObjCNSObject); |
| 2254 | SIMPLE_ATTR(Overloadable); |
| 2255 | UNSIGNED_ATTR(Packed); |
| 2256 | SIMPLE_ATTR(Pure); |
| 2257 | UNSIGNED_ATTR(Regparm); |
| 2258 | STRING_ATTR(Section); |
| 2259 | SIMPLE_ATTR(StdCall); |
| 2260 | SIMPLE_ATTR(TransparentUnion); |
| 2261 | SIMPLE_ATTR(Unavailable); |
| 2262 | SIMPLE_ATTR(Unused); |
| 2263 | SIMPLE_ATTR(Used); |
| 2264 | |
| 2265 | case Attr::Visibility: |
| 2266 | New = ::new (Context) VisibilityAttr( |
| 2267 | (VisibilityAttr::VisibilityTypes)Record[Idx++]); |
| 2268 | break; |
| 2269 | |
| 2270 | SIMPLE_ATTR(WarnUnusedResult); |
| 2271 | SIMPLE_ATTR(Weak); |
| 2272 | SIMPLE_ATTR(WeakImport); |
| 2273 | } |
| 2274 | |
| 2275 | assert(New && "Unable to decode attribute?"); |
| 2276 | New->setInherited(IsInherited); |
| 2277 | New->setNext(Attrs); |
| 2278 | Attrs = New; |
| 2279 | } |
| 2280 | #undef UNSIGNED_ATTR |
| 2281 | #undef STRING_ATTR |
| 2282 | #undef SIMPLE_ATTR |
| 2283 | |
| 2284 | // The list of attributes was built backwards. Reverse the list |
| 2285 | // before returning it. |
| 2286 | Attr *PrevAttr = 0, *NextAttr = 0; |
| 2287 | while (Attrs) { |
| 2288 | NextAttr = Attrs->getNext(); |
| 2289 | Attrs->setNext(PrevAttr); |
| 2290 | PrevAttr = Attrs; |
| 2291 | Attrs = NextAttr; |
| 2292 | } |
| 2293 | |
| 2294 | return PrevAttr; |
| 2295 | } |
| 2296 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2297 | Stmt *PCHReader::ReadStmt() { |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2298 | // Within the bitstream, expressions are stored in Reverse Polish |
| 2299 | // Notation, with each of the subexpressions preceding the |
| 2300 | // expression they are stored in. To evaluate expressions, we |
| 2301 | // continue reading expressions and placing them on the stack, with |
| 2302 | // expressions having operands removing those operands from the |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2303 | // stack. Evaluation terminates when we see a STMT_STOP record, and |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2304 | // the single remaining expression on the stack is our result. |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2305 | RecordData Record; |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2306 | unsigned Idx; |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2307 | llvm::SmallVector<Stmt *, 16> StmtStack; |
| 2308 | PCHStmtReader Reader(*this, Record, Idx, StmtStack); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2309 | Stmt::EmptyShell Empty; |
| 2310 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2311 | while (true) { |
| 2312 | unsigned Code = Stream.ReadCode(); |
| 2313 | if (Code == llvm::bitc::END_BLOCK) { |
| 2314 | if (Stream.ReadBlockEnd()) { |
| 2315 | Error("Error at end of Source Manager block"); |
| 2316 | return 0; |
| 2317 | } |
| 2318 | break; |
| 2319 | } |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2320 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2321 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2322 | // No known subblocks, always skip them. |
| 2323 | Stream.ReadSubBlockID(); |
| 2324 | if (Stream.SkipBlock()) { |
| 2325 | Error("Malformed block record"); |
| 2326 | return 0; |
| 2327 | } |
| 2328 | continue; |
| 2329 | } |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2330 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2331 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2332 | Stream.ReadAbbrevRecord(); |
| 2333 | continue; |
| 2334 | } |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2335 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2336 | Stmt *S = 0; |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2337 | Idx = 0; |
| 2338 | Record.clear(); |
| 2339 | bool Finished = false; |
| 2340 | switch ((pch::StmtCode)Stream.ReadRecord(Code, Record)) { |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2341 | case pch::STMT_STOP: |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2342 | Finished = true; |
| 2343 | break; |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2344 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2345 | case pch::STMT_NULL_PTR: |
| 2346 | S = 0; |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2347 | break; |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2348 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 2349 | case pch::STMT_NULL: |
| 2350 | S = new (Context) NullStmt(Empty); |
| 2351 | break; |
| 2352 | |
| 2353 | case pch::STMT_COMPOUND: |
| 2354 | S = new (Context) CompoundStmt(Empty); |
| 2355 | break; |
| 2356 | |
| 2357 | case pch::STMT_CASE: |
| 2358 | S = new (Context) CaseStmt(Empty); |
| 2359 | break; |
| 2360 | |
| 2361 | case pch::STMT_DEFAULT: |
| 2362 | S = new (Context) DefaultStmt(Empty); |
| 2363 | break; |
| 2364 | |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2365 | case pch::STMT_LABEL: |
| 2366 | S = new (Context) LabelStmt(Empty); |
| 2367 | break; |
| 2368 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 2369 | case pch::STMT_IF: |
| 2370 | S = new (Context) IfStmt(Empty); |
| 2371 | break; |
| 2372 | |
| 2373 | case pch::STMT_SWITCH: |
| 2374 | S = new (Context) SwitchStmt(Empty); |
| 2375 | break; |
| 2376 | |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 2377 | case pch::STMT_WHILE: |
| 2378 | S = new (Context) WhileStmt(Empty); |
| 2379 | break; |
| 2380 | |
Douglas Gregor | fb5f25b | 2009-04-17 00:29:51 +0000 | [diff] [blame] | 2381 | case pch::STMT_DO: |
| 2382 | S = new (Context) DoStmt(Empty); |
| 2383 | break; |
| 2384 | |
| 2385 | case pch::STMT_FOR: |
| 2386 | S = new (Context) ForStmt(Empty); |
| 2387 | break; |
| 2388 | |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2389 | case pch::STMT_GOTO: |
| 2390 | S = new (Context) GotoStmt(Empty); |
| 2391 | break; |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 2392 | |
| 2393 | case pch::STMT_INDIRECT_GOTO: |
| 2394 | S = new (Context) IndirectGotoStmt(Empty); |
| 2395 | break; |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2396 | |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 2397 | case pch::STMT_CONTINUE: |
| 2398 | S = new (Context) ContinueStmt(Empty); |
| 2399 | break; |
| 2400 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 2401 | case pch::STMT_BREAK: |
| 2402 | S = new (Context) BreakStmt(Empty); |
| 2403 | break; |
| 2404 | |
Douglas Gregor | 22d2dcd | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 2405 | case pch::STMT_RETURN: |
| 2406 | S = new (Context) ReturnStmt(Empty); |
| 2407 | break; |
| 2408 | |
Douglas Gregor | 78ff29f | 2009-04-17 16:55:36 +0000 | [diff] [blame] | 2409 | case pch::STMT_DECL: |
| 2410 | S = new (Context) DeclStmt(Empty); |
| 2411 | break; |
| 2412 | |
Douglas Gregor | 3e1f9fb | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 2413 | case pch::STMT_ASM: |
| 2414 | S = new (Context) AsmStmt(Empty); |
| 2415 | break; |
| 2416 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2417 | case pch::EXPR_PREDEFINED: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2418 | S = new (Context) PredefinedExpr(Empty); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2419 | break; |
| 2420 | |
| 2421 | case pch::EXPR_DECL_REF: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2422 | S = new (Context) DeclRefExpr(Empty); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2423 | break; |
| 2424 | |
| 2425 | case pch::EXPR_INTEGER_LITERAL: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2426 | S = new (Context) IntegerLiteral(Empty); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2427 | break; |
| 2428 | |
| 2429 | case pch::EXPR_FLOATING_LITERAL: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2430 | S = new (Context) FloatingLiteral(Empty); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2431 | break; |
| 2432 | |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 2433 | case pch::EXPR_IMAGINARY_LITERAL: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2434 | S = new (Context) ImaginaryLiteral(Empty); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 2435 | break; |
| 2436 | |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 2437 | case pch::EXPR_STRING_LITERAL: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2438 | S = StringLiteral::CreateEmpty(Context, |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 2439 | Record[PCHStmtReader::NumExprFields + 1]); |
| 2440 | break; |
| 2441 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2442 | case pch::EXPR_CHARACTER_LITERAL: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2443 | S = new (Context) CharacterLiteral(Empty); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2444 | break; |
| 2445 | |
Douglas Gregor | 4ea0b1f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 2446 | case pch::EXPR_PAREN: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2447 | S = new (Context) ParenExpr(Empty); |
Douglas Gregor | 4ea0b1f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 2448 | break; |
| 2449 | |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 2450 | case pch::EXPR_UNARY_OPERATOR: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2451 | S = new (Context) UnaryOperator(Empty); |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 2452 | break; |
| 2453 | |
| 2454 | case pch::EXPR_SIZEOF_ALIGN_OF: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2455 | S = new (Context) SizeOfAlignOfExpr(Empty); |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 2456 | break; |
| 2457 | |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 2458 | case pch::EXPR_ARRAY_SUBSCRIPT: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2459 | S = new (Context) ArraySubscriptExpr(Empty); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 2460 | break; |
| 2461 | |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 2462 | case pch::EXPR_CALL: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2463 | S = new (Context) CallExpr(Context, Empty); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 2464 | break; |
| 2465 | |
| 2466 | case pch::EXPR_MEMBER: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2467 | S = new (Context) MemberExpr(Empty); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 2468 | break; |
| 2469 | |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 2470 | case pch::EXPR_BINARY_OPERATOR: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2471 | S = new (Context) BinaryOperator(Empty); |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 2474 | case pch::EXPR_COMPOUND_ASSIGN_OPERATOR: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2475 | S = new (Context) CompoundAssignOperator(Empty); |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 2476 | break; |
| 2477 | |
| 2478 | case pch::EXPR_CONDITIONAL_OPERATOR: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2479 | S = new (Context) ConditionalOperator(Empty); |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 2480 | break; |
| 2481 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2482 | case pch::EXPR_IMPLICIT_CAST: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2483 | S = new (Context) ImplicitCastExpr(Empty); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2484 | break; |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 2485 | |
| 2486 | case pch::EXPR_CSTYLE_CAST: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2487 | S = new (Context) CStyleCastExpr(Empty); |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 2488 | break; |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 2489 | |
Douglas Gregor | b70b48f | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 2490 | case pch::EXPR_COMPOUND_LITERAL: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2491 | S = new (Context) CompoundLiteralExpr(Empty); |
Douglas Gregor | b70b48f | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 2492 | break; |
| 2493 | |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 2494 | case pch::EXPR_EXT_VECTOR_ELEMENT: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2495 | S = new (Context) ExtVectorElementExpr(Empty); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 2496 | break; |
| 2497 | |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2498 | case pch::EXPR_INIT_LIST: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2499 | S = new (Context) InitListExpr(Empty); |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2500 | break; |
| 2501 | |
| 2502 | case pch::EXPR_DESIGNATED_INIT: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2503 | S = DesignatedInitExpr::CreateEmpty(Context, |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2504 | Record[PCHStmtReader::NumExprFields] - 1); |
| 2505 | |
| 2506 | break; |
| 2507 | |
| 2508 | case pch::EXPR_IMPLICIT_VALUE_INIT: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2509 | S = new (Context) ImplicitValueInitExpr(Empty); |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 2510 | break; |
| 2511 | |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 2512 | case pch::EXPR_VA_ARG: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2513 | S = new (Context) VAArgExpr(Empty); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 2514 | break; |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 2515 | |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 2516 | case pch::EXPR_ADDR_LABEL: |
| 2517 | S = new (Context) AddrLabelExpr(Empty); |
| 2518 | break; |
| 2519 | |
Douglas Gregor | eca12f6 | 2009-04-17 19:05:30 +0000 | [diff] [blame] | 2520 | case pch::EXPR_STMT: |
| 2521 | S = new (Context) StmtExpr(Empty); |
| 2522 | break; |
| 2523 | |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 2524 | case pch::EXPR_TYPES_COMPATIBLE: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2525 | S = new (Context) TypesCompatibleExpr(Empty); |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 2526 | break; |
| 2527 | |
| 2528 | case pch::EXPR_CHOOSE: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2529 | S = new (Context) ChooseExpr(Empty); |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 2530 | break; |
| 2531 | |
| 2532 | case pch::EXPR_GNU_NULL: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2533 | S = new (Context) GNUNullExpr(Empty); |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 2534 | break; |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 2535 | |
| 2536 | case pch::EXPR_SHUFFLE_VECTOR: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2537 | S = new (Context) ShuffleVectorExpr(Empty); |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | |
Douglas Gregor | e246b74 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 2540 | case pch::EXPR_BLOCK: |
| 2541 | S = new (Context) BlockExpr(Empty); |
| 2542 | break; |
| 2543 | |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 2544 | case pch::EXPR_BLOCK_DECL_REF: |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2545 | S = new (Context) BlockDeclRefExpr(Empty); |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 2546 | break; |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2549 | // We hit a STMT_STOP, so we're done with this expression. |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2550 | if (Finished) |
| 2551 | break; |
| 2552 | |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2553 | ++NumStatementsRead; |
| 2554 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2555 | if (S) { |
| 2556 | unsigned NumSubStmts = Reader.Visit(S); |
| 2557 | while (NumSubStmts > 0) { |
| 2558 | StmtStack.pop_back(); |
| 2559 | --NumSubStmts; |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2563 | assert(Idx == Record.size() && "Invalid deserialization of statement"); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2564 | StmtStack.push_back(S); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2565 | } |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2566 | assert(StmtStack.size() == 1 && "Extra expressions on stack!"); |
Douglas Gregor | 22d2dcd | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 2567 | SwitchCaseStmts.clear(); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2568 | return StmtStack.back(); |
| 2569 | } |
| 2570 | |
| 2571 | Expr *PCHReader::ReadExpr() { |
| 2572 | return dyn_cast_or_null<Expr>(ReadStmt()); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2573 | } |
| 2574 | |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2575 | DiagnosticBuilder PCHReader::Diag(unsigned DiagID) { |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2576 | return Diag(SourceLocation(), DiagID); |
| 2577 | } |
| 2578 | |
| 2579 | DiagnosticBuilder PCHReader::Diag(SourceLocation Loc, unsigned DiagID) { |
| 2580 | return PP.getDiagnostics().Report(FullSourceLoc(Loc, |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2581 | Context.getSourceManager()), |
| 2582 | DiagID); |
| 2583 | } |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 2584 | |
| 2585 | /// \brief Record that the given ID maps to the given switch-case |
| 2586 | /// statement. |
| 2587 | void PCHReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
| 2588 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 2589 | SwitchCaseStmts[ID] = SC; |
| 2590 | } |
| 2591 | |
| 2592 | /// \brief Retrieve the switch-case statement with the given ID. |
| 2593 | SwitchCase *PCHReader::getSwitchCaseWithID(unsigned ID) { |
| 2594 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 2595 | return SwitchCaseStmts[ID]; |
| 2596 | } |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2597 | |
| 2598 | /// \brief Record that the given label statement has been |
| 2599 | /// deserialized and has the given ID. |
| 2600 | void PCHReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
| 2601 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
| 2602 | "Deserialized label twice"); |
| 2603 | LabelStmts[ID] = S; |
| 2604 | |
| 2605 | // If we've already seen any goto statements that point to this |
| 2606 | // label, resolve them now. |
| 2607 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 2608 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 2609 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 2610 | Goto->second->setLabel(S); |
| 2611 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 2612 | |
| 2613 | // If we've already seen any address-label statements that point to |
| 2614 | // this label, resolve them now. |
| 2615 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
| 2616 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
| 2617 | = UnresolvedAddrLabelExprs.equal_range(ID); |
| 2618 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
| 2619 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 2620 | AddrLabel->second->setLabel(S); |
| 2621 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /// \brief Set the label of the given statement to the label |
| 2625 | /// identified by ID. |
| 2626 | /// |
| 2627 | /// Depending on the order in which the label and other statements |
| 2628 | /// referencing that label occur, this operation may complete |
| 2629 | /// immediately (updating the statement) or it may queue the |
| 2630 | /// statement to be back-patched later. |
| 2631 | void PCHReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
| 2632 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 2633 | if (Label != LabelStmts.end()) { |
| 2634 | // We've already seen this label, so set the label of the goto and |
| 2635 | // we're done. |
| 2636 | S->setLabel(Label->second); |
| 2637 | } else { |
| 2638 | // We haven't seen this label yet, so add this goto to the set of |
| 2639 | // unresolved goto statements. |
| 2640 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 2641 | } |
| 2642 | } |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 2643 | |
| 2644 | /// \brief Set the label of the given expression to the label |
| 2645 | /// identified by ID. |
| 2646 | /// |
| 2647 | /// Depending on the order in which the label and other statements |
| 2648 | /// referencing that label occur, this operation may complete |
| 2649 | /// immediately (updating the statement) or it may queue the |
| 2650 | /// statement to be back-patched later. |
| 2651 | void PCHReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
| 2652 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 2653 | if (Label != LabelStmts.end()) { |
| 2654 | // We've already seen this label, so set the label of the |
| 2655 | // label-address expression and we're done. |
| 2656 | S->setLabel(Label->second); |
| 2657 | } else { |
| 2658 | // We haven't seen this label yet, so add this label-address |
| 2659 | // expression to the set of unresolved label-address expressions. |
| 2660 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 2661 | } |
| 2662 | } |