Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1 | //===--- PCHWriter.h - Precompiled Headers Writer ---------------*- 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 PCHWriter class, which writes a precompiled header. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Frontend/PCHWriter.h" |
Douglas Gregor | 87887da | 2009-04-20 15:53:59 +0000 | [diff] [blame] | 15 | #include "../Sema/Sema.h" // FIXME: move header into include/clang/Sema |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 16 | #include "../Sema/IdentifierResolver.h" // FIXME: move header |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/AST/Decl.h" |
| 19 | #include "clang/AST/DeclContextInternals.h" |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
| 21 | #include "clang/AST/StmtVisitor.h" |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/Type.h" |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 23 | #include "clang/Lex/MacroInfo.h" |
| 24 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | cda68f2 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 25 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 26 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 27 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 28 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 29 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 30 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/APFloat.h" |
| 32 | #include "llvm/ADT/APInt.h" |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 33 | #include "llvm/Bitcode/BitstreamWriter.h" |
| 34 | #include "llvm/Support/Compiler.h" |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "llvm/Support/MemoryBuffer.h" |
Chris Lattner | 64b65f8 | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 36 | #include <cstdio> |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 37 | using namespace clang; |
| 38 | |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | // Type serialization |
| 41 | //===----------------------------------------------------------------------===// |
Chris Lattner | d83ede5 | 2009-04-27 06:16:06 +0000 | [diff] [blame^] | 42 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | namespace { |
| 44 | class VISIBILITY_HIDDEN PCHTypeWriter { |
| 45 | PCHWriter &Writer; |
| 46 | PCHWriter::RecordData &Record; |
| 47 | |
| 48 | public: |
| 49 | /// \brief Type code that corresponds to the record generated. |
| 50 | pch::TypeCode Code; |
| 51 | |
| 52 | PCHTypeWriter(PCHWriter &Writer, PCHWriter::RecordData &Record) |
| 53 | : Writer(Writer), Record(Record) { } |
| 54 | |
| 55 | void VisitArrayType(const ArrayType *T); |
| 56 | void VisitFunctionType(const FunctionType *T); |
| 57 | void VisitTagType(const TagType *T); |
| 58 | |
| 59 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 60 | #define ABSTRACT_TYPE(Class, Base) |
| 61 | #define DEPENDENT_TYPE(Class, Base) |
| 62 | #include "clang/AST/TypeNodes.def" |
| 63 | }; |
| 64 | } |
| 65 | |
| 66 | void PCHTypeWriter::VisitExtQualType(const ExtQualType *T) { |
| 67 | Writer.AddTypeRef(QualType(T->getBaseType(), 0), Record); |
| 68 | Record.push_back(T->getObjCGCAttr()); // FIXME: use stable values |
| 69 | Record.push_back(T->getAddressSpace()); |
| 70 | Code = pch::TYPE_EXT_QUAL; |
| 71 | } |
| 72 | |
| 73 | void PCHTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
| 74 | assert(false && "Built-in types are never serialized"); |
| 75 | } |
| 76 | |
| 77 | void PCHTypeWriter::VisitFixedWidthIntType(const FixedWidthIntType *T) { |
| 78 | Record.push_back(T->getWidth()); |
| 79 | Record.push_back(T->isSigned()); |
| 80 | Code = pch::TYPE_FIXED_WIDTH_INT; |
| 81 | } |
| 82 | |
| 83 | void PCHTypeWriter::VisitComplexType(const ComplexType *T) { |
| 84 | Writer.AddTypeRef(T->getElementType(), Record); |
| 85 | Code = pch::TYPE_COMPLEX; |
| 86 | } |
| 87 | |
| 88 | void PCHTypeWriter::VisitPointerType(const PointerType *T) { |
| 89 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 90 | Code = pch::TYPE_POINTER; |
| 91 | } |
| 92 | |
| 93 | void PCHTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
| 94 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 95 | Code = pch::TYPE_BLOCK_POINTER; |
| 96 | } |
| 97 | |
| 98 | void PCHTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
| 99 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 100 | Code = pch::TYPE_LVALUE_REFERENCE; |
| 101 | } |
| 102 | |
| 103 | void PCHTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
| 104 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 105 | Code = pch::TYPE_RVALUE_REFERENCE; |
| 106 | } |
| 107 | |
| 108 | void PCHTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
| 109 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 110 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
| 111 | Code = pch::TYPE_MEMBER_POINTER; |
| 112 | } |
| 113 | |
| 114 | void PCHTypeWriter::VisitArrayType(const ArrayType *T) { |
| 115 | Writer.AddTypeRef(T->getElementType(), Record); |
| 116 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
| 117 | Record.push_back(T->getIndexTypeQualifier()); // FIXME: stable values |
| 118 | } |
| 119 | |
| 120 | void PCHTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 121 | VisitArrayType(T); |
| 122 | Writer.AddAPInt(T->getSize(), Record); |
| 123 | Code = pch::TYPE_CONSTANT_ARRAY; |
| 124 | } |
| 125 | |
| 126 | void PCHTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
| 127 | VisitArrayType(T); |
| 128 | Code = pch::TYPE_INCOMPLETE_ARRAY; |
| 129 | } |
| 130 | |
| 131 | void PCHTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
| 132 | VisitArrayType(T); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 133 | Writer.AddStmt(T->getSizeExpr()); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 134 | Code = pch::TYPE_VARIABLE_ARRAY; |
| 135 | } |
| 136 | |
| 137 | void PCHTypeWriter::VisitVectorType(const VectorType *T) { |
| 138 | Writer.AddTypeRef(T->getElementType(), Record); |
| 139 | Record.push_back(T->getNumElements()); |
| 140 | Code = pch::TYPE_VECTOR; |
| 141 | } |
| 142 | |
| 143 | void PCHTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
| 144 | VisitVectorType(T); |
| 145 | Code = pch::TYPE_EXT_VECTOR; |
| 146 | } |
| 147 | |
| 148 | void PCHTypeWriter::VisitFunctionType(const FunctionType *T) { |
| 149 | Writer.AddTypeRef(T->getResultType(), Record); |
| 150 | } |
| 151 | |
| 152 | void PCHTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
| 153 | VisitFunctionType(T); |
| 154 | Code = pch::TYPE_FUNCTION_NO_PROTO; |
| 155 | } |
| 156 | |
| 157 | void PCHTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 158 | VisitFunctionType(T); |
| 159 | Record.push_back(T->getNumArgs()); |
| 160 | for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) |
| 161 | Writer.AddTypeRef(T->getArgType(I), Record); |
| 162 | Record.push_back(T->isVariadic()); |
| 163 | Record.push_back(T->getTypeQuals()); |
| 164 | Code = pch::TYPE_FUNCTION_PROTO; |
| 165 | } |
| 166 | |
| 167 | void PCHTypeWriter::VisitTypedefType(const TypedefType *T) { |
| 168 | Writer.AddDeclRef(T->getDecl(), Record); |
| 169 | Code = pch::TYPE_TYPEDEF; |
| 170 | } |
| 171 | |
| 172 | void PCHTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 173 | Writer.AddStmt(T->getUnderlyingExpr()); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 174 | Code = pch::TYPE_TYPEOF_EXPR; |
| 175 | } |
| 176 | |
| 177 | void PCHTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
| 178 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 179 | Code = pch::TYPE_TYPEOF; |
| 180 | } |
| 181 | |
| 182 | void PCHTypeWriter::VisitTagType(const TagType *T) { |
| 183 | Writer.AddDeclRef(T->getDecl(), Record); |
| 184 | assert(!T->isBeingDefined() && |
| 185 | "Cannot serialize in the middle of a type definition"); |
| 186 | } |
| 187 | |
| 188 | void PCHTypeWriter::VisitRecordType(const RecordType *T) { |
| 189 | VisitTagType(T); |
| 190 | Code = pch::TYPE_RECORD; |
| 191 | } |
| 192 | |
| 193 | void PCHTypeWriter::VisitEnumType(const EnumType *T) { |
| 194 | VisitTagType(T); |
| 195 | Code = pch::TYPE_ENUM; |
| 196 | } |
| 197 | |
| 198 | void |
| 199 | PCHTypeWriter::VisitTemplateSpecializationType( |
| 200 | const TemplateSpecializationType *T) { |
Douglas Gregor | 3c8ff3e | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 201 | // FIXME: Serialize this type (C++ only) |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 202 | assert(false && "Cannot serialize template specialization types"); |
| 203 | } |
| 204 | |
| 205 | void PCHTypeWriter::VisitQualifiedNameType(const QualifiedNameType *T) { |
Douglas Gregor | 3c8ff3e | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 206 | // FIXME: Serialize this type (C++ only) |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 207 | assert(false && "Cannot serialize qualified name types"); |
| 208 | } |
| 209 | |
| 210 | void PCHTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 211 | Writer.AddDeclRef(T->getDecl(), Record); |
| 212 | Code = pch::TYPE_OBJC_INTERFACE; |
| 213 | } |
| 214 | |
| 215 | void |
| 216 | PCHTypeWriter::VisitObjCQualifiedInterfaceType( |
| 217 | const ObjCQualifiedInterfaceType *T) { |
| 218 | VisitObjCInterfaceType(T); |
| 219 | Record.push_back(T->getNumProtocols()); |
| 220 | for (unsigned I = 0, N = T->getNumProtocols(); I != N; ++I) |
| 221 | Writer.AddDeclRef(T->getProtocol(I), Record); |
| 222 | Code = pch::TYPE_OBJC_QUALIFIED_INTERFACE; |
| 223 | } |
| 224 | |
| 225 | void PCHTypeWriter::VisitObjCQualifiedIdType(const ObjCQualifiedIdType *T) { |
| 226 | Record.push_back(T->getNumProtocols()); |
| 227 | for (unsigned I = 0, N = T->getNumProtocols(); I != N; ++I) |
| 228 | Writer.AddDeclRef(T->getProtocols(I), Record); |
| 229 | Code = pch::TYPE_OBJC_QUALIFIED_ID; |
| 230 | } |
| 231 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 232 | |
| 233 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 234 | // Statement/expression serialization |
| 235 | //===----------------------------------------------------------------------===// |
| 236 | namespace { |
| 237 | class VISIBILITY_HIDDEN PCHStmtWriter |
| 238 | : public StmtVisitor<PCHStmtWriter, void> { |
| 239 | |
| 240 | PCHWriter &Writer; |
| 241 | PCHWriter::RecordData &Record; |
| 242 | |
| 243 | public: |
| 244 | pch::StmtCode Code; |
| 245 | |
| 246 | PCHStmtWriter(PCHWriter &Writer, PCHWriter::RecordData &Record) |
| 247 | : Writer(Writer), Record(Record) { } |
| 248 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 249 | void VisitStmt(Stmt *S); |
| 250 | void VisitNullStmt(NullStmt *S); |
| 251 | void VisitCompoundStmt(CompoundStmt *S); |
| 252 | void VisitSwitchCase(SwitchCase *S); |
| 253 | void VisitCaseStmt(CaseStmt *S); |
| 254 | void VisitDefaultStmt(DefaultStmt *S); |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 255 | void VisitLabelStmt(LabelStmt *S); |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 256 | void VisitIfStmt(IfStmt *S); |
| 257 | void VisitSwitchStmt(SwitchStmt *S); |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 258 | void VisitWhileStmt(WhileStmt *S); |
Douglas Gregor | fb5f25b | 2009-04-17 00:29:51 +0000 | [diff] [blame] | 259 | void VisitDoStmt(DoStmt *S); |
| 260 | void VisitForStmt(ForStmt *S); |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 261 | void VisitGotoStmt(GotoStmt *S); |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 262 | void VisitIndirectGotoStmt(IndirectGotoStmt *S); |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 263 | void VisitContinueStmt(ContinueStmt *S); |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 264 | void VisitBreakStmt(BreakStmt *S); |
Douglas Gregor | 22d2dcd | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 265 | void VisitReturnStmt(ReturnStmt *S); |
Douglas Gregor | 78ff29f | 2009-04-17 16:55:36 +0000 | [diff] [blame] | 266 | void VisitDeclStmt(DeclStmt *S); |
Douglas Gregor | 3e1f9fb | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 267 | void VisitAsmStmt(AsmStmt *S); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 268 | void VisitExpr(Expr *E); |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 269 | void VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 270 | void VisitDeclRefExpr(DeclRefExpr *E); |
| 271 | void VisitIntegerLiteral(IntegerLiteral *E); |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 272 | void VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 273 | void VisitImaginaryLiteral(ImaginaryLiteral *E); |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 274 | void VisitStringLiteral(StringLiteral *E); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 275 | void VisitCharacterLiteral(CharacterLiteral *E); |
Douglas Gregor | 4ea0b1f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 276 | void VisitParenExpr(ParenExpr *E); |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 277 | void VisitUnaryOperator(UnaryOperator *E); |
| 278 | void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 279 | void VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 280 | void VisitCallExpr(CallExpr *E); |
| 281 | void VisitMemberExpr(MemberExpr *E); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 282 | void VisitCastExpr(CastExpr *E); |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 283 | void VisitBinaryOperator(BinaryOperator *E); |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 284 | void VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 285 | void VisitConditionalOperator(ConditionalOperator *E); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 286 | void VisitImplicitCastExpr(ImplicitCastExpr *E); |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 287 | void VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 288 | void VisitCStyleCastExpr(CStyleCastExpr *E); |
Douglas Gregor | b70b48f | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 289 | void VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 290 | void VisitExtVectorElementExpr(ExtVectorElementExpr *E); |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 291 | void VisitInitListExpr(InitListExpr *E); |
| 292 | void VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 293 | void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 294 | void VisitVAArgExpr(VAArgExpr *E); |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 295 | void VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | eca12f6 | 2009-04-17 19:05:30 +0000 | [diff] [blame] | 296 | void VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 297 | void VisitTypesCompatibleExpr(TypesCompatibleExpr *E); |
| 298 | void VisitChooseExpr(ChooseExpr *E); |
| 299 | void VisitGNUNullExpr(GNUNullExpr *E); |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 300 | void VisitShuffleVectorExpr(ShuffleVectorExpr *E); |
Douglas Gregor | e246b74 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 301 | void VisitBlockExpr(BlockExpr *E); |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 302 | void VisitBlockDeclRefExpr(BlockDeclRefExpr *E); |
Chris Lattner | 80f83c6 | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 303 | |
Steve Naroff | 79762bd | 2009-04-26 18:52:16 +0000 | [diff] [blame] | 304 | // Objective-C Expressions |
Chris Lattner | c49bbe7 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 305 | void VisitObjCStringLiteral(ObjCStringLiteral *E); |
Chris Lattner | 80f83c6 | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 306 | void VisitObjCEncodeExpr(ObjCEncodeExpr *E); |
Chris Lattner | c49bbe7 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 307 | void VisitObjCSelectorExpr(ObjCSelectorExpr *E); |
| 308 | void VisitObjCProtocolExpr(ObjCProtocolExpr *E); |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 309 | void VisitObjCIvarRefExpr(ObjCIvarRefExpr *E); |
| 310 | void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E); |
| 311 | void VisitObjCKVCRefExpr(ObjCKVCRefExpr *E); |
Steve Naroff | fb3e402 | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 312 | void VisitObjCMessageExpr(ObjCMessageExpr *E); |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 313 | void VisitObjCSuperExpr(ObjCSuperExpr *E); |
Steve Naroff | 79762bd | 2009-04-26 18:52:16 +0000 | [diff] [blame] | 314 | |
| 315 | // Objective-C Statements |
| 316 | void VisitObjCForCollectionStmt(ObjCForCollectionStmt *); |
Douglas Gregor | ce06671 | 2009-04-26 22:20:50 +0000 | [diff] [blame] | 317 | void VisitObjCAtCatchStmt(ObjCAtCatchStmt *); |
| 318 | void VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *); |
Steve Naroff | 79762bd | 2009-04-26 18:52:16 +0000 | [diff] [blame] | 319 | void VisitObjCAtTryStmt(ObjCAtTryStmt *); |
| 320 | void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *); |
| 321 | void VisitObjCAtThrowStmt(ObjCAtThrowStmt *); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 322 | }; |
| 323 | } |
| 324 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 325 | void PCHStmtWriter::VisitStmt(Stmt *S) { |
| 326 | } |
| 327 | |
| 328 | void PCHStmtWriter::VisitNullStmt(NullStmt *S) { |
| 329 | VisitStmt(S); |
| 330 | Writer.AddSourceLocation(S->getSemiLoc(), Record); |
| 331 | Code = pch::STMT_NULL; |
| 332 | } |
| 333 | |
| 334 | void PCHStmtWriter::VisitCompoundStmt(CompoundStmt *S) { |
| 335 | VisitStmt(S); |
| 336 | Record.push_back(S->size()); |
| 337 | for (CompoundStmt::body_iterator CS = S->body_begin(), CSEnd = S->body_end(); |
| 338 | CS != CSEnd; ++CS) |
| 339 | Writer.WriteSubStmt(*CS); |
| 340 | Writer.AddSourceLocation(S->getLBracLoc(), Record); |
| 341 | Writer.AddSourceLocation(S->getRBracLoc(), Record); |
| 342 | Code = pch::STMT_COMPOUND; |
| 343 | } |
| 344 | |
| 345 | void PCHStmtWriter::VisitSwitchCase(SwitchCase *S) { |
| 346 | VisitStmt(S); |
| 347 | Record.push_back(Writer.RecordSwitchCaseID(S)); |
| 348 | } |
| 349 | |
| 350 | void PCHStmtWriter::VisitCaseStmt(CaseStmt *S) { |
| 351 | VisitSwitchCase(S); |
| 352 | Writer.WriteSubStmt(S->getLHS()); |
| 353 | Writer.WriteSubStmt(S->getRHS()); |
| 354 | Writer.WriteSubStmt(S->getSubStmt()); |
| 355 | Writer.AddSourceLocation(S->getCaseLoc(), Record); |
| 356 | Code = pch::STMT_CASE; |
| 357 | } |
| 358 | |
| 359 | void PCHStmtWriter::VisitDefaultStmt(DefaultStmt *S) { |
| 360 | VisitSwitchCase(S); |
| 361 | Writer.WriteSubStmt(S->getSubStmt()); |
| 362 | Writer.AddSourceLocation(S->getDefaultLoc(), Record); |
| 363 | Code = pch::STMT_DEFAULT; |
| 364 | } |
| 365 | |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 366 | void PCHStmtWriter::VisitLabelStmt(LabelStmt *S) { |
| 367 | VisitStmt(S); |
| 368 | Writer.AddIdentifierRef(S->getID(), Record); |
| 369 | Writer.WriteSubStmt(S->getSubStmt()); |
| 370 | Writer.AddSourceLocation(S->getIdentLoc(), Record); |
| 371 | Record.push_back(Writer.GetLabelID(S)); |
| 372 | Code = pch::STMT_LABEL; |
| 373 | } |
| 374 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 375 | void PCHStmtWriter::VisitIfStmt(IfStmt *S) { |
| 376 | VisitStmt(S); |
| 377 | Writer.WriteSubStmt(S->getCond()); |
| 378 | Writer.WriteSubStmt(S->getThen()); |
| 379 | Writer.WriteSubStmt(S->getElse()); |
| 380 | Writer.AddSourceLocation(S->getIfLoc(), Record); |
| 381 | Code = pch::STMT_IF; |
| 382 | } |
| 383 | |
| 384 | void PCHStmtWriter::VisitSwitchStmt(SwitchStmt *S) { |
| 385 | VisitStmt(S); |
| 386 | Writer.WriteSubStmt(S->getCond()); |
| 387 | Writer.WriteSubStmt(S->getBody()); |
| 388 | Writer.AddSourceLocation(S->getSwitchLoc(), Record); |
| 389 | for (SwitchCase *SC = S->getSwitchCaseList(); SC; |
| 390 | SC = SC->getNextSwitchCase()) |
| 391 | Record.push_back(Writer.getSwitchCaseID(SC)); |
| 392 | Code = pch::STMT_SWITCH; |
| 393 | } |
| 394 | |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 395 | void PCHStmtWriter::VisitWhileStmt(WhileStmt *S) { |
| 396 | VisitStmt(S); |
| 397 | Writer.WriteSubStmt(S->getCond()); |
| 398 | Writer.WriteSubStmt(S->getBody()); |
| 399 | Writer.AddSourceLocation(S->getWhileLoc(), Record); |
| 400 | Code = pch::STMT_WHILE; |
| 401 | } |
| 402 | |
Douglas Gregor | fb5f25b | 2009-04-17 00:29:51 +0000 | [diff] [blame] | 403 | void PCHStmtWriter::VisitDoStmt(DoStmt *S) { |
| 404 | VisitStmt(S); |
| 405 | Writer.WriteSubStmt(S->getCond()); |
| 406 | Writer.WriteSubStmt(S->getBody()); |
| 407 | Writer.AddSourceLocation(S->getDoLoc(), Record); |
| 408 | Code = pch::STMT_DO; |
| 409 | } |
| 410 | |
| 411 | void PCHStmtWriter::VisitForStmt(ForStmt *S) { |
| 412 | VisitStmt(S); |
| 413 | Writer.WriteSubStmt(S->getInit()); |
| 414 | Writer.WriteSubStmt(S->getCond()); |
| 415 | Writer.WriteSubStmt(S->getInc()); |
| 416 | Writer.WriteSubStmt(S->getBody()); |
| 417 | Writer.AddSourceLocation(S->getForLoc(), Record); |
| 418 | Code = pch::STMT_FOR; |
| 419 | } |
| 420 | |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 421 | void PCHStmtWriter::VisitGotoStmt(GotoStmt *S) { |
| 422 | VisitStmt(S); |
| 423 | Record.push_back(Writer.GetLabelID(S->getLabel())); |
| 424 | Writer.AddSourceLocation(S->getGotoLoc(), Record); |
| 425 | Writer.AddSourceLocation(S->getLabelLoc(), Record); |
| 426 | Code = pch::STMT_GOTO; |
| 427 | } |
| 428 | |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 429 | void PCHStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 430 | VisitStmt(S); |
Chris Lattner | 9ef9c28 | 2009-04-19 01:04:21 +0000 | [diff] [blame] | 431 | Writer.AddSourceLocation(S->getGotoLoc(), Record); |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 432 | Writer.WriteSubStmt(S->getTarget()); |
| 433 | Code = pch::STMT_INDIRECT_GOTO; |
| 434 | } |
| 435 | |
Douglas Gregor | a6b503f | 2009-04-17 00:16:09 +0000 | [diff] [blame] | 436 | void PCHStmtWriter::VisitContinueStmt(ContinueStmt *S) { |
| 437 | VisitStmt(S); |
| 438 | Writer.AddSourceLocation(S->getContinueLoc(), Record); |
| 439 | Code = pch::STMT_CONTINUE; |
| 440 | } |
| 441 | |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 442 | void PCHStmtWriter::VisitBreakStmt(BreakStmt *S) { |
| 443 | VisitStmt(S); |
| 444 | Writer.AddSourceLocation(S->getBreakLoc(), Record); |
| 445 | Code = pch::STMT_BREAK; |
| 446 | } |
| 447 | |
Douglas Gregor | 22d2dcd | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 448 | void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) { |
| 449 | VisitStmt(S); |
| 450 | Writer.WriteSubStmt(S->getRetValue()); |
| 451 | Writer.AddSourceLocation(S->getReturnLoc(), Record); |
| 452 | Code = pch::STMT_RETURN; |
| 453 | } |
| 454 | |
Douglas Gregor | 78ff29f | 2009-04-17 16:55:36 +0000 | [diff] [blame] | 455 | void PCHStmtWriter::VisitDeclStmt(DeclStmt *S) { |
| 456 | VisitStmt(S); |
| 457 | Writer.AddSourceLocation(S->getStartLoc(), Record); |
| 458 | Writer.AddSourceLocation(S->getEndLoc(), Record); |
| 459 | DeclGroupRef DG = S->getDeclGroup(); |
| 460 | for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D) |
| 461 | Writer.AddDeclRef(*D, Record); |
| 462 | Code = pch::STMT_DECL; |
| 463 | } |
| 464 | |
Douglas Gregor | 3e1f9fb | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 465 | void PCHStmtWriter::VisitAsmStmt(AsmStmt *S) { |
| 466 | VisitStmt(S); |
| 467 | Record.push_back(S->getNumOutputs()); |
| 468 | Record.push_back(S->getNumInputs()); |
| 469 | Record.push_back(S->getNumClobbers()); |
| 470 | Writer.AddSourceLocation(S->getAsmLoc(), Record); |
| 471 | Writer.AddSourceLocation(S->getRParenLoc(), Record); |
| 472 | Record.push_back(S->isVolatile()); |
| 473 | Record.push_back(S->isSimple()); |
| 474 | Writer.WriteSubStmt(S->getAsmString()); |
| 475 | |
| 476 | // Outputs |
| 477 | for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { |
| 478 | Writer.AddString(S->getOutputName(I), Record); |
| 479 | Writer.WriteSubStmt(S->getOutputConstraintLiteral(I)); |
| 480 | Writer.WriteSubStmt(S->getOutputExpr(I)); |
| 481 | } |
| 482 | |
| 483 | // Inputs |
| 484 | for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) { |
| 485 | Writer.AddString(S->getInputName(I), Record); |
| 486 | Writer.WriteSubStmt(S->getInputConstraintLiteral(I)); |
| 487 | Writer.WriteSubStmt(S->getInputExpr(I)); |
| 488 | } |
| 489 | |
| 490 | // Clobbers |
| 491 | for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) |
| 492 | Writer.WriteSubStmt(S->getClobber(I)); |
| 493 | |
| 494 | Code = pch::STMT_ASM; |
| 495 | } |
| 496 | |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 497 | void PCHStmtWriter::VisitExpr(Expr *E) { |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 498 | VisitStmt(E); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 499 | Writer.AddTypeRef(E->getType(), Record); |
| 500 | Record.push_back(E->isTypeDependent()); |
| 501 | Record.push_back(E->isValueDependent()); |
| 502 | } |
| 503 | |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 504 | void PCHStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 505 | VisitExpr(E); |
| 506 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 507 | Record.push_back(E->getIdentType()); // FIXME: stable encoding |
| 508 | Code = pch::EXPR_PREDEFINED; |
| 509 | } |
| 510 | |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 511 | void PCHStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 512 | VisitExpr(E); |
| 513 | Writer.AddDeclRef(E->getDecl(), Record); |
| 514 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 515 | Code = pch::EXPR_DECL_REF; |
| 516 | } |
| 517 | |
| 518 | void PCHStmtWriter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 519 | VisitExpr(E); |
| 520 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 521 | Writer.AddAPInt(E->getValue(), Record); |
| 522 | Code = pch::EXPR_INTEGER_LITERAL; |
| 523 | } |
| 524 | |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 525 | void PCHStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 526 | VisitExpr(E); |
| 527 | Writer.AddAPFloat(E->getValue(), Record); |
| 528 | Record.push_back(E->isExact()); |
| 529 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 530 | Code = pch::EXPR_FLOATING_LITERAL; |
| 531 | } |
| 532 | |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 533 | void PCHStmtWriter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 534 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 535 | Writer.WriteSubStmt(E->getSubExpr()); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 536 | Code = pch::EXPR_IMAGINARY_LITERAL; |
| 537 | } |
| 538 | |
Douglas Gregor | 596e093 | 2009-04-15 16:35:07 +0000 | [diff] [blame] | 539 | void PCHStmtWriter::VisitStringLiteral(StringLiteral *E) { |
| 540 | VisitExpr(E); |
| 541 | Record.push_back(E->getByteLength()); |
| 542 | Record.push_back(E->getNumConcatenated()); |
| 543 | Record.push_back(E->isWide()); |
| 544 | // FIXME: String data should be stored as a blob at the end of the |
| 545 | // StringLiteral. However, we can't do so now because we have no |
| 546 | // provision for coping with abbreviations when we're jumping around |
| 547 | // the PCH file during deserialization. |
| 548 | Record.insert(Record.end(), |
| 549 | E->getStrData(), E->getStrData() + E->getByteLength()); |
| 550 | for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I) |
| 551 | Writer.AddSourceLocation(E->getStrTokenLoc(I), Record); |
| 552 | Code = pch::EXPR_STRING_LITERAL; |
| 553 | } |
| 554 | |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 555 | void PCHStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 556 | VisitExpr(E); |
| 557 | Record.push_back(E->getValue()); |
| 558 | Writer.AddSourceLocation(E->getLoc(), Record); |
| 559 | Record.push_back(E->isWide()); |
| 560 | Code = pch::EXPR_CHARACTER_LITERAL; |
| 561 | } |
| 562 | |
Douglas Gregor | 4ea0b1f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 563 | void PCHStmtWriter::VisitParenExpr(ParenExpr *E) { |
| 564 | VisitExpr(E); |
| 565 | Writer.AddSourceLocation(E->getLParen(), Record); |
| 566 | Writer.AddSourceLocation(E->getRParen(), Record); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 567 | Writer.WriteSubStmt(E->getSubExpr()); |
Douglas Gregor | 4ea0b1f | 2009-04-14 23:59:37 +0000 | [diff] [blame] | 568 | Code = pch::EXPR_PAREN; |
| 569 | } |
| 570 | |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 571 | void PCHStmtWriter::VisitUnaryOperator(UnaryOperator *E) { |
| 572 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 573 | Writer.WriteSubStmt(E->getSubExpr()); |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 574 | Record.push_back(E->getOpcode()); // FIXME: stable encoding |
| 575 | Writer.AddSourceLocation(E->getOperatorLoc(), Record); |
| 576 | Code = pch::EXPR_UNARY_OPERATOR; |
| 577 | } |
| 578 | |
| 579 | void PCHStmtWriter::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
| 580 | VisitExpr(E); |
| 581 | Record.push_back(E->isSizeOf()); |
| 582 | if (E->isArgumentType()) |
| 583 | Writer.AddTypeRef(E->getArgumentType(), Record); |
| 584 | else { |
| 585 | Record.push_back(0); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 586 | Writer.WriteSubStmt(E->getArgumentExpr()); |
Douglas Gregor | 12d7405 | 2009-04-15 15:58:59 +0000 | [diff] [blame] | 587 | } |
| 588 | Writer.AddSourceLocation(E->getOperatorLoc(), Record); |
| 589 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 590 | Code = pch::EXPR_SIZEOF_ALIGN_OF; |
| 591 | } |
| 592 | |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 593 | void PCHStmtWriter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 594 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 595 | Writer.WriteSubStmt(E->getLHS()); |
| 596 | Writer.WriteSubStmt(E->getRHS()); |
Douglas Gregor | 21ddd8c | 2009-04-15 22:19:53 +0000 | [diff] [blame] | 597 | Writer.AddSourceLocation(E->getRBracketLoc(), Record); |
| 598 | Code = pch::EXPR_ARRAY_SUBSCRIPT; |
| 599 | } |
| 600 | |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 601 | void PCHStmtWriter::VisitCallExpr(CallExpr *E) { |
| 602 | VisitExpr(E); |
| 603 | Record.push_back(E->getNumArgs()); |
| 604 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 605 | Writer.WriteSubStmt(E->getCallee()); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 606 | for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); |
| 607 | Arg != ArgEnd; ++Arg) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 608 | Writer.WriteSubStmt(*Arg); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 609 | Code = pch::EXPR_CALL; |
| 610 | } |
| 611 | |
| 612 | void PCHStmtWriter::VisitMemberExpr(MemberExpr *E) { |
| 613 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 614 | Writer.WriteSubStmt(E->getBase()); |
Douglas Gregor | 7e2b1cd | 2009-04-15 17:43:59 +0000 | [diff] [blame] | 615 | Writer.AddDeclRef(E->getMemberDecl(), Record); |
| 616 | Writer.AddSourceLocation(E->getMemberLoc(), Record); |
| 617 | Record.push_back(E->isArrow()); |
| 618 | Code = pch::EXPR_MEMBER; |
| 619 | } |
| 620 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 621 | void PCHStmtWriter::VisitCastExpr(CastExpr *E) { |
| 622 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 623 | Writer.WriteSubStmt(E->getSubExpr()); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 626 | void PCHStmtWriter::VisitBinaryOperator(BinaryOperator *E) { |
| 627 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 628 | Writer.WriteSubStmt(E->getLHS()); |
| 629 | Writer.WriteSubStmt(E->getRHS()); |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 630 | Record.push_back(E->getOpcode()); // FIXME: stable encoding |
| 631 | Writer.AddSourceLocation(E->getOperatorLoc(), Record); |
| 632 | Code = pch::EXPR_BINARY_OPERATOR; |
| 633 | } |
| 634 | |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 635 | void PCHStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 636 | VisitBinaryOperator(E); |
| 637 | Writer.AddTypeRef(E->getComputationLHSType(), Record); |
| 638 | Writer.AddTypeRef(E->getComputationResultType(), Record); |
| 639 | Code = pch::EXPR_COMPOUND_ASSIGN_OPERATOR; |
| 640 | } |
| 641 | |
| 642 | void PCHStmtWriter::VisitConditionalOperator(ConditionalOperator *E) { |
| 643 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 644 | Writer.WriteSubStmt(E->getCond()); |
| 645 | Writer.WriteSubStmt(E->getLHS()); |
| 646 | Writer.WriteSubStmt(E->getRHS()); |
Douglas Gregor | c599bbf | 2009-04-15 22:40:36 +0000 | [diff] [blame] | 647 | Code = pch::EXPR_CONDITIONAL_OPERATOR; |
| 648 | } |
| 649 | |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 650 | void PCHStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 651 | VisitCastExpr(E); |
| 652 | Record.push_back(E->isLvalueCast()); |
| 653 | Code = pch::EXPR_IMPLICIT_CAST; |
| 654 | } |
| 655 | |
Douglas Gregor | c75d0cb | 2009-04-15 00:25:59 +0000 | [diff] [blame] | 656 | void PCHStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 657 | VisitCastExpr(E); |
| 658 | Writer.AddTypeRef(E->getTypeAsWritten(), Record); |
| 659 | } |
| 660 | |
| 661 | void PCHStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) { |
| 662 | VisitExplicitCastExpr(E); |
| 663 | Writer.AddSourceLocation(E->getLParenLoc(), Record); |
| 664 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 665 | Code = pch::EXPR_CSTYLE_CAST; |
| 666 | } |
| 667 | |
Douglas Gregor | b70b48f | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 668 | void PCHStmtWriter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 669 | VisitExpr(E); |
| 670 | Writer.AddSourceLocation(E->getLParenLoc(), Record); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 671 | Writer.WriteSubStmt(E->getInitializer()); |
Douglas Gregor | b70b48f | 2009-04-16 02:33:48 +0000 | [diff] [blame] | 672 | Record.push_back(E->isFileScope()); |
| 673 | Code = pch::EXPR_COMPOUND_LITERAL; |
| 674 | } |
| 675 | |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 676 | void PCHStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) { |
| 677 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 678 | Writer.WriteSubStmt(E->getBase()); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 679 | Writer.AddIdentifierRef(&E->getAccessor(), Record); |
| 680 | Writer.AddSourceLocation(E->getAccessorLoc(), Record); |
| 681 | Code = pch::EXPR_EXT_VECTOR_ELEMENT; |
| 682 | } |
| 683 | |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 684 | void PCHStmtWriter::VisitInitListExpr(InitListExpr *E) { |
| 685 | VisitExpr(E); |
| 686 | Record.push_back(E->getNumInits()); |
| 687 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 688 | Writer.WriteSubStmt(E->getInit(I)); |
| 689 | Writer.WriteSubStmt(E->getSyntacticForm()); |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 690 | Writer.AddSourceLocation(E->getLBraceLoc(), Record); |
| 691 | Writer.AddSourceLocation(E->getRBraceLoc(), Record); |
| 692 | Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record); |
| 693 | Record.push_back(E->hadArrayRangeDesignator()); |
| 694 | Code = pch::EXPR_INIT_LIST; |
| 695 | } |
| 696 | |
| 697 | void PCHStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 698 | VisitExpr(E); |
| 699 | Record.push_back(E->getNumSubExprs()); |
| 700 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 701 | Writer.WriteSubStmt(E->getSubExpr(I)); |
Douglas Gregor | 6710a3c | 2009-04-16 00:55:48 +0000 | [diff] [blame] | 702 | Writer.AddSourceLocation(E->getEqualOrColonLoc(), Record); |
| 703 | Record.push_back(E->usesGNUSyntax()); |
| 704 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 705 | DEnd = E->designators_end(); |
| 706 | D != DEnd; ++D) { |
| 707 | if (D->isFieldDesignator()) { |
| 708 | if (FieldDecl *Field = D->getField()) { |
| 709 | Record.push_back(pch::DESIG_FIELD_DECL); |
| 710 | Writer.AddDeclRef(Field, Record); |
| 711 | } else { |
| 712 | Record.push_back(pch::DESIG_FIELD_NAME); |
| 713 | Writer.AddIdentifierRef(D->getFieldName(), Record); |
| 714 | } |
| 715 | Writer.AddSourceLocation(D->getDotLoc(), Record); |
| 716 | Writer.AddSourceLocation(D->getFieldLoc(), Record); |
| 717 | } else if (D->isArrayDesignator()) { |
| 718 | Record.push_back(pch::DESIG_ARRAY); |
| 719 | Record.push_back(D->getFirstExprIndex()); |
| 720 | Writer.AddSourceLocation(D->getLBracketLoc(), Record); |
| 721 | Writer.AddSourceLocation(D->getRBracketLoc(), Record); |
| 722 | } else { |
| 723 | assert(D->isArrayRangeDesignator() && "Unknown designator"); |
| 724 | Record.push_back(pch::DESIG_ARRAY_RANGE); |
| 725 | Record.push_back(D->getFirstExprIndex()); |
| 726 | Writer.AddSourceLocation(D->getLBracketLoc(), Record); |
| 727 | Writer.AddSourceLocation(D->getEllipsisLoc(), Record); |
| 728 | Writer.AddSourceLocation(D->getRBracketLoc(), Record); |
| 729 | } |
| 730 | } |
| 731 | Code = pch::EXPR_DESIGNATED_INIT; |
| 732 | } |
| 733 | |
| 734 | void PCHStmtWriter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 735 | VisitExpr(E); |
| 736 | Code = pch::EXPR_IMPLICIT_VALUE_INIT; |
| 737 | } |
| 738 | |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 739 | void PCHStmtWriter::VisitVAArgExpr(VAArgExpr *E) { |
| 740 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 741 | Writer.WriteSubStmt(E->getSubExpr()); |
Douglas Gregor | ec0b829 | 2009-04-15 23:02:49 +0000 | [diff] [blame] | 742 | Writer.AddSourceLocation(E->getBuiltinLoc(), Record); |
| 743 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 744 | Code = pch::EXPR_VA_ARG; |
| 745 | } |
| 746 | |
Douglas Gregor | 95a8fe3 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 747 | void PCHStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 748 | VisitExpr(E); |
| 749 | Writer.AddSourceLocation(E->getAmpAmpLoc(), Record); |
| 750 | Writer.AddSourceLocation(E->getLabelLoc(), Record); |
| 751 | Record.push_back(Writer.GetLabelID(E->getLabel())); |
| 752 | Code = pch::EXPR_ADDR_LABEL; |
| 753 | } |
| 754 | |
Douglas Gregor | eca12f6 | 2009-04-17 19:05:30 +0000 | [diff] [blame] | 755 | void PCHStmtWriter::VisitStmtExpr(StmtExpr *E) { |
| 756 | VisitExpr(E); |
| 757 | Writer.WriteSubStmt(E->getSubStmt()); |
| 758 | Writer.AddSourceLocation(E->getLParenLoc(), Record); |
| 759 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 760 | Code = pch::EXPR_STMT; |
| 761 | } |
| 762 | |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 763 | void PCHStmtWriter::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) { |
| 764 | VisitExpr(E); |
| 765 | Writer.AddTypeRef(E->getArgType1(), Record); |
| 766 | Writer.AddTypeRef(E->getArgType2(), Record); |
| 767 | Writer.AddSourceLocation(E->getBuiltinLoc(), Record); |
| 768 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 769 | Code = pch::EXPR_TYPES_COMPATIBLE; |
| 770 | } |
| 771 | |
| 772 | void PCHStmtWriter::VisitChooseExpr(ChooseExpr *E) { |
| 773 | VisitExpr(E); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 774 | Writer.WriteSubStmt(E->getCond()); |
| 775 | Writer.WriteSubStmt(E->getLHS()); |
| 776 | Writer.WriteSubStmt(E->getRHS()); |
Douglas Gregor | 209d462 | 2009-04-15 23:33:31 +0000 | [diff] [blame] | 777 | Writer.AddSourceLocation(E->getBuiltinLoc(), Record); |
| 778 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 779 | Code = pch::EXPR_CHOOSE; |
| 780 | } |
| 781 | |
| 782 | void PCHStmtWriter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 783 | VisitExpr(E); |
| 784 | Writer.AddSourceLocation(E->getTokenLocation(), Record); |
| 785 | Code = pch::EXPR_GNU_NULL; |
| 786 | } |
| 787 | |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 788 | void PCHStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { |
| 789 | VisitExpr(E); |
| 790 | Record.push_back(E->getNumSubExprs()); |
| 791 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 792 | Writer.WriteSubStmt(E->getExpr(I)); |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 793 | Writer.AddSourceLocation(E->getBuiltinLoc(), Record); |
| 794 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 795 | Code = pch::EXPR_SHUFFLE_VECTOR; |
| 796 | } |
| 797 | |
Douglas Gregor | e246b74 | 2009-04-17 19:21:43 +0000 | [diff] [blame] | 798 | void PCHStmtWriter::VisitBlockExpr(BlockExpr *E) { |
| 799 | VisitExpr(E); |
| 800 | Writer.AddDeclRef(E->getBlockDecl(), Record); |
| 801 | Record.push_back(E->hasBlockDeclRefExprs()); |
| 802 | Code = pch::EXPR_BLOCK; |
| 803 | } |
| 804 | |
Douglas Gregor | 725e94b | 2009-04-16 00:01:45 +0000 | [diff] [blame] | 805 | void PCHStmtWriter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { |
| 806 | VisitExpr(E); |
| 807 | Writer.AddDeclRef(E->getDecl(), Record); |
| 808 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 809 | Record.push_back(E->isByRef()); |
| 810 | Code = pch::EXPR_BLOCK_DECL_REF; |
| 811 | } |
| 812 | |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 813 | //===----------------------------------------------------------------------===// |
Chris Lattner | 80f83c6 | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 814 | // Objective-C Expressions and Statements. |
| 815 | //===----------------------------------------------------------------------===// |
| 816 | |
Chris Lattner | c49bbe7 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 817 | void PCHStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) { |
| 818 | VisitExpr(E); |
| 819 | Writer.WriteSubStmt(E->getString()); |
| 820 | Writer.AddSourceLocation(E->getAtLoc(), Record); |
| 821 | Code = pch::EXPR_OBJC_STRING_LITERAL; |
| 822 | } |
| 823 | |
Chris Lattner | 80f83c6 | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 824 | void PCHStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { |
| 825 | VisitExpr(E); |
| 826 | Writer.AddTypeRef(E->getEncodedType(), Record); |
| 827 | Writer.AddSourceLocation(E->getAtLoc(), Record); |
| 828 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 829 | Code = pch::EXPR_OBJC_ENCODE; |
| 830 | } |
| 831 | |
Chris Lattner | c49bbe7 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 832 | void PCHStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 833 | VisitExpr(E); |
Steve Naroff | 9e84d78 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 834 | Writer.AddSelectorRef(E->getSelector(), Record); |
Chris Lattner | c49bbe7 | 2009-04-22 06:29:42 +0000 | [diff] [blame] | 835 | Writer.AddSourceLocation(E->getAtLoc(), Record); |
| 836 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 837 | Code = pch::EXPR_OBJC_SELECTOR_EXPR; |
| 838 | } |
| 839 | |
| 840 | void PCHStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 841 | VisitExpr(E); |
| 842 | Writer.AddDeclRef(E->getProtocol(), Record); |
| 843 | Writer.AddSourceLocation(E->getAtLoc(), Record); |
| 844 | Writer.AddSourceLocation(E->getRParenLoc(), Record); |
| 845 | Code = pch::EXPR_OBJC_PROTOCOL_EXPR; |
| 846 | } |
| 847 | |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 848 | void PCHStmtWriter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| 849 | VisitExpr(E); |
| 850 | Writer.AddDeclRef(E->getDecl(), Record); |
| 851 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 852 | Writer.WriteSubStmt(E->getBase()); |
| 853 | Record.push_back(E->isArrow()); |
| 854 | Record.push_back(E->isFreeIvar()); |
Steve Naroff | a323e97 | 2009-04-26 14:11:39 +0000 | [diff] [blame] | 855 | Code = pch::EXPR_OBJC_IVAR_REF_EXPR; |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | void PCHStmtWriter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 859 | VisitExpr(E); |
| 860 | Writer.AddDeclRef(E->getProperty(), Record); |
| 861 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 862 | Writer.WriteSubStmt(E->getBase()); |
Steve Naroff | a323e97 | 2009-04-26 14:11:39 +0000 | [diff] [blame] | 863 | Code = pch::EXPR_OBJC_PROPERTY_REF_EXPR; |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | void PCHStmtWriter::VisitObjCKVCRefExpr(ObjCKVCRefExpr *E) { |
| 867 | VisitExpr(E); |
| 868 | Writer.AddDeclRef(E->getGetterMethod(), Record); |
| 869 | Writer.AddDeclRef(E->getSetterMethod(), Record); |
| 870 | |
| 871 | // NOTE: ClassProp and Base are mutually exclusive. |
| 872 | Writer.AddDeclRef(E->getClassProp(), Record); |
| 873 | Writer.WriteSubStmt(E->getBase()); |
| 874 | Writer.AddSourceLocation(E->getLocation(), Record); |
| 875 | Writer.AddSourceLocation(E->getClassLoc(), Record); |
Steve Naroff | a323e97 | 2009-04-26 14:11:39 +0000 | [diff] [blame] | 876 | Code = pch::EXPR_OBJC_KVC_REF_EXPR; |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Steve Naroff | fb3e402 | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 879 | void PCHStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) { |
| 880 | VisitExpr(E); |
| 881 | Record.push_back(E->getNumArgs()); |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 882 | Writer.AddSourceLocation(E->getLeftLoc(), Record); |
| 883 | Writer.AddSourceLocation(E->getRightLoc(), Record); |
Steve Naroff | fb3e402 | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 884 | Writer.AddSelectorRef(E->getSelector(), Record); |
| 885 | Writer.AddDeclRef(E->getMethodDecl(), Record); // optional |
Steve Naroff | fb3e402 | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 886 | Writer.WriteSubStmt(E->getReceiver()); |
Douglas Gregor | ce06671 | 2009-04-26 22:20:50 +0000 | [diff] [blame] | 887 | |
| 888 | if (!E->getReceiver()) { |
| 889 | ObjCMessageExpr::ClassInfo CI = E->getClassInfo(); |
| 890 | Writer.AddDeclRef(CI.first, Record); |
| 891 | Writer.AddIdentifierRef(CI.second, Record); |
| 892 | } |
| 893 | |
Steve Naroff | fb3e402 | 2009-04-25 14:04:28 +0000 | [diff] [blame] | 894 | for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); |
| 895 | Arg != ArgEnd; ++Arg) |
| 896 | Writer.WriteSubStmt(*Arg); |
| 897 | Code = pch::EXPR_OBJC_MESSAGE_EXPR; |
| 898 | } |
| 899 | |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 900 | void PCHStmtWriter::VisitObjCSuperExpr(ObjCSuperExpr *E) { |
| 901 | VisitExpr(E); |
| 902 | Writer.AddSourceLocation(E->getLoc(), Record); |
Steve Naroff | a323e97 | 2009-04-26 14:11:39 +0000 | [diff] [blame] | 903 | Code = pch::EXPR_OBJC_SUPER_EXPR; |
Chris Lattner | c0478bf | 2009-04-26 00:44:05 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Steve Naroff | 79762bd | 2009-04-26 18:52:16 +0000 | [diff] [blame] | 906 | void PCHStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 907 | VisitStmt(S); |
| 908 | Writer.WriteSubStmt(S->getElement()); |
| 909 | Writer.WriteSubStmt(S->getCollection()); |
| 910 | Writer.WriteSubStmt(S->getBody()); |
| 911 | Writer.AddSourceLocation(S->getForLoc(), Record); |
| 912 | Writer.AddSourceLocation(S->getRParenLoc(), Record); |
| 913 | Code = pch::STMT_OBJC_FOR_COLLECTION; |
| 914 | } |
| 915 | |
Douglas Gregor | ce06671 | 2009-04-26 22:20:50 +0000 | [diff] [blame] | 916 | void PCHStmtWriter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Steve Naroff | 79762bd | 2009-04-26 18:52:16 +0000 | [diff] [blame] | 917 | Writer.WriteSubStmt(S->getCatchBody()); |
| 918 | Writer.WriteSubStmt(S->getNextCatchStmt()); |
| 919 | Writer.AddDeclRef(S->getCatchParamDecl(), Record); |
| 920 | Writer.AddSourceLocation(S->getAtCatchLoc(), Record); |
| 921 | Writer.AddSourceLocation(S->getRParenLoc(), Record); |
| 922 | Code = pch::STMT_OBJC_CATCH; |
| 923 | } |
| 924 | |
Douglas Gregor | ce06671 | 2009-04-26 22:20:50 +0000 | [diff] [blame] | 925 | void PCHStmtWriter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Steve Naroff | 79762bd | 2009-04-26 18:52:16 +0000 | [diff] [blame] | 926 | Writer.WriteSubStmt(S->getFinallyBody()); |
| 927 | Writer.AddSourceLocation(S->getAtFinallyLoc(), Record); |
| 928 | Code = pch::STMT_OBJC_FINALLY; |
| 929 | } |
| 930 | |
| 931 | void PCHStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 932 | Writer.WriteSubStmt(S->getTryBody()); |
| 933 | Writer.WriteSubStmt(S->getCatchStmts()); |
| 934 | Writer.WriteSubStmt(S->getFinallyStmt()); |
| 935 | Writer.AddSourceLocation(S->getAtTryLoc(), Record); |
| 936 | Code = pch::STMT_OBJC_AT_TRY; |
| 937 | } |
| 938 | |
| 939 | void PCHStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { |
| 940 | Writer.WriteSubStmt(S->getSynchExpr()); |
| 941 | Writer.WriteSubStmt(S->getSynchBody()); |
| 942 | Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record); |
| 943 | Code = pch::STMT_OBJC_AT_SYNCHRONIZED; |
| 944 | } |
| 945 | |
| 946 | void PCHStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 947 | Writer.WriteSubStmt(S->getThrowExpr()); |
| 948 | Writer.AddSourceLocation(S->getThrowLoc(), Record); |
| 949 | Code = pch::STMT_OBJC_AT_THROW; |
| 950 | } |
Chris Lattner | 80f83c6 | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 951 | |
| 952 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 953 | // PCHWriter Implementation |
| 954 | //===----------------------------------------------------------------------===// |
| 955 | |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 956 | static void EmitBlockID(unsigned ID, const char *Name, |
| 957 | llvm::BitstreamWriter &Stream, |
| 958 | PCHWriter::RecordData &Record) { |
| 959 | Record.clear(); |
| 960 | Record.push_back(ID); |
| 961 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 962 | |
| 963 | // Emit the block name if present. |
| 964 | if (Name == 0 || Name[0] == 0) return; |
| 965 | Record.clear(); |
| 966 | while (*Name) |
| 967 | Record.push_back(*Name++); |
| 968 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 969 | } |
| 970 | |
| 971 | static void EmitRecordID(unsigned ID, const char *Name, |
| 972 | llvm::BitstreamWriter &Stream, |
| 973 | PCHWriter::RecordData &Record) { |
| 974 | Record.clear(); |
| 975 | Record.push_back(ID); |
| 976 | while (*Name) |
| 977 | Record.push_back(*Name++); |
| 978 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | d16afaa | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
| 982 | PCHWriter::RecordData &Record) { |
| 983 | #define RECORD(X) EmitRecordID(pch::X, #X, Stream, Record) |
| 984 | RECORD(STMT_STOP); |
| 985 | RECORD(STMT_NULL_PTR); |
| 986 | RECORD(STMT_NULL); |
| 987 | RECORD(STMT_COMPOUND); |
| 988 | RECORD(STMT_CASE); |
| 989 | RECORD(STMT_DEFAULT); |
| 990 | RECORD(STMT_LABEL); |
| 991 | RECORD(STMT_IF); |
| 992 | RECORD(STMT_SWITCH); |
| 993 | RECORD(STMT_WHILE); |
| 994 | RECORD(STMT_DO); |
| 995 | RECORD(STMT_FOR); |
| 996 | RECORD(STMT_GOTO); |
| 997 | RECORD(STMT_INDIRECT_GOTO); |
| 998 | RECORD(STMT_CONTINUE); |
| 999 | RECORD(STMT_BREAK); |
| 1000 | RECORD(STMT_RETURN); |
| 1001 | RECORD(STMT_DECL); |
| 1002 | RECORD(STMT_ASM); |
| 1003 | RECORD(EXPR_PREDEFINED); |
| 1004 | RECORD(EXPR_DECL_REF); |
| 1005 | RECORD(EXPR_INTEGER_LITERAL); |
| 1006 | RECORD(EXPR_FLOATING_LITERAL); |
| 1007 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 1008 | RECORD(EXPR_STRING_LITERAL); |
| 1009 | RECORD(EXPR_CHARACTER_LITERAL); |
| 1010 | RECORD(EXPR_PAREN); |
| 1011 | RECORD(EXPR_UNARY_OPERATOR); |
| 1012 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 1013 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 1014 | RECORD(EXPR_CALL); |
| 1015 | RECORD(EXPR_MEMBER); |
| 1016 | RECORD(EXPR_BINARY_OPERATOR); |
| 1017 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 1018 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 1019 | RECORD(EXPR_IMPLICIT_CAST); |
| 1020 | RECORD(EXPR_CSTYLE_CAST); |
| 1021 | RECORD(EXPR_COMPOUND_LITERAL); |
| 1022 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 1023 | RECORD(EXPR_INIT_LIST); |
| 1024 | RECORD(EXPR_DESIGNATED_INIT); |
| 1025 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 1026 | RECORD(EXPR_VA_ARG); |
| 1027 | RECORD(EXPR_ADDR_LABEL); |
| 1028 | RECORD(EXPR_STMT); |
| 1029 | RECORD(EXPR_TYPES_COMPATIBLE); |
| 1030 | RECORD(EXPR_CHOOSE); |
| 1031 | RECORD(EXPR_GNU_NULL); |
| 1032 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 1033 | RECORD(EXPR_BLOCK); |
| 1034 | RECORD(EXPR_BLOCK_DECL_REF); |
| 1035 | RECORD(EXPR_OBJC_STRING_LITERAL); |
| 1036 | RECORD(EXPR_OBJC_ENCODE); |
| 1037 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 1038 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 1039 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 1040 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 1041 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 1042 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
| 1043 | RECORD(EXPR_OBJC_SUPER_EXPR); |
| 1044 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 1045 | RECORD(STMT_OBJC_CATCH); |
| 1046 | RECORD(STMT_OBJC_FINALLY); |
| 1047 | RECORD(STMT_OBJC_AT_TRY); |
| 1048 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 1049 | RECORD(STMT_OBJC_AT_THROW); |
| 1050 | #undef RECORD |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | void PCHWriter::WriteBlockInfoBlock() { |
| 1054 | RecordData Record; |
| 1055 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
| 1056 | |
Chris Lattner | 880f3f7 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1057 | #define BLOCK(X) EmitBlockID(pch::X ## _ID, #X, Stream, Record) |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1058 | #define RECORD(X) EmitRecordID(pch::X, #X, Stream, Record) |
| 1059 | |
| 1060 | // PCH Top-Level Block. |
Chris Lattner | 880f3f7 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1061 | BLOCK(PCH_BLOCK); |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1062 | RECORD(TYPE_OFFSET); |
| 1063 | RECORD(DECL_OFFSET); |
| 1064 | RECORD(LANGUAGE_OPTIONS); |
| 1065 | RECORD(TARGET_TRIPLE); |
| 1066 | RECORD(IDENTIFIER_OFFSET); |
| 1067 | RECORD(IDENTIFIER_TABLE); |
| 1068 | RECORD(EXTERNAL_DEFINITIONS); |
| 1069 | RECORD(SPECIAL_TYPES); |
| 1070 | RECORD(STATISTICS); |
| 1071 | RECORD(TENTATIVE_DEFINITIONS); |
| 1072 | RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); |
| 1073 | RECORD(SELECTOR_OFFSETS); |
| 1074 | RECORD(METHOD_POOL); |
| 1075 | RECORD(PP_COUNTER_VALUE); |
| 1076 | |
| 1077 | // SourceManager Block. |
Chris Lattner | 880f3f7 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1078 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1079 | RECORD(SM_SLOC_FILE_ENTRY); |
| 1080 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 1081 | RECORD(SM_SLOC_BUFFER_BLOB); |
| 1082 | RECORD(SM_SLOC_INSTANTIATION_ENTRY); |
| 1083 | RECORD(SM_LINE_TABLE); |
| 1084 | RECORD(SM_HEADER_FILE_INFO); |
| 1085 | |
| 1086 | // Preprocessor Block. |
Chris Lattner | 880f3f7 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1087 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1088 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 1089 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 1090 | RECORD(PP_TOKEN); |
| 1091 | |
| 1092 | // Types block. |
Chris Lattner | 880f3f7 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1093 | BLOCK(TYPES_BLOCK); |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1094 | RECORD(TYPE_EXT_QUAL); |
| 1095 | RECORD(TYPE_FIXED_WIDTH_INT); |
| 1096 | RECORD(TYPE_COMPLEX); |
| 1097 | RECORD(TYPE_POINTER); |
| 1098 | RECORD(TYPE_BLOCK_POINTER); |
| 1099 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1100 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1101 | RECORD(TYPE_MEMBER_POINTER); |
| 1102 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1103 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1104 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1105 | RECORD(TYPE_VECTOR); |
| 1106 | RECORD(TYPE_EXT_VECTOR); |
| 1107 | RECORD(TYPE_FUNCTION_PROTO); |
| 1108 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 1109 | RECORD(TYPE_TYPEDEF); |
| 1110 | RECORD(TYPE_TYPEOF_EXPR); |
| 1111 | RECORD(TYPE_TYPEOF); |
| 1112 | RECORD(TYPE_RECORD); |
| 1113 | RECORD(TYPE_ENUM); |
| 1114 | RECORD(TYPE_OBJC_INTERFACE); |
| 1115 | RECORD(TYPE_OBJC_QUALIFIED_INTERFACE); |
| 1116 | RECORD(TYPE_OBJC_QUALIFIED_ID); |
Chris Lattner | d16afaa | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1117 | // Statements and Exprs can occur in the Types block. |
| 1118 | AddStmtsExprs(Stream, Record); |
| 1119 | |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1120 | // Decls block. |
Chris Lattner | 880f3f7 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1121 | BLOCK(DECLS_BLOCK); |
Chris Lattner | 8a0e316 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1122 | RECORD(DECL_ATTR); |
| 1123 | RECORD(DECL_TRANSLATION_UNIT); |
| 1124 | RECORD(DECL_TYPEDEF); |
| 1125 | RECORD(DECL_ENUM); |
| 1126 | RECORD(DECL_RECORD); |
| 1127 | RECORD(DECL_ENUM_CONSTANT); |
| 1128 | RECORD(DECL_FUNCTION); |
| 1129 | RECORD(DECL_OBJC_METHOD); |
| 1130 | RECORD(DECL_OBJC_INTERFACE); |
| 1131 | RECORD(DECL_OBJC_PROTOCOL); |
| 1132 | RECORD(DECL_OBJC_IVAR); |
| 1133 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
| 1134 | RECORD(DECL_OBJC_CLASS); |
| 1135 | RECORD(DECL_OBJC_FORWARD_PROTOCOL); |
| 1136 | RECORD(DECL_OBJC_CATEGORY); |
| 1137 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1138 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1139 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1140 | RECORD(DECL_OBJC_PROPERTY); |
| 1141 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1142 | RECORD(DECL_FIELD); |
| 1143 | RECORD(DECL_VAR); |
Chris Lattner | 8a0e316 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1144 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1145 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 8a0e316 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1146 | RECORD(DECL_ORIGINAL_PARM_VAR); |
| 1147 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1148 | RECORD(DECL_BLOCK); |
| 1149 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1150 | RECORD(DECL_CONTEXT_VISIBLE); |
Chris Lattner | d16afaa | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1151 | // Statements and Exprs can occur in the Decls block. |
| 1152 | AddStmtsExprs(Stream, Record); |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1153 | #undef RECORD |
| 1154 | #undef BLOCK |
| 1155 | Stream.ExitBlock(); |
| 1156 | } |
| 1157 | |
| 1158 | |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1159 | /// \brief Write the target triple (e.g., i686-apple-darwin9). |
| 1160 | void PCHWriter::WriteTargetTriple(const TargetInfo &Target) { |
| 1161 | using namespace llvm; |
| 1162 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1163 | Abbrev->Add(BitCodeAbbrevOp(pch::TARGET_TRIPLE)); |
| 1164 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Triple name |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1165 | unsigned TripleAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1166 | |
| 1167 | RecordData Record; |
| 1168 | Record.push_back(pch::TARGET_TRIPLE); |
| 1169 | const char *Triple = Target.getTargetTriple(); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1170 | Stream.EmitRecordWithBlob(TripleAbbrev, Record, Triple, strlen(Triple)); |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | /// \brief Write the LangOptions structure. |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1174 | void PCHWriter::WriteLanguageOptions(const LangOptions &LangOpts) { |
| 1175 | RecordData Record; |
| 1176 | Record.push_back(LangOpts.Trigraphs); |
| 1177 | Record.push_back(LangOpts.BCPLComment); // BCPL-style '//' comments. |
| 1178 | Record.push_back(LangOpts.DollarIdents); // '$' allowed in identifiers. |
| 1179 | Record.push_back(LangOpts.AsmPreprocessor); // Preprocessor in asm mode. |
| 1180 | Record.push_back(LangOpts.GNUMode); // True in gnu99 mode false in c99 mode (etc) |
| 1181 | Record.push_back(LangOpts.ImplicitInt); // C89 implicit 'int'. |
| 1182 | Record.push_back(LangOpts.Digraphs); // C94, C99 and C++ |
| 1183 | Record.push_back(LangOpts.HexFloats); // C99 Hexadecimal float constants. |
| 1184 | Record.push_back(LangOpts.C99); // C99 Support |
| 1185 | Record.push_back(LangOpts.Microsoft); // Microsoft extensions. |
| 1186 | Record.push_back(LangOpts.CPlusPlus); // C++ Support |
| 1187 | Record.push_back(LangOpts.CPlusPlus0x); // C++0x Support |
| 1188 | Record.push_back(LangOpts.NoExtensions); // All extensions are disabled, strict mode. |
| 1189 | Record.push_back(LangOpts.CXXOperatorNames); // Treat C++ operator names as keywords. |
| 1190 | |
| 1191 | Record.push_back(LangOpts.ObjC1); // Objective-C 1 support enabled. |
| 1192 | Record.push_back(LangOpts.ObjC2); // Objective-C 2 support enabled. |
| 1193 | Record.push_back(LangOpts.ObjCNonFragileABI); // Objective-C modern abi enabled |
| 1194 | |
| 1195 | Record.push_back(LangOpts.PascalStrings); // Allow Pascal strings |
| 1196 | Record.push_back(LangOpts.Boolean); // Allow bool/true/false |
| 1197 | Record.push_back(LangOpts.WritableStrings); // Allow writable strings |
| 1198 | Record.push_back(LangOpts.LaxVectorConversions); |
| 1199 | Record.push_back(LangOpts.Exceptions); // Support exception handling. |
| 1200 | |
| 1201 | Record.push_back(LangOpts.NeXTRuntime); // Use NeXT runtime. |
| 1202 | Record.push_back(LangOpts.Freestanding); // Freestanding implementation |
| 1203 | Record.push_back(LangOpts.NoBuiltin); // Do not use builtin functions (-fno-builtin) |
| 1204 | |
| 1205 | Record.push_back(LangOpts.ThreadsafeStatics); // Whether static initializers are protected |
| 1206 | // by locks. |
| 1207 | Record.push_back(LangOpts.Blocks); // block extension to C |
| 1208 | Record.push_back(LangOpts.EmitAllDecls); // Emit all declarations, even if |
| 1209 | // they are unused. |
| 1210 | Record.push_back(LangOpts.MathErrno); // Math functions must respect errno |
| 1211 | // (modulo the platform support). |
| 1212 | |
| 1213 | Record.push_back(LangOpts.OverflowChecking); // Extension to call a handler function when |
| 1214 | // signed integer arithmetic overflows. |
| 1215 | |
| 1216 | Record.push_back(LangOpts.HeinousExtensions); // Extensions that we really don't like and |
| 1217 | // may be ripped out at any time. |
| 1218 | |
| 1219 | Record.push_back(LangOpts.Optimize); // Whether __OPTIMIZE__ should be defined. |
| 1220 | Record.push_back(LangOpts.OptimizeSize); // Whether __OPTIMIZE_SIZE__ should be |
| 1221 | // defined. |
| 1222 | Record.push_back(LangOpts.Static); // Should __STATIC__ be defined (as |
| 1223 | // opposed to __DYNAMIC__). |
| 1224 | Record.push_back(LangOpts.PICLevel); // The value for __PIC__, if non-zero. |
| 1225 | |
| 1226 | Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be |
| 1227 | // used (instead of C99 semantics). |
| 1228 | Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined. |
| 1229 | Record.push_back(LangOpts.getGCMode()); |
| 1230 | Record.push_back(LangOpts.getVisibilityMode()); |
| 1231 | Record.push_back(LangOpts.InstantiationDepth); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1232 | Stream.EmitRecord(pch::LANGUAGE_OPTIONS, Record); |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1235 | //===----------------------------------------------------------------------===// |
| 1236 | // Source Manager Serialization |
| 1237 | //===----------------------------------------------------------------------===// |
| 1238 | |
| 1239 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1240 | /// file. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1241 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1242 | using namespace llvm; |
| 1243 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1244 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_FILE_ENTRY)); |
| 1245 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1246 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1247 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1248 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1249 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1250 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1254 | /// buffer. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1255 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1256 | using namespace llvm; |
| 1257 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1258 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_BUFFER_ENTRY)); |
| 1259 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1260 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1261 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1262 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1263 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1264 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1268 | /// buffer's blob. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1269 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1270 | using namespace llvm; |
| 1271 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1272 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_BUFFER_BLOB)); |
| 1273 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1274 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | /// \brief Create an abbreviation for the SLocEntry that refers to an |
| 1278 | /// buffer. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1279 | static unsigned CreateSLocInstantiationAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1280 | using namespace llvm; |
| 1281 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1282 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_INSTANTIATION_ENTRY)); |
| 1283 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1284 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1285 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1286 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 364e580 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1287 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1288 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /// \brief Writes the block containing the serialized form of the |
| 1292 | /// source manager. |
| 1293 | /// |
| 1294 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1295 | /// blob), indexed based on the file name, so that we only create |
| 1296 | /// entries for files that we actually need. In the common case (no |
| 1297 | /// errors), we probably won't have to create file entries for any of |
| 1298 | /// the files in the AST. |
Douglas Gregor | f6e1fb2 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1299 | void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
| 1300 | const Preprocessor &PP) { |
Chris Lattner | 84b04f1 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1301 | // Enter the source manager block. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1302 | Stream.EnterSubblock(pch::SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1303 | |
| 1304 | // Abbreviations for the various kinds of source-location entries. |
| 1305 | int SLocFileAbbrv = -1; |
| 1306 | int SLocBufferAbbrv = -1; |
| 1307 | int SLocBufferBlobAbbrv = -1; |
| 1308 | int SLocInstantiationAbbrv = -1; |
| 1309 | |
| 1310 | // Write out the source location entry table. We skip the first |
| 1311 | // entry, which is always the same dummy entry. |
| 1312 | RecordData Record; |
| 1313 | for (SourceManager::sloc_entry_iterator |
| 1314 | SLoc = SourceMgr.sloc_entry_begin() + 1, |
| 1315 | SLocEnd = SourceMgr.sloc_entry_end(); |
| 1316 | SLoc != SLocEnd; ++SLoc) { |
| 1317 | // Figure out which record code to use. |
| 1318 | unsigned Code; |
| 1319 | if (SLoc->isFile()) { |
| 1320 | if (SLoc->getFile().getContentCache()->Entry) |
| 1321 | Code = pch::SM_SLOC_FILE_ENTRY; |
| 1322 | else |
| 1323 | Code = pch::SM_SLOC_BUFFER_ENTRY; |
| 1324 | } else |
| 1325 | Code = pch::SM_SLOC_INSTANTIATION_ENTRY; |
| 1326 | Record.push_back(Code); |
| 1327 | |
| 1328 | Record.push_back(SLoc->getOffset()); |
| 1329 | if (SLoc->isFile()) { |
| 1330 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1331 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1332 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1333 | Record.push_back(File.hasLineDirectives()); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1334 | |
| 1335 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
| 1336 | if (Content->Entry) { |
| 1337 | // The source location entry is a file. The blob associated |
| 1338 | // with this entry is the file name. |
| 1339 | if (SLocFileAbbrv == -1) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1340 | SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1341 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1342 | Content->Entry->getName(), |
| 1343 | strlen(Content->Entry->getName())); |
| 1344 | } else { |
| 1345 | // The source location entry is a buffer. The blob associated |
| 1346 | // with this entry contains the contents of the buffer. |
| 1347 | if (SLocBufferAbbrv == -1) { |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1348 | SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1349 | SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | // We add one to the size so that we capture the trailing NULL |
| 1353 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1354 | // the reader side). |
| 1355 | const llvm::MemoryBuffer *Buffer = Content->getBuffer(); |
| 1356 | const char *Name = Buffer->getBufferIdentifier(); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1357 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, Name, strlen(Name) + 1); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1358 | Record.clear(); |
| 1359 | Record.push_back(pch::SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1360 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1361 | Buffer->getBufferStart(), |
| 1362 | Buffer->getBufferSize() + 1); |
| 1363 | } |
| 1364 | } else { |
| 1365 | // The source location entry is an instantiation. |
| 1366 | const SrcMgr::InstantiationInfo &Inst = SLoc->getInstantiation(); |
| 1367 | Record.push_back(Inst.getSpellingLoc().getRawEncoding()); |
| 1368 | Record.push_back(Inst.getInstantiationLocStart().getRawEncoding()); |
| 1369 | Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding()); |
| 1370 | |
Douglas Gregor | 364e580 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1371 | // Compute the token length for this macro expansion. |
| 1372 | unsigned NextOffset = SourceMgr.getNextOffset(); |
| 1373 | SourceManager::sloc_entry_iterator NextSLoc = SLoc; |
| 1374 | if (++NextSLoc != SLocEnd) |
| 1375 | NextOffset = NextSLoc->getOffset(); |
| 1376 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
| 1377 | |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1378 | if (SLocInstantiationAbbrv == -1) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1379 | SLocInstantiationAbbrv = CreateSLocInstantiationAbbrev(Stream); |
| 1380 | Stream.EmitRecordWithAbbrev(SLocInstantiationAbbrv, Record); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | Record.clear(); |
| 1384 | } |
| 1385 | |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1386 | // Write the line table. |
| 1387 | if (SourceMgr.hasLineTable()) { |
| 1388 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1389 | |
| 1390 | // Emit the file names |
| 1391 | Record.push_back(LineTable.getNumFilenames()); |
| 1392 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1393 | // Emit the file name |
| 1394 | const char *Filename = LineTable.getFilename(I); |
| 1395 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1396 | Record.push_back(FilenameLen); |
| 1397 | if (FilenameLen) |
| 1398 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1399 | } |
| 1400 | |
| 1401 | // Emit the line entries |
| 1402 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1403 | L != LEnd; ++L) { |
| 1404 | // Emit the file ID |
| 1405 | Record.push_back(L->first); |
| 1406 | |
| 1407 | // Emit the line entries |
| 1408 | Record.push_back(L->second.size()); |
| 1409 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1410 | LEEnd = L->second.end(); |
| 1411 | LE != LEEnd; ++LE) { |
| 1412 | Record.push_back(LE->FileOffset); |
| 1413 | Record.push_back(LE->LineNo); |
| 1414 | Record.push_back(LE->FilenameID); |
| 1415 | Record.push_back((unsigned)LE->FileKind); |
| 1416 | Record.push_back(LE->IncludeOffset); |
| 1417 | } |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1418 | Stream.EmitRecord(pch::SM_LINE_TABLE, Record); |
Douglas Gregor | 635f97f | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | |
Douglas Gregor | f6e1fb2 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1422 | // Loop over all the header files. |
| 1423 | HeaderSearch &HS = PP.getHeaderSearchInfo(); |
| 1424 | for (HeaderSearch::header_file_iterator I = HS.header_file_begin(), |
| 1425 | E = HS.header_file_end(); |
| 1426 | I != E; ++I) { |
| 1427 | Record.push_back(I->isImport); |
| 1428 | Record.push_back(I->DirInfo); |
| 1429 | Record.push_back(I->NumIncludes); |
| 1430 | if (I->ControllingMacro) |
| 1431 | AddIdentifierRef(I->ControllingMacro, Record); |
| 1432 | else |
| 1433 | Record.push_back(0); |
| 1434 | Stream.EmitRecord(pch::SM_HEADER_FILE_INFO, Record); |
| 1435 | Record.clear(); |
| 1436 | } |
| 1437 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1438 | Stream.ExitBlock(); |
Douglas Gregor | ab1cef7 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Chris Lattner | ffc05ed | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1441 | /// \brief Writes the block containing the serialized form of the |
| 1442 | /// preprocessor. |
| 1443 | /// |
Chris Lattner | 850eabd | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1444 | void PCHWriter::WritePreprocessor(const Preprocessor &PP) { |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1445 | RecordData Record; |
Chris Lattner | 84b04f1 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1446 | |
Chris Lattner | 4b21c20 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1447 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1448 | if (PP.getCounterValue() != 0) { |
| 1449 | Record.push_back(PP.getCounterValue()); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1450 | Stream.EmitRecord(pch::PP_COUNTER_VALUE, Record); |
Chris Lattner | 4b21c20 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1451 | Record.clear(); |
Douglas Gregor | f6e1fb2 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | // Enter the preprocessor block. |
| 1455 | Stream.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 2); |
Chris Lattner | 4b21c20 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1456 | |
Douglas Gregor | f6e1fb2 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1457 | // If the PCH file contains __DATE__ or __TIME__ emit a warning about this. |
| 1458 | // FIXME: use diagnostics subsystem for localization etc. |
| 1459 | if (PP.SawDateOrTime()) |
| 1460 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
| 1461 | |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1462 | // Loop over all the macro definitions that are live at the end of the file, |
| 1463 | // emitting each to the PP section. |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1464 | for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end(); |
| 1465 | I != E; ++I) { |
Chris Lattner | db1c81b | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1466 | // FIXME: This emits macros in hash table order, we should do it in a stable |
| 1467 | // order so that output is reproducible. |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1468 | MacroInfo *MI = I->second; |
| 1469 | |
| 1470 | // Don't emit builtin macros like __LINE__ to the PCH file unless they have |
| 1471 | // been redefined by the header (in which case they are not isBuiltinMacro). |
| 1472 | if (MI->isBuiltinMacro()) |
| 1473 | continue; |
| 1474 | |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1475 | // FIXME: Remove this identifier reference? |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1476 | AddIdentifierRef(I->first, Record); |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1477 | MacroOffsets[I->first] = Stream.GetCurrentBitNo(); |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1478 | Record.push_back(MI->getDefinitionLoc().getRawEncoding()); |
| 1479 | Record.push_back(MI->isUsed()); |
| 1480 | |
| 1481 | unsigned Code; |
| 1482 | if (MI->isObjectLike()) { |
| 1483 | Code = pch::PP_MACRO_OBJECT_LIKE; |
| 1484 | } else { |
| 1485 | Code = pch::PP_MACRO_FUNCTION_LIKE; |
| 1486 | |
| 1487 | Record.push_back(MI->isC99Varargs()); |
| 1488 | Record.push_back(MI->isGNUVarargs()); |
| 1489 | Record.push_back(MI->getNumArgs()); |
| 1490 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1491 | I != E; ++I) |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1492 | AddIdentifierRef(*I, Record); |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1493 | } |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1494 | Stream.EmitRecord(Code, Record); |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1495 | Record.clear(); |
| 1496 | |
Chris Lattner | 850eabd | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1497 | // Emit the tokens array. |
| 1498 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1499 | // Note that we know that the preprocessor does not have any annotation |
| 1500 | // tokens in it because they are created by the parser, and thus can't be |
| 1501 | // in a macro definition. |
| 1502 | const Token &Tok = MI->getReplacementToken(TokNo); |
| 1503 | |
| 1504 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1505 | Record.push_back(Tok.getLength()); |
| 1506 | |
Chris Lattner | 850eabd | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1507 | // FIXME: When reading literal tokens, reconstruct the literal pointer if |
| 1508 | // it is needed. |
Chris Lattner | 2924186 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1509 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
Chris Lattner | 850eabd | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1510 | |
| 1511 | // FIXME: Should translate token kind to a stable encoding. |
| 1512 | Record.push_back(Tok.getKind()); |
| 1513 | // FIXME: Should translate token flags to a stable encoding. |
| 1514 | Record.push_back(Tok.getFlags()); |
| 1515 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1516 | Stream.EmitRecord(pch::PP_TOKEN, Record); |
Chris Lattner | 850eabd | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1517 | Record.clear(); |
| 1518 | } |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1519 | ++NumMacros; |
Chris Lattner | 1b09495 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1520 | } |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1521 | Stream.ExitBlock(); |
Chris Lattner | ffc05ed | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1525 | /// \brief Write the representation of a type to the PCH stream. |
| 1526 | void PCHWriter::WriteType(const Type *T) { |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1527 | pch::TypeID &ID = TypeIDs[T]; |
Chris Lattner | 84b04f1 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1528 | if (ID == 0) // we haven't seen this type before. |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1529 | ID = NextTypeID++; |
| 1530 | |
| 1531 | // Record the offset for this type. |
| 1532 | if (TypeOffsets.size() == ID - pch::NUM_PREDEF_TYPE_IDS) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1533 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1534 | else if (TypeOffsets.size() < ID - pch::NUM_PREDEF_TYPE_IDS) { |
| 1535 | TypeOffsets.resize(ID + 1 - pch::NUM_PREDEF_TYPE_IDS); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1536 | TypeOffsets[ID - pch::NUM_PREDEF_TYPE_IDS] = Stream.GetCurrentBitNo(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | RecordData Record; |
| 1540 | |
| 1541 | // Emit the type's representation. |
| 1542 | PCHTypeWriter W(*this, Record); |
| 1543 | switch (T->getTypeClass()) { |
| 1544 | // For all of the concrete, non-dependent types, call the |
| 1545 | // appropriate visitor function. |
| 1546 | #define TYPE(Class, Base) \ |
| 1547 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
| 1548 | #define ABSTRACT_TYPE(Class, Base) |
| 1549 | #define DEPENDENT_TYPE(Class, Base) |
| 1550 | #include "clang/AST/TypeNodes.def" |
| 1551 | |
| 1552 | // For all of the dependent type nodes (which only occur in C++ |
| 1553 | // templates), produce an error. |
| 1554 | #define TYPE(Class, Base) |
| 1555 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 1556 | #include "clang/AST/TypeNodes.def" |
| 1557 | assert(false && "Cannot serialize dependent type nodes"); |
| 1558 | break; |
| 1559 | } |
| 1560 | |
| 1561 | // Emit the serialized record. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1562 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1563 | |
| 1564 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1565 | FlushStmts(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | /// \brief Write a block containing all of the types. |
| 1569 | void PCHWriter::WriteTypesBlock(ASTContext &Context) { |
Chris Lattner | 84b04f1 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1570 | // Enter the types block. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1571 | Stream.EnterSubblock(pch::TYPES_BLOCK_ID, 2); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1572 | |
Douglas Gregor | e43f097 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 1573 | // Emit all of the types that need to be emitted (so far). |
| 1574 | while (!TypesToEmit.empty()) { |
| 1575 | const Type *T = TypesToEmit.front(); |
| 1576 | TypesToEmit.pop(); |
| 1577 | assert(!isa<BuiltinType>(T) && "Built-in types are not serialized"); |
| 1578 | WriteType(T); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | // Exit the types block |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1582 | Stream.ExitBlock(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | /// \brief Write the block containing all of the declaration IDs |
| 1586 | /// lexically declared within the given DeclContext. |
| 1587 | /// |
| 1588 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 1589 | /// bistream, or 0 if no block was written. |
| 1590 | uint64_t PCHWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
| 1591 | DeclContext *DC) { |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1592 | if (DC->decls_empty(Context)) |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1593 | return 0; |
| 1594 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1595 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1596 | RecordData Record; |
| 1597 | for (DeclContext::decl_iterator D = DC->decls_begin(Context), |
| 1598 | DEnd = DC->decls_end(Context); |
| 1599 | D != DEnd; ++D) |
| 1600 | AddDeclRef(*D, Record); |
| 1601 | |
Douglas Gregor | af136d9 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1602 | ++NumLexicalDeclContexts; |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1603 | Stream.EmitRecord(pch::DECL_CONTEXT_LEXICAL, Record); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1604 | return Offset; |
| 1605 | } |
| 1606 | |
| 1607 | /// \brief Write the block containing all of the declaration IDs |
| 1608 | /// visible from the given DeclContext. |
| 1609 | /// |
| 1610 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
| 1611 | /// bistream, or 0 if no block was written. |
| 1612 | uint64_t PCHWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 1613 | DeclContext *DC) { |
| 1614 | if (DC->getPrimaryContext() != DC) |
| 1615 | return 0; |
| 1616 | |
Douglas Gregor | 35ca85e | 2009-04-21 22:32:33 +0000 | [diff] [blame] | 1617 | // Since there is no name lookup into functions or methods, and we |
| 1618 | // perform name lookup for the translation unit via the |
| 1619 | // IdentifierInfo chains, don't bother to build a |
| 1620 | // visible-declarations table for these entities. |
| 1621 | if (DC->isFunctionOrMethod() || DC->isTranslationUnit()) |
Douglas Gregor | 5afd980 | 2009-04-18 15:49:20 +0000 | [diff] [blame] | 1622 | return 0; |
| 1623 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1624 | // Force the DeclContext to build a its name-lookup table. |
| 1625 | DC->lookup(Context, DeclarationName()); |
| 1626 | |
| 1627 | // Serialize the contents of the mapping used for lookup. Note that, |
| 1628 | // although we have two very different code paths, the serialized |
| 1629 | // representation is the same for both cases: a declaration name, |
| 1630 | // followed by a size, followed by references to the visible |
| 1631 | // declarations that have that name. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1632 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1633 | RecordData Record; |
| 1634 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
Douglas Gregor | 982365e | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 1635 | if (!Map) |
| 1636 | return 0; |
| 1637 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1638 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 1639 | D != DEnd; ++D) { |
| 1640 | AddDeclarationName(D->first, Record); |
| 1641 | DeclContext::lookup_result Result = D->second.getLookupResult(Context); |
| 1642 | Record.push_back(Result.second - Result.first); |
| 1643 | for(; Result.first != Result.second; ++Result.first) |
| 1644 | AddDeclRef(*Result.first, Record); |
| 1645 | } |
| 1646 | |
| 1647 | if (Record.size() == 0) |
| 1648 | return 0; |
| 1649 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1650 | Stream.EmitRecord(pch::DECL_CONTEXT_VISIBLE, Record); |
Douglas Gregor | af136d9 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1651 | ++NumVisibleDeclContexts; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1652 | return Offset; |
| 1653 | } |
| 1654 | |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1655 | namespace { |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1656 | // Trait used for the on-disk hash table used in the method pool. |
| 1657 | class VISIBILITY_HIDDEN PCHMethodPoolTrait { |
| 1658 | PCHWriter &Writer; |
| 1659 | |
| 1660 | public: |
| 1661 | typedef Selector key_type; |
| 1662 | typedef key_type key_type_ref; |
| 1663 | |
| 1664 | typedef std::pair<ObjCMethodList, ObjCMethodList> data_type; |
| 1665 | typedef const data_type& data_type_ref; |
| 1666 | |
| 1667 | explicit PCHMethodPoolTrait(PCHWriter &Writer) : Writer(Writer) { } |
| 1668 | |
| 1669 | static unsigned ComputeHash(Selector Sel) { |
| 1670 | unsigned N = Sel.getNumArgs(); |
| 1671 | if (N == 0) |
| 1672 | ++N; |
| 1673 | unsigned R = 5381; |
| 1674 | for (unsigned I = 0; I != N; ++I) |
| 1675 | if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I)) |
| 1676 | R = clang::BernsteinHashPartial(II->getName(), II->getLength(), R); |
| 1677 | return R; |
| 1678 | } |
| 1679 | |
| 1680 | std::pair<unsigned,unsigned> |
| 1681 | EmitKeyDataLength(llvm::raw_ostream& Out, Selector Sel, |
| 1682 | data_type_ref Methods) { |
| 1683 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 1684 | clang::io::Emit16(Out, KeyLen); |
| 1685 | unsigned DataLen = 2 + 2; // 2 bytes for each of the method counts |
| 1686 | for (const ObjCMethodList *Method = &Methods.first; Method; |
| 1687 | Method = Method->Next) |
| 1688 | if (Method->Method) |
| 1689 | DataLen += 4; |
| 1690 | for (const ObjCMethodList *Method = &Methods.second; Method; |
| 1691 | Method = Method->Next) |
| 1692 | if (Method->Method) |
| 1693 | DataLen += 4; |
| 1694 | clang::io::Emit16(Out, DataLen); |
| 1695 | return std::make_pair(KeyLen, DataLen); |
| 1696 | } |
| 1697 | |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1698 | void EmitKey(llvm::raw_ostream& Out, Selector Sel, unsigned) { |
| 1699 | uint64_t Start = Out.tell(); |
| 1700 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 1701 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1702 | unsigned N = Sel.getNumArgs(); |
| 1703 | clang::io::Emit16(Out, N); |
| 1704 | if (N == 0) |
| 1705 | N = 1; |
| 1706 | for (unsigned I = 0; I != N; ++I) |
| 1707 | clang::io::Emit32(Out, |
| 1708 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 1709 | } |
| 1710 | |
| 1711 | void EmitData(llvm::raw_ostream& Out, key_type_ref, |
Douglas Gregor | 9c26698 | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1712 | data_type_ref Methods, unsigned DataLen) { |
| 1713 | uint64_t Start = Out.tell(); (void)Start; |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1714 | unsigned NumInstanceMethods = 0; |
| 1715 | for (const ObjCMethodList *Method = &Methods.first; Method; |
| 1716 | Method = Method->Next) |
| 1717 | if (Method->Method) |
| 1718 | ++NumInstanceMethods; |
| 1719 | |
| 1720 | unsigned NumFactoryMethods = 0; |
| 1721 | for (const ObjCMethodList *Method = &Methods.second; Method; |
| 1722 | Method = Method->Next) |
| 1723 | if (Method->Method) |
| 1724 | ++NumFactoryMethods; |
| 1725 | |
| 1726 | clang::io::Emit16(Out, NumInstanceMethods); |
| 1727 | clang::io::Emit16(Out, NumFactoryMethods); |
| 1728 | for (const ObjCMethodList *Method = &Methods.first; Method; |
| 1729 | Method = Method->Next) |
| 1730 | if (Method->Method) |
| 1731 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1732 | for (const ObjCMethodList *Method = &Methods.second; Method; |
| 1733 | Method = Method->Next) |
| 1734 | if (Method->Method) |
| 1735 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | 9c26698 | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1736 | |
| 1737 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1738 | } |
| 1739 | }; |
| 1740 | } // end anonymous namespace |
| 1741 | |
| 1742 | /// \brief Write the method pool into the PCH file. |
| 1743 | /// |
| 1744 | /// The method pool contains both instance and factory methods, stored |
| 1745 | /// in an on-disk hash table indexed by the selector. |
| 1746 | void PCHWriter::WriteMethodPool(Sema &SemaRef) { |
| 1747 | using namespace llvm; |
| 1748 | |
| 1749 | // Create and write out the blob that contains the instance and |
| 1750 | // factor method pools. |
| 1751 | bool Empty = true; |
| 1752 | { |
| 1753 | OnDiskChainedHashTableGenerator<PCHMethodPoolTrait> Generator; |
| 1754 | |
| 1755 | // Create the on-disk hash table representation. Start by |
| 1756 | // iterating through the instance method pool. |
| 1757 | PCHMethodPoolTrait::key_type Key; |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1758 | unsigned NumSelectorsInMethodPool = 0; |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1759 | for (llvm::DenseMap<Selector, ObjCMethodList>::iterator |
| 1760 | Instance = SemaRef.InstanceMethodPool.begin(), |
| 1761 | InstanceEnd = SemaRef.InstanceMethodPool.end(); |
| 1762 | Instance != InstanceEnd; ++Instance) { |
| 1763 | // Check whether there is a factory method with the same |
| 1764 | // selector. |
| 1765 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Factory |
| 1766 | = SemaRef.FactoryMethodPool.find(Instance->first); |
| 1767 | |
| 1768 | if (Factory == SemaRef.FactoryMethodPool.end()) |
| 1769 | Generator.insert(Instance->first, |
| 1770 | std::make_pair(Instance->second, |
| 1771 | ObjCMethodList())); |
| 1772 | else |
| 1773 | Generator.insert(Instance->first, |
| 1774 | std::make_pair(Instance->second, Factory->second)); |
| 1775 | |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1776 | ++NumSelectorsInMethodPool; |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1777 | Empty = false; |
| 1778 | } |
| 1779 | |
| 1780 | // Now iterate through the factory method pool, to pick up any |
| 1781 | // selectors that weren't already in the instance method pool. |
| 1782 | for (llvm::DenseMap<Selector, ObjCMethodList>::iterator |
| 1783 | Factory = SemaRef.FactoryMethodPool.begin(), |
| 1784 | FactoryEnd = SemaRef.FactoryMethodPool.end(); |
| 1785 | Factory != FactoryEnd; ++Factory) { |
| 1786 | // Check whether there is an instance method with the same |
| 1787 | // selector. If so, there is no work to do here. |
| 1788 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Instance |
| 1789 | = SemaRef.InstanceMethodPool.find(Factory->first); |
| 1790 | |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1791 | if (Instance == SemaRef.InstanceMethodPool.end()) { |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1792 | Generator.insert(Factory->first, |
| 1793 | std::make_pair(ObjCMethodList(), Factory->second)); |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1794 | ++NumSelectorsInMethodPool; |
| 1795 | } |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1796 | |
| 1797 | Empty = false; |
| 1798 | } |
| 1799 | |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1800 | if (Empty && SelectorOffsets.empty()) |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1801 | return; |
| 1802 | |
| 1803 | // Create the on-disk hash table in a buffer. |
| 1804 | llvm::SmallVector<char, 4096> MethodPool; |
| 1805 | uint32_t BucketOffset; |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1806 | SelectorOffsets.resize(SelVector.size()); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1807 | { |
| 1808 | PCHMethodPoolTrait Trait(*this); |
| 1809 | llvm::raw_svector_ostream Out(MethodPool); |
| 1810 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | 9c26698 | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1811 | clang::io::Emit32(Out, 0); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1812 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1813 | |
| 1814 | // For every selector that we have seen but which was not |
| 1815 | // written into the hash table, write the selector itself and |
| 1816 | // record it's offset. |
| 1817 | for (unsigned I = 0, N = SelVector.size(); I != N; ++I) |
| 1818 | if (SelectorOffsets[I] == 0) |
| 1819 | Trait.EmitKey(Out, SelVector[I], 0); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | // Create a blob abbreviation |
| 1823 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1824 | Abbrev->Add(BitCodeAbbrevOp(pch::METHOD_POOL)); |
| 1825 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1826 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1827 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1828 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1829 | |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1830 | // Write the method pool |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1831 | RecordData Record; |
| 1832 | Record.push_back(pch::METHOD_POOL); |
| 1833 | Record.push_back(BucketOffset); |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1834 | Record.push_back(NumSelectorsInMethodPool); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1835 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, |
| 1836 | &MethodPool.front(), |
| 1837 | MethodPool.size()); |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1838 | |
| 1839 | // Create a blob abbreviation for the selector table offsets. |
| 1840 | Abbrev = new BitCodeAbbrev(); |
| 1841 | Abbrev->Add(BitCodeAbbrevOp(pch::SELECTOR_OFFSETS)); |
| 1842 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index |
| 1843 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1844 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1845 | |
| 1846 | // Write the selector offsets table. |
| 1847 | Record.clear(); |
| 1848 | Record.push_back(pch::SELECTOR_OFFSETS); |
| 1849 | Record.push_back(SelectorOffsets.size()); |
| 1850 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 1851 | (const char *)&SelectorOffsets.front(), |
| 1852 | SelectorOffsets.size() * 4); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | namespace { |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1857 | class VISIBILITY_HIDDEN PCHIdentifierTableTrait { |
| 1858 | PCHWriter &Writer; |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1859 | Preprocessor &PP; |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1860 | |
| 1861 | public: |
| 1862 | typedef const IdentifierInfo* key_type; |
| 1863 | typedef key_type key_type_ref; |
| 1864 | |
| 1865 | typedef pch::IdentID data_type; |
| 1866 | typedef data_type data_type_ref; |
| 1867 | |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1868 | PCHIdentifierTableTrait(PCHWriter &Writer, Preprocessor &PP) |
| 1869 | : Writer(Writer), PP(PP) { } |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1870 | |
| 1871 | static unsigned ComputeHash(const IdentifierInfo* II) { |
| 1872 | return clang::BernsteinHash(II->getName()); |
| 1873 | } |
| 1874 | |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1875 | std::pair<unsigned,unsigned> |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1876 | EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II, |
| 1877 | pch::IdentID ID) { |
| 1878 | unsigned KeyLen = strlen(II->getName()) + 1; |
Douglas Gregor | c713da9 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1879 | unsigned DataLen = 4 + 4; // 4 bytes for token ID, builtin, flags |
| 1880 | // 4 bytes for the persistent ID |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1881 | if (II->hasMacroDefinition() && |
| 1882 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro()) |
| 1883 | DataLen += 8; |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1884 | for (IdentifierResolver::iterator D = IdentifierResolver::begin(II), |
| 1885 | DEnd = IdentifierResolver::end(); |
| 1886 | D != DEnd; ++D) |
| 1887 | DataLen += sizeof(pch::DeclID); |
Douglas Gregor | 85c4a87 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 1888 | // We emit the key length after the data length so that the |
| 1889 | // "uninteresting" identifiers following the identifier hash table |
| 1890 | // structure will have the same (key length, key characters) |
| 1891 | // layout as the keys in the hash table. This also matches the |
| 1892 | // format for identifiers in pretokenized headers. |
Douglas Gregor | c713da9 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1893 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 85c4a87 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 1894 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1895 | return std::make_pair(KeyLen, DataLen); |
| 1896 | } |
| 1897 | |
| 1898 | void EmitKey(llvm::raw_ostream& Out, const IdentifierInfo* II, |
| 1899 | unsigned KeyLen) { |
| 1900 | // Record the location of the key data. This is used when generating |
| 1901 | // the mapping from persistent IDs to strings. |
| 1902 | Writer.SetIdentifierOffset(II, Out.tell()); |
| 1903 | Out.write(II->getName(), KeyLen); |
| 1904 | } |
| 1905 | |
| 1906 | void EmitData(llvm::raw_ostream& Out, const IdentifierInfo* II, |
| 1907 | pch::IdentID ID, unsigned) { |
| 1908 | uint32_t Bits = 0; |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1909 | bool hasMacroDefinition = |
| 1910 | II->hasMacroDefinition() && |
| 1911 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro(); |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1912 | Bits = Bits | (uint32_t)II->getTokenID(); |
Douglas Gregor | da38c6c | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 1913 | Bits = (Bits << 10) | (uint32_t)II->getObjCOrBuiltinID(); |
| 1914 | Bits = (Bits << 1) | hasMacroDefinition; |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1915 | Bits = (Bits << 1) | II->isExtensionToken(); |
| 1916 | Bits = (Bits << 1) | II->isPoisoned(); |
| 1917 | Bits = (Bits << 1) | II->isCPlusPlusOperatorKeyword(); |
| 1918 | clang::io::Emit32(Out, Bits); |
| 1919 | clang::io::Emit32(Out, ID); |
| 1920 | |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1921 | if (hasMacroDefinition) |
| 1922 | clang::io::Emit64(Out, Writer.getMacroOffset(II)); |
| 1923 | |
Douglas Gregor | c713da9 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1924 | // Emit the declaration IDs in reverse order, because the |
| 1925 | // IdentifierResolver provides the declarations as they would be |
| 1926 | // visible (e.g., the function "stat" would come before the struct |
| 1927 | // "stat"), but IdentifierResolver::AddDeclToIdentifierChain() |
| 1928 | // adds declarations to the end of the list (so we need to see the |
| 1929 | // struct "status" before the function "status"). |
| 1930 | llvm::SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II), |
| 1931 | IdentifierResolver::end()); |
| 1932 | for (llvm::SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
| 1933 | DEnd = Decls.rend(); |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1934 | D != DEnd; ++D) |
Douglas Gregor | c713da9 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1935 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1936 | } |
| 1937 | }; |
| 1938 | } // end anonymous namespace |
| 1939 | |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1940 | /// \brief Write the identifier table into the PCH file. |
| 1941 | /// |
| 1942 | /// The identifier table consists of a blob containing string data |
| 1943 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 1944 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1945 | void PCHWriter::WriteIdentifierTable(Preprocessor &PP) { |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1946 | using namespace llvm; |
| 1947 | |
| 1948 | // Create and write out the blob that contains the identifier |
| 1949 | // strings. |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1950 | IdentifierOffsets.resize(IdentifierIDs.size()); |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1951 | { |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1952 | OnDiskChainedHashTableGenerator<PCHIdentifierTableTrait> Generator; |
| 1953 | |
Douglas Gregor | 85c4a87 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 1954 | llvm::SmallVector<const IdentifierInfo *, 32> UninterestingIdentifiers; |
| 1955 | |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1956 | // Create the on-disk hash table representation. |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1957 | for (llvm::DenseMap<const IdentifierInfo *, pch::IdentID>::iterator |
| 1958 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 1959 | ID != IDEnd; ++ID) { |
| 1960 | assert(ID->first && "NULL identifier in identifier table"); |
Douglas Gregor | 85c4a87 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 1961 | |
| 1962 | // Classify each identifier as either "interesting" or "not |
| 1963 | // interesting". Interesting identifiers are those that have |
| 1964 | // additional information that needs to be read from the PCH |
| 1965 | // file, e.g., a built-in ID, declaration chain, or macro |
| 1966 | // definition. These identifiers are placed into the hash table |
| 1967 | // so that they can be found when looked up in the user program. |
| 1968 | // All other identifiers are "uninteresting", which means that |
| 1969 | // the IdentifierInfo built by default has all of the |
| 1970 | // information we care about. Such identifiers are placed after |
| 1971 | // the hash table. |
| 1972 | const IdentifierInfo *II = ID->first; |
| 1973 | if (II->isPoisoned() || |
| 1974 | II->isExtensionToken() || |
| 1975 | II->hasMacroDefinition() || |
| 1976 | II->getObjCOrBuiltinID() || |
| 1977 | II->getFETokenInfo<void>()) |
| 1978 | Generator.insert(ID->first, ID->second); |
| 1979 | else |
| 1980 | UninterestingIdentifiers.push_back(II); |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1981 | } |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1982 | |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1983 | // Create the on-disk hash table in a buffer. |
| 1984 | llvm::SmallVector<char, 4096> IdentifierTable; |
Douglas Gregor | c713da9 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1985 | uint32_t BucketOffset; |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1986 | { |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1987 | PCHIdentifierTableTrait Trait(*this, PP); |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1988 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1989 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | 9c26698 | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1990 | clang::io::Emit32(Out, 0); |
Douglas Gregor | c713da9 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1991 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 85c4a87 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 1992 | |
| 1993 | for (unsigned I = 0, N = UninterestingIdentifiers.size(); I != N; ++I) { |
| 1994 | const IdentifierInfo *II = UninterestingIdentifiers[I]; |
| 1995 | unsigned N = II->getLength() + 1; |
| 1996 | clang::io::Emit16(Out, N); |
| 1997 | SetIdentifierOffset(II, Out.tell()); |
| 1998 | Out.write(II->getName(), N); |
| 1999 | } |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | // Create a blob abbreviation |
| 2003 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2004 | Abbrev->Add(BitCodeAbbrevOp(pch::IDENTIFIER_TABLE)); |
Douglas Gregor | c713da9 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2005 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2006 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2007 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2008 | |
| 2009 | // Write the identifier table |
| 2010 | RecordData Record; |
| 2011 | Record.push_back(pch::IDENTIFIER_TABLE); |
Douglas Gregor | c713da9 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2012 | Record.push_back(BucketOffset); |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2013 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, |
| 2014 | &IdentifierTable.front(), |
| 2015 | IdentifierTable.size()); |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | // Write the offsets table for identifier IDs. |
Douglas Gregor | de44c9f | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2019 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2020 | Abbrev->Add(BitCodeAbbrevOp(pch::IDENTIFIER_OFFSET)); |
| 2021 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
| 2022 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2023 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2024 | |
| 2025 | RecordData Record; |
| 2026 | Record.push_back(pch::IDENTIFIER_OFFSET); |
| 2027 | Record.push_back(IdentifierOffsets.size()); |
| 2028 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
| 2029 | (const char *)&IdentifierOffsets.front(), |
| 2030 | IdentifierOffsets.size() * sizeof(uint32_t)); |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
Douglas Gregor | 1c50788 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2033 | /// \brief Write a record containing the given attributes. |
| 2034 | void PCHWriter::WriteAttributeRecord(const Attr *Attr) { |
| 2035 | RecordData Record; |
| 2036 | for (; Attr; Attr = Attr->getNext()) { |
| 2037 | Record.push_back(Attr->getKind()); // FIXME: stable encoding |
| 2038 | Record.push_back(Attr->isInherited()); |
| 2039 | switch (Attr->getKind()) { |
| 2040 | case Attr::Alias: |
| 2041 | AddString(cast<AliasAttr>(Attr)->getAliasee(), Record); |
| 2042 | break; |
| 2043 | |
| 2044 | case Attr::Aligned: |
| 2045 | Record.push_back(cast<AlignedAttr>(Attr)->getAlignment()); |
| 2046 | break; |
| 2047 | |
| 2048 | case Attr::AlwaysInline: |
| 2049 | break; |
| 2050 | |
| 2051 | case Attr::AnalyzerNoReturn: |
| 2052 | break; |
| 2053 | |
| 2054 | case Attr::Annotate: |
| 2055 | AddString(cast<AnnotateAttr>(Attr)->getAnnotation(), Record); |
| 2056 | break; |
| 2057 | |
| 2058 | case Attr::AsmLabel: |
| 2059 | AddString(cast<AsmLabelAttr>(Attr)->getLabel(), Record); |
| 2060 | break; |
| 2061 | |
| 2062 | case Attr::Blocks: |
| 2063 | Record.push_back(cast<BlocksAttr>(Attr)->getType()); // FIXME: stable |
| 2064 | break; |
| 2065 | |
| 2066 | case Attr::Cleanup: |
| 2067 | AddDeclRef(cast<CleanupAttr>(Attr)->getFunctionDecl(), Record); |
| 2068 | break; |
| 2069 | |
| 2070 | case Attr::Const: |
| 2071 | break; |
| 2072 | |
| 2073 | case Attr::Constructor: |
| 2074 | Record.push_back(cast<ConstructorAttr>(Attr)->getPriority()); |
| 2075 | break; |
| 2076 | |
| 2077 | case Attr::DLLExport: |
| 2078 | case Attr::DLLImport: |
| 2079 | case Attr::Deprecated: |
| 2080 | break; |
| 2081 | |
| 2082 | case Attr::Destructor: |
| 2083 | Record.push_back(cast<DestructorAttr>(Attr)->getPriority()); |
| 2084 | break; |
| 2085 | |
| 2086 | case Attr::FastCall: |
| 2087 | break; |
| 2088 | |
| 2089 | case Attr::Format: { |
| 2090 | const FormatAttr *Format = cast<FormatAttr>(Attr); |
| 2091 | AddString(Format->getType(), Record); |
| 2092 | Record.push_back(Format->getFormatIdx()); |
| 2093 | Record.push_back(Format->getFirstArg()); |
| 2094 | break; |
| 2095 | } |
| 2096 | |
Chris Lattner | 15ce6cc | 2009-04-20 19:12:28 +0000 | [diff] [blame] | 2097 | case Attr::GNUInline: |
Douglas Gregor | 1c50788 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2098 | case Attr::IBOutletKind: |
| 2099 | case Attr::NoReturn: |
| 2100 | case Attr::NoThrow: |
| 2101 | case Attr::Nodebug: |
| 2102 | case Attr::Noinline: |
| 2103 | break; |
| 2104 | |
| 2105 | case Attr::NonNull: { |
| 2106 | const NonNullAttr *NonNull = cast<NonNullAttr>(Attr); |
| 2107 | Record.push_back(NonNull->size()); |
| 2108 | Record.insert(Record.end(), NonNull->begin(), NonNull->end()); |
| 2109 | break; |
| 2110 | } |
| 2111 | |
| 2112 | case Attr::ObjCException: |
| 2113 | case Attr::ObjCNSObject: |
Ted Kremenek | b98860c | 2009-04-25 00:17:17 +0000 | [diff] [blame] | 2114 | case Attr::ObjCOwnershipRetain: |
Ted Kremenek | aa6e318 | 2009-04-24 23:09:54 +0000 | [diff] [blame] | 2115 | case Attr::ObjCOwnershipReturns: |
Douglas Gregor | 1c50788 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2116 | case Attr::Overloadable: |
| 2117 | break; |
| 2118 | |
| 2119 | case Attr::Packed: |
| 2120 | Record.push_back(cast<PackedAttr>(Attr)->getAlignment()); |
| 2121 | break; |
| 2122 | |
| 2123 | case Attr::Pure: |
| 2124 | break; |
| 2125 | |
| 2126 | case Attr::Regparm: |
| 2127 | Record.push_back(cast<RegparmAttr>(Attr)->getNumParams()); |
| 2128 | break; |
| 2129 | |
| 2130 | case Attr::Section: |
| 2131 | AddString(cast<SectionAttr>(Attr)->getName(), Record); |
| 2132 | break; |
| 2133 | |
| 2134 | case Attr::StdCall: |
| 2135 | case Attr::TransparentUnion: |
| 2136 | case Attr::Unavailable: |
| 2137 | case Attr::Unused: |
| 2138 | case Attr::Used: |
| 2139 | break; |
| 2140 | |
| 2141 | case Attr::Visibility: |
| 2142 | // FIXME: stable encoding |
| 2143 | Record.push_back(cast<VisibilityAttr>(Attr)->getVisibility()); |
| 2144 | break; |
| 2145 | |
| 2146 | case Attr::WarnUnusedResult: |
| 2147 | case Attr::Weak: |
| 2148 | case Attr::WeakImport: |
| 2149 | break; |
| 2150 | } |
| 2151 | } |
| 2152 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2153 | Stream.EmitRecord(pch::DECL_ATTR, Record); |
Douglas Gregor | 1c50788 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | void PCHWriter::AddString(const std::string &Str, RecordData &Record) { |
| 2157 | Record.push_back(Str.size()); |
| 2158 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 2159 | } |
| 2160 | |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2161 | /// \brief Note that the identifier II occurs at the given offset |
| 2162 | /// within the identifier table. |
| 2163 | void PCHWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Douglas Gregor | de44c9f | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2164 | IdentifierOffsets[IdentifierIDs[II] - 1] = Offset; |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
Douglas Gregor | 2d71183 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2167 | /// \brief Note that the selector Sel occurs at the given offset |
| 2168 | /// within the method pool/selector table. |
| 2169 | void PCHWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
| 2170 | unsigned ID = SelectorIDs[Sel]; |
| 2171 | assert(ID && "Unknown selector"); |
| 2172 | SelectorOffsets[ID - 1] = Offset; |
| 2173 | } |
| 2174 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2175 | PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2176 | : Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS), |
Douglas Gregor | af136d9 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2177 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
| 2178 | NumVisibleDeclContexts(0) { } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2179 | |
Douglas Gregor | 87887da | 2009-04-20 15:53:59 +0000 | [diff] [blame] | 2180 | void PCHWriter::WritePCH(Sema &SemaRef) { |
Douglas Gregor | 24a224c | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2181 | using namespace llvm; |
| 2182 | |
Douglas Gregor | 87887da | 2009-04-20 15:53:59 +0000 | [diff] [blame] | 2183 | ASTContext &Context = SemaRef.Context; |
| 2184 | Preprocessor &PP = SemaRef.PP; |
| 2185 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2186 | // Emit the file header. |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2187 | Stream.Emit((unsigned)'C', 8); |
| 2188 | Stream.Emit((unsigned)'P', 8); |
| 2189 | Stream.Emit((unsigned)'C', 8); |
| 2190 | Stream.Emit((unsigned)'H', 8); |
Chris Lattner | 920673a | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 2191 | |
| 2192 | WriteBlockInfoBlock(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2193 | |
| 2194 | // The translation unit is the first declaration we'll emit. |
| 2195 | DeclIDs[Context.getTranslationUnitDecl()] = 1; |
| 2196 | DeclsToEmit.push(Context.getTranslationUnitDecl()); |
| 2197 | |
Douglas Gregor | da38c6c | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2198 | // Make sure that we emit IdentifierInfos (and any attached |
| 2199 | // declarations) for builtins. |
| 2200 | { |
| 2201 | IdentifierTable &Table = PP.getIdentifierTable(); |
| 2202 | llvm::SmallVector<const char *, 32> BuiltinNames; |
| 2203 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
| 2204 | Context.getLangOptions().NoBuiltin); |
| 2205 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 2206 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 2207 | } |
| 2208 | |
Douglas Gregor | 77b2cd5 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2209 | // Build a record containing all of the tentative definitions in |
| 2210 | // this header file. Generally, this record will be empty. |
| 2211 | RecordData TentativeDefinitions; |
| 2212 | for (llvm::DenseMap<DeclarationName, VarDecl *>::iterator |
| 2213 | TD = SemaRef.TentativeDefinitions.begin(), |
| 2214 | TDEnd = SemaRef.TentativeDefinitions.end(); |
| 2215 | TD != TDEnd; ++TD) |
| 2216 | AddDeclRef(TD->second, TentativeDefinitions); |
| 2217 | |
Douglas Gregor | 062d948 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2218 | // Build a record containing all of the locally-scoped external |
| 2219 | // declarations in this header file. Generally, this record will be |
| 2220 | // empty. |
| 2221 | RecordData LocallyScopedExternalDecls; |
| 2222 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
| 2223 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 2224 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
| 2225 | TD != TDEnd; ++TD) |
| 2226 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 2227 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2228 | // Write the remaining PCH contents. |
Douglas Gregor | e01ad44 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2229 | RecordData Record; |
Douglas Gregor | 24a224c | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2230 | Stream.EnterSubblock(pch::PCH_BLOCK_ID, 4); |
Douglas Gregor | b5887f3 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2231 | WriteTargetTriple(Context.Target); |
Douglas Gregor | 179cfb1 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2232 | WriteLanguageOptions(Context.getLangOptions()); |
Douglas Gregor | f6e1fb2 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2233 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Chris Lattner | ffc05ed | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2234 | WritePreprocessor(PP); |
Douglas Gregor | e43f097 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2235 | |
| 2236 | // Keep writing types and declarations until all types and |
| 2237 | // declarations have been written. |
| 2238 | do { |
| 2239 | if (!DeclsToEmit.empty()) |
| 2240 | WriteDeclsBlock(Context); |
| 2241 | if (!TypesToEmit.empty()) |
| 2242 | WriteTypesBlock(Context); |
| 2243 | } while (!(DeclsToEmit.empty() && TypesToEmit.empty())); |
| 2244 | |
Douglas Gregor | c3221aa | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2245 | WriteMethodPool(SemaRef); |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2246 | WriteIdentifierTable(PP); |
Douglas Gregor | 24a224c | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2247 | |
| 2248 | // Write the type offsets array |
| 2249 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2250 | Abbrev->Add(BitCodeAbbrevOp(pch::TYPE_OFFSET)); |
| 2251 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
| 2252 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2253 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2254 | Record.clear(); |
| 2255 | Record.push_back(pch::TYPE_OFFSET); |
| 2256 | Record.push_back(TypeOffsets.size()); |
| 2257 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, |
| 2258 | (const char *)&TypeOffsets.front(), |
| 2259 | TypeOffsets.size() * sizeof(uint64_t)); |
| 2260 | |
| 2261 | // Write the declaration offsets array |
| 2262 | Abbrev = new BitCodeAbbrev(); |
| 2263 | Abbrev->Add(BitCodeAbbrevOp(pch::DECL_OFFSET)); |
| 2264 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
| 2265 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2266 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2267 | Record.clear(); |
| 2268 | Record.push_back(pch::DECL_OFFSET); |
| 2269 | Record.push_back(DeclOffsets.size()); |
| 2270 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, |
| 2271 | (const char *)&DeclOffsets.front(), |
| 2272 | DeclOffsets.size() * sizeof(uint64_t)); |
Douglas Gregor | e01ad44 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2273 | |
| 2274 | // Write the record of special types. |
| 2275 | Record.clear(); |
| 2276 | AddTypeRef(Context.getBuiltinVaListType(), Record); |
Douglas Gregor | bb21d4b | 2009-04-23 22:29:11 +0000 | [diff] [blame] | 2277 | AddTypeRef(Context.getObjCIdType(), Record); |
| 2278 | AddTypeRef(Context.getObjCSelType(), Record); |
| 2279 | AddTypeRef(Context.getObjCProtoType(), Record); |
| 2280 | AddTypeRef(Context.getObjCClassType(), Record); |
| 2281 | AddTypeRef(Context.getRawCFConstantStringType(), Record); |
| 2282 | AddTypeRef(Context.getRawObjCFastEnumerationStateType(), Record); |
Douglas Gregor | e01ad44 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2283 | Stream.EmitRecord(pch::SPECIAL_TYPES, Record); |
| 2284 | |
Douglas Gregor | 77b2cd5 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2285 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | 631f6c6 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2286 | if (!ExternalDefinitions.empty()) |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2287 | Stream.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 77b2cd5 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2288 | |
| 2289 | // Write the record containing tentative definitions. |
| 2290 | if (!TentativeDefinitions.empty()) |
| 2291 | Stream.EmitRecord(pch::TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 062d948 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2292 | |
| 2293 | // Write the record containing locally-scoped external definitions. |
| 2294 | if (!LocallyScopedExternalDecls.empty()) |
| 2295 | Stream.EmitRecord(pch::LOCALLY_SCOPED_EXTERNAL_DECLS, |
| 2296 | LocallyScopedExternalDecls); |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2297 | |
| 2298 | // Some simple statistics |
Douglas Gregor | e01ad44 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2299 | Record.clear(); |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2300 | Record.push_back(NumStatements); |
Douglas Gregor | e0ad2dd | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2301 | Record.push_back(NumMacros); |
Douglas Gregor | af136d9 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2302 | Record.push_back(NumLexicalDeclContexts); |
| 2303 | Record.push_back(NumVisibleDeclContexts); |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2304 | Stream.EmitRecord(pch::STATISTICS, Record); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2305 | Stream.ExitBlock(); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | void PCHWriter::AddSourceLocation(SourceLocation Loc, RecordData &Record) { |
| 2309 | Record.push_back(Loc.getRawEncoding()); |
| 2310 | } |
| 2311 | |
| 2312 | void PCHWriter::AddAPInt(const llvm::APInt &Value, RecordData &Record) { |
| 2313 | Record.push_back(Value.getBitWidth()); |
| 2314 | unsigned N = Value.getNumWords(); |
| 2315 | const uint64_t* Words = Value.getRawData(); |
| 2316 | for (unsigned I = 0; I != N; ++I) |
| 2317 | Record.push_back(Words[I]); |
| 2318 | } |
| 2319 | |
Douglas Gregor | 47f1b2c | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2320 | void PCHWriter::AddAPSInt(const llvm::APSInt &Value, RecordData &Record) { |
| 2321 | Record.push_back(Value.isUnsigned()); |
| 2322 | AddAPInt(Value, Record); |
| 2323 | } |
| 2324 | |
Douglas Gregor | e2f3720 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2325 | void PCHWriter::AddAPFloat(const llvm::APFloat &Value, RecordData &Record) { |
| 2326 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 2327 | } |
| 2328 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2329 | void PCHWriter::AddIdentifierRef(const IdentifierInfo *II, RecordData &Record) { |
Douglas Gregor | da38c6c | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2330 | Record.push_back(getIdentifierRef(II)); |
| 2331 | } |
| 2332 | |
| 2333 | pch::IdentID PCHWriter::getIdentifierRef(const IdentifierInfo *II) { |
| 2334 | if (II == 0) |
| 2335 | return 0; |
Douglas Gregor | 7a224cf | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2336 | |
| 2337 | pch::IdentID &ID = IdentifierIDs[II]; |
| 2338 | if (ID == 0) |
| 2339 | ID = IdentifierIDs.size(); |
Douglas Gregor | da38c6c | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2340 | return ID; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
Steve Naroff | 9e84d78 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2343 | void PCHWriter::AddSelectorRef(const Selector SelRef, RecordData &Record) { |
| 2344 | if (SelRef.getAsOpaquePtr() == 0) { |
| 2345 | Record.push_back(0); |
| 2346 | return; |
| 2347 | } |
| 2348 | |
| 2349 | pch::SelectorID &SID = SelectorIDs[SelRef]; |
| 2350 | if (SID == 0) { |
| 2351 | SID = SelectorIDs.size(); |
| 2352 | SelVector.push_back(SelRef); |
| 2353 | } |
| 2354 | Record.push_back(SID); |
| 2355 | } |
| 2356 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2357 | void PCHWriter::AddTypeRef(QualType T, RecordData &Record) { |
| 2358 | if (T.isNull()) { |
| 2359 | Record.push_back(pch::PREDEF_TYPE_NULL_ID); |
| 2360 | return; |
| 2361 | } |
| 2362 | |
| 2363 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr())) { |
Douglas Gregor | b3a04c8 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2364 | pch::TypeID ID = 0; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2365 | switch (BT->getKind()) { |
| 2366 | case BuiltinType::Void: ID = pch::PREDEF_TYPE_VOID_ID; break; |
| 2367 | case BuiltinType::Bool: ID = pch::PREDEF_TYPE_BOOL_ID; break; |
| 2368 | case BuiltinType::Char_U: ID = pch::PREDEF_TYPE_CHAR_U_ID; break; |
| 2369 | case BuiltinType::UChar: ID = pch::PREDEF_TYPE_UCHAR_ID; break; |
| 2370 | case BuiltinType::UShort: ID = pch::PREDEF_TYPE_USHORT_ID; break; |
| 2371 | case BuiltinType::UInt: ID = pch::PREDEF_TYPE_UINT_ID; break; |
| 2372 | case BuiltinType::ULong: ID = pch::PREDEF_TYPE_ULONG_ID; break; |
| 2373 | case BuiltinType::ULongLong: ID = pch::PREDEF_TYPE_ULONGLONG_ID; break; |
| 2374 | case BuiltinType::Char_S: ID = pch::PREDEF_TYPE_CHAR_S_ID; break; |
| 2375 | case BuiltinType::SChar: ID = pch::PREDEF_TYPE_SCHAR_ID; break; |
| 2376 | case BuiltinType::WChar: ID = pch::PREDEF_TYPE_WCHAR_ID; break; |
| 2377 | case BuiltinType::Short: ID = pch::PREDEF_TYPE_SHORT_ID; break; |
| 2378 | case BuiltinType::Int: ID = pch::PREDEF_TYPE_INT_ID; break; |
| 2379 | case BuiltinType::Long: ID = pch::PREDEF_TYPE_LONG_ID; break; |
| 2380 | case BuiltinType::LongLong: ID = pch::PREDEF_TYPE_LONGLONG_ID; break; |
| 2381 | case BuiltinType::Float: ID = pch::PREDEF_TYPE_FLOAT_ID; break; |
| 2382 | case BuiltinType::Double: ID = pch::PREDEF_TYPE_DOUBLE_ID; break; |
| 2383 | case BuiltinType::LongDouble: ID = pch::PREDEF_TYPE_LONGDOUBLE_ID; break; |
| 2384 | case BuiltinType::Overload: ID = pch::PREDEF_TYPE_OVERLOAD_ID; break; |
| 2385 | case BuiltinType::Dependent: ID = pch::PREDEF_TYPE_DEPENDENT_ID; break; |
| 2386 | } |
| 2387 | |
| 2388 | Record.push_back((ID << 3) | T.getCVRQualifiers()); |
| 2389 | return; |
| 2390 | } |
| 2391 | |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2392 | pch::TypeID &ID = TypeIDs[T.getTypePtr()]; |
Douglas Gregor | e43f097 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2393 | if (ID == 0) { |
| 2394 | // We haven't seen this type before. Assign it a new ID and put it |
| 2395 | // into the queu of types to emit. |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2396 | ID = NextTypeID++; |
Douglas Gregor | e43f097 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2397 | TypesToEmit.push(T.getTypePtr()); |
| 2398 | } |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2399 | |
| 2400 | // Encode the type qualifiers in the type reference. |
| 2401 | Record.push_back((ID << 3) | T.getCVRQualifiers()); |
| 2402 | } |
| 2403 | |
| 2404 | void PCHWriter::AddDeclRef(const Decl *D, RecordData &Record) { |
| 2405 | if (D == 0) { |
| 2406 | Record.push_back(0); |
| 2407 | return; |
| 2408 | } |
| 2409 | |
Douglas Gregor | ac8f280 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2410 | pch::DeclID &ID = DeclIDs[D]; |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2411 | if (ID == 0) { |
| 2412 | // We haven't seen this declaration before. Give it a new ID and |
| 2413 | // enqueue it in the list of declarations to emit. |
| 2414 | ID = DeclIDs.size(); |
| 2415 | DeclsToEmit.push(const_cast<Decl *>(D)); |
| 2416 | } |
| 2417 | |
| 2418 | Record.push_back(ID); |
| 2419 | } |
| 2420 | |
Douglas Gregor | ff9a609 | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2421 | pch::DeclID PCHWriter::getDeclID(const Decl *D) { |
| 2422 | if (D == 0) |
| 2423 | return 0; |
| 2424 | |
| 2425 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 2426 | return DeclIDs[D]; |
| 2427 | } |
| 2428 | |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2429 | void PCHWriter::AddDeclarationName(DeclarationName Name, RecordData &Record) { |
| 2430 | Record.push_back(Name.getNameKind()); |
| 2431 | switch (Name.getNameKind()) { |
| 2432 | case DeclarationName::Identifier: |
| 2433 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 2434 | break; |
| 2435 | |
| 2436 | case DeclarationName::ObjCZeroArgSelector: |
| 2437 | case DeclarationName::ObjCOneArgSelector: |
| 2438 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 9e84d78 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2439 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | c34897d | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2440 | break; |
| 2441 | |
| 2442 | case DeclarationName::CXXConstructorName: |
| 2443 | case DeclarationName::CXXDestructorName: |
| 2444 | case DeclarationName::CXXConversionFunctionName: |
| 2445 | AddTypeRef(Name.getCXXNameType(), Record); |
| 2446 | break; |
| 2447 | |
| 2448 | case DeclarationName::CXXOperatorName: |
| 2449 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 2450 | break; |
| 2451 | |
| 2452 | case DeclarationName::CXXUsingDirective: |
| 2453 | // No extra data to emit |
| 2454 | break; |
| 2455 | } |
| 2456 | } |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2457 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2458 | /// \brief Write the given substatement or subexpression to the |
| 2459 | /// bitstream. |
| 2460 | void PCHWriter::WriteSubStmt(Stmt *S) { |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2461 | RecordData Record; |
| 2462 | PCHStmtWriter Writer(*this, Record); |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2463 | ++NumStatements; |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2464 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2465 | if (!S) { |
| 2466 | Stream.EmitRecord(pch::STMT_NULL_PTR, Record); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2467 | return; |
| 2468 | } |
| 2469 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2470 | Writer.Code = pch::STMT_NULL_PTR; |
| 2471 | Writer.Visit(S); |
| 2472 | assert(Writer.Code != pch::STMT_NULL_PTR && |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2473 | "Unhandled expression writing PCH file"); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2474 | Stream.EmitRecord(Writer.Code, Record); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2477 | /// \brief Flush all of the statements that have been added to the |
| 2478 | /// queue via AddStmt(). |
| 2479 | void PCHWriter::FlushStmts() { |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2480 | RecordData Record; |
| 2481 | PCHStmtWriter Writer(*this, Record); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2482 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2483 | for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) { |
Douglas Gregor | 456e095 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2484 | ++NumStatements; |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2485 | Stmt *S = StmtsToEmit[I]; |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2486 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2487 | if (!S) { |
| 2488 | Stream.EmitRecord(pch::STMT_NULL_PTR, Record); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2489 | continue; |
| 2490 | } |
| 2491 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2492 | Writer.Code = pch::STMT_NULL_PTR; |
| 2493 | Writer.Visit(S); |
| 2494 | assert(Writer.Code != pch::STMT_NULL_PTR && |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2495 | "Unhandled expression writing PCH file"); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2496 | Stream.EmitRecord(Writer.Code, Record); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2497 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2498 | assert(N == StmtsToEmit.size() && |
| 2499 | "Substatement writen via AddStmt rather than WriteSubStmt!"); |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2500 | |
| 2501 | // Note that we are at the end of a full expression. Any |
| 2502 | // expression records that follow this one are part of a different |
| 2503 | // expression. |
| 2504 | Record.clear(); |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2505 | Stream.EmitRecord(pch::STMT_STOP, Record); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2506 | } |
Douglas Gregor | a151ba4 | 2009-04-14 23:32:43 +0000 | [diff] [blame] | 2507 | |
Douglas Gregor | c72f6c8 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2508 | StmtsToEmit.clear(); |
Douglas Gregor | 22d2dcd | 2009-04-17 16:34:57 +0000 | [diff] [blame] | 2509 | SwitchCaseIDs.clear(); |
Douglas Gregor | c10f86f | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2510 | } |
Douglas Gregor | 9c4782a | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 2511 | |
| 2512 | unsigned PCHWriter::RecordSwitchCaseID(SwitchCase *S) { |
| 2513 | assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() && |
| 2514 | "SwitchCase recorded twice"); |
| 2515 | unsigned NextID = SwitchCaseIDs.size(); |
| 2516 | SwitchCaseIDs[S] = NextID; |
| 2517 | return NextID; |
| 2518 | } |
| 2519 | |
| 2520 | unsigned PCHWriter::getSwitchCaseID(SwitchCase *S) { |
| 2521 | assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() && |
| 2522 | "SwitchCase hasn't been seen yet"); |
| 2523 | return SwitchCaseIDs[S]; |
| 2524 | } |
Douglas Gregor | 6e411bf | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2525 | |
| 2526 | /// \brief Retrieve the ID for the given label statement, which may |
| 2527 | /// or may not have been emitted yet. |
| 2528 | unsigned PCHWriter::GetLabelID(LabelStmt *S) { |
| 2529 | std::map<LabelStmt *, unsigned>::iterator Pos = LabelIDs.find(S); |
| 2530 | if (Pos != LabelIDs.end()) |
| 2531 | return Pos->second; |
| 2532 | |
| 2533 | unsigned NextID = LabelIDs.size(); |
| 2534 | LabelIDs[S] = NextID; |
| 2535 | return NextID; |
| 2536 | } |