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