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