Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1 | //===--- PCHWriter.cpp - Precompiled Headers Writer -----------------------===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 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 | e778504 | 2009-04-20 15:53:59 +0000 | [diff] [blame] | 15 | #include "../Sema/Sema.h" // FIXME: move header into include/clang/Sema |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 16 | #include "../Sema/IdentifierResolver.h" // FIXME: move header |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/AST/Decl.h" |
| 19 | #include "clang/AST/DeclContextInternals.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 21 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 22 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 23 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 24 | #include "clang/Lex/PreprocessingRecord.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 25 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 26 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 27 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 28 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 29 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 30 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 31 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 32 | #include "clang/Basic/Version.h" |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/APFloat.h" |
| 34 | #include "llvm/ADT/APInt.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 36 | #include "llvm/Bitcode/BitstreamWriter.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 37 | #include "llvm/Support/MemoryBuffer.h" |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 38 | #include "llvm/System/Path.h" |
Chris Lattner | 3c304bd | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 39 | #include <cstdio> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 40 | using namespace clang; |
| 41 | |
| 42 | //===----------------------------------------------------------------------===// |
| 43 | // Type serialization |
| 44 | //===----------------------------------------------------------------------===// |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 45 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 46 | namespace { |
Benjamin Kramer | bd21828 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 47 | class PCHTypeWriter { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | PCHWriter &Writer; |
| 49 | PCHWriter::RecordData &Record; |
| 50 | |
| 51 | public: |
| 52 | /// \brief Type code that corresponds to the record generated. |
| 53 | pch::TypeCode Code; |
| 54 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | PCHTypeWriter(PCHWriter &Writer, PCHWriter::RecordData &Record) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 56 | : Writer(Writer), Record(Record), Code(pch::TYPE_EXT_QUAL) { } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 57 | |
| 58 | void VisitArrayType(const ArrayType *T); |
| 59 | void VisitFunctionType(const FunctionType *T); |
| 60 | void VisitTagType(const TagType *T); |
| 61 | |
| 62 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 63 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 64 | #include "clang/AST/TypeNodes.def" |
| 65 | }; |
| 66 | } |
| 67 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 68 | void PCHTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
| 69 | assert(false && "Built-in types are never serialized"); |
| 70 | } |
| 71 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 72 | void PCHTypeWriter::VisitComplexType(const ComplexType *T) { |
| 73 | Writer.AddTypeRef(T->getElementType(), Record); |
| 74 | Code = pch::TYPE_COMPLEX; |
| 75 | } |
| 76 | |
| 77 | void PCHTypeWriter::VisitPointerType(const PointerType *T) { |
| 78 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 79 | Code = pch::TYPE_POINTER; |
| 80 | } |
| 81 | |
| 82 | void PCHTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 83 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 84 | Code = pch::TYPE_BLOCK_POINTER; |
| 85 | } |
| 86 | |
| 87 | void PCHTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
| 88 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 89 | Code = pch::TYPE_LVALUE_REFERENCE; |
| 90 | } |
| 91 | |
| 92 | void PCHTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
| 93 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 94 | Code = pch::TYPE_RVALUE_REFERENCE; |
| 95 | } |
| 96 | |
| 97 | void PCHTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 99 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 100 | Code = pch::TYPE_MEMBER_POINTER; |
| 101 | } |
| 102 | |
| 103 | void PCHTypeWriter::VisitArrayType(const ArrayType *T) { |
| 104 | Writer.AddTypeRef(T->getElementType(), Record); |
| 105 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 106 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void PCHTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 110 | VisitArrayType(T); |
| 111 | Writer.AddAPInt(T->getSize(), Record); |
| 112 | Code = pch::TYPE_CONSTANT_ARRAY; |
| 113 | } |
| 114 | |
| 115 | void PCHTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
| 116 | VisitArrayType(T); |
| 117 | Code = pch::TYPE_INCOMPLETE_ARRAY; |
| 118 | } |
| 119 | |
| 120 | void PCHTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
| 121 | VisitArrayType(T); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 122 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 123 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 124 | Writer.AddStmt(T->getSizeExpr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 125 | Code = pch::TYPE_VARIABLE_ARRAY; |
| 126 | } |
| 127 | |
| 128 | void PCHTypeWriter::VisitVectorType(const VectorType *T) { |
| 129 | Writer.AddTypeRef(T->getElementType(), Record); |
| 130 | Record.push_back(T->getNumElements()); |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 131 | Record.push_back(T->getAltiVecSpecific()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 132 | Code = pch::TYPE_VECTOR; |
| 133 | } |
| 134 | |
| 135 | void PCHTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
| 136 | VisitVectorType(T); |
| 137 | Code = pch::TYPE_EXT_VECTOR; |
| 138 | } |
| 139 | |
| 140 | void PCHTypeWriter::VisitFunctionType(const FunctionType *T) { |
| 141 | Writer.AddTypeRef(T->getResultType(), Record); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 142 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 143 | Record.push_back(C.getNoReturn()); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 144 | Record.push_back(C.getRegParm()); |
Douglas Gregor | ab8bbf4 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 145 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 146 | Record.push_back(C.getCC()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void PCHTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
| 150 | VisitFunctionType(T); |
| 151 | Code = pch::TYPE_FUNCTION_NO_PROTO; |
| 152 | } |
| 153 | |
| 154 | void PCHTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 155 | VisitFunctionType(T); |
| 156 | Record.push_back(T->getNumArgs()); |
| 157 | for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) |
| 158 | Writer.AddTypeRef(T->getArgType(I), Record); |
| 159 | Record.push_back(T->isVariadic()); |
| 160 | Record.push_back(T->getTypeQuals()); |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 161 | Record.push_back(T->hasExceptionSpec()); |
| 162 | Record.push_back(T->hasAnyExceptionSpec()); |
| 163 | Record.push_back(T->getNumExceptions()); |
| 164 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 165 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 166 | Code = pch::TYPE_FUNCTION_PROTO; |
| 167 | } |
| 168 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 169 | void PCHTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
| 170 | Writer.AddDeclRef(T->getDecl(), Record); |
| 171 | Code = pch::TYPE_UNRESOLVED_USING; |
| 172 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 173 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 174 | void PCHTypeWriter::VisitTypedefType(const TypedefType *T) { |
| 175 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 176 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 177 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 178 | Code = pch::TYPE_TYPEDEF; |
| 179 | } |
| 180 | |
| 181 | void PCHTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 182 | Writer.AddStmt(T->getUnderlyingExpr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 183 | Code = pch::TYPE_TYPEOF_EXPR; |
| 184 | } |
| 185 | |
| 186 | void PCHTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
| 187 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 188 | Code = pch::TYPE_TYPEOF; |
| 189 | } |
| 190 | |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 191 | void PCHTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
| 192 | Writer.AddStmt(T->getUnderlyingExpr()); |
| 193 | Code = pch::TYPE_DECLTYPE; |
| 194 | } |
| 195 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 196 | void PCHTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 197 | Record.push_back(T->isDependentType()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 198 | Writer.AddDeclRef(T->getDecl(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | assert(!T->isBeingDefined() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 200 | "Cannot serialize in the middle of a type definition"); |
| 201 | } |
| 202 | |
| 203 | void PCHTypeWriter::VisitRecordType(const RecordType *T) { |
| 204 | VisitTagType(T); |
| 205 | Code = pch::TYPE_RECORD; |
| 206 | } |
| 207 | |
| 208 | void PCHTypeWriter::VisitEnumType(const EnumType *T) { |
| 209 | VisitTagType(T); |
| 210 | Code = pch::TYPE_ENUM; |
| 211 | } |
| 212 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | void |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 214 | PCHTypeWriter::VisitSubstTemplateTypeParmType( |
| 215 | const SubstTemplateTypeParmType *T) { |
| 216 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 217 | Writer.AddTypeRef(T->getReplacementType(), Record); |
| 218 | Code = pch::TYPE_SUBST_TEMPLATE_TYPE_PARM; |
| 219 | } |
| 220 | |
| 221 | void |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 222 | PCHTypeWriter::VisitTemplateSpecializationType( |
| 223 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 224 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 225 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 226 | Record.push_back(T->getNumArgs()); |
| 227 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 228 | ArgI != ArgE; ++ArgI) |
| 229 | Writer.AddTemplateArgument(*ArgI, Record); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 230 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 231 | : T->getCanonicalTypeInternal(), |
| 232 | Record); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 233 | Code = pch::TYPE_TEMPLATE_SPECIALIZATION; |
| 234 | } |
| 235 | |
| 236 | void |
| 237 | PCHTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 238 | VisitArrayType(T); |
| 239 | Writer.AddStmt(T->getSizeExpr()); |
| 240 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
| 241 | Code = pch::TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | void |
| 245 | PCHTypeWriter::VisitDependentSizedExtVectorType( |
| 246 | const DependentSizedExtVectorType *T) { |
| 247 | // FIXME: Serialize this type (C++ only) |
| 248 | assert(false && "Cannot serialize dependent sized extended vector types"); |
| 249 | } |
| 250 | |
| 251 | void |
| 252 | PCHTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
| 253 | Record.push_back(T->getDepth()); |
| 254 | Record.push_back(T->getIndex()); |
| 255 | Record.push_back(T->isParameterPack()); |
| 256 | Writer.AddIdentifierRef(T->getName(), Record); |
| 257 | Code = pch::TYPE_TEMPLATE_TYPE_PARM; |
| 258 | } |
| 259 | |
| 260 | void |
| 261 | PCHTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 262 | Record.push_back(T->getKeyword()); |
| 263 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 264 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 265 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 266 | : T->getCanonicalTypeInternal(), |
| 267 | Record); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 268 | Code = pch::TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void |
| 272 | PCHTypeWriter::VisitDependentTemplateSpecializationType( |
| 273 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 274 | Record.push_back(T->getKeyword()); |
| 275 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 276 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 277 | Record.push_back(T->getNumArgs()); |
| 278 | for (DependentTemplateSpecializationType::iterator |
| 279 | I = T->begin(), E = T->end(); I != E; ++I) |
| 280 | Writer.AddTemplateArgument(*I, Record); |
| 281 | Code = pch::TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 284 | void PCHTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 285 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 286 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 287 | Writer.AddTypeRef(T->getNamedType(), Record); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 288 | Code = pch::TYPE_ELABORATED; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 289 | } |
| 290 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 291 | void PCHTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
| 292 | Writer.AddDeclRef(T->getDecl(), Record); |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 293 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 294 | Code = pch::TYPE_INJECTED_CLASS_NAME; |
| 295 | } |
| 296 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 297 | void PCHTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 298 | Writer.AddDeclRef(T->getDecl(), Record); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 299 | Code = pch::TYPE_OBJC_INTERFACE; |
| 300 | } |
| 301 | |
| 302 | void PCHTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 303 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 304 | Record.push_back(T->getNumProtocols()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 305 | for (ObjCObjectType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 446ee4e | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 306 | E = T->qual_end(); I != E; ++I) |
| 307 | Writer.AddDeclRef(*I, Record); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 308 | Code = pch::TYPE_OBJC_OBJECT; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 311 | void |
| 312 | PCHTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 313 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 314 | Code = pch::TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 315 | } |
| 316 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 317 | namespace { |
| 318 | |
| 319 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
| 320 | PCHWriter &Writer; |
| 321 | PCHWriter::RecordData &Record; |
| 322 | |
| 323 | public: |
| 324 | TypeLocWriter(PCHWriter &Writer, PCHWriter::RecordData &Record) |
| 325 | : Writer(Writer), Record(Record) { } |
| 326 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 327 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 328 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 329 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 330 | #include "clang/AST/TypeLocNodes.def" |
| 331 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 332 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 333 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | } |
| 337 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 338 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 339 | // nothing to do |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 340 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 341 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 342 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 343 | if (TL.needsExtraLocalData()) { |
| 344 | Record.push_back(TL.getWrittenTypeSpec()); |
| 345 | Record.push_back(TL.getWrittenSignSpec()); |
| 346 | Record.push_back(TL.getWrittenWidthSpec()); |
| 347 | Record.push_back(TL.hasModeAttr()); |
| 348 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 349 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 350 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 351 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 352 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 353 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 354 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 355 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 356 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 357 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 358 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 359 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 360 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 361 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 362 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 363 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 364 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 365 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 366 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 367 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 368 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 369 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 370 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 371 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 372 | if (TL.getSizeExpr()) |
| 373 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 374 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 375 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 376 | VisitArrayTypeLoc(TL); |
| 377 | } |
| 378 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 379 | VisitArrayTypeLoc(TL); |
| 380 | } |
| 381 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 382 | VisitArrayTypeLoc(TL); |
| 383 | } |
| 384 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 385 | DependentSizedArrayTypeLoc TL) { |
| 386 | VisitArrayTypeLoc(TL); |
| 387 | } |
| 388 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 389 | DependentSizedExtVectorTypeLoc TL) { |
| 390 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 391 | } |
| 392 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 393 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 394 | } |
| 395 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 396 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 397 | } |
| 398 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
| 399 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 400 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 401 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 402 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 403 | } |
| 404 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 405 | VisitFunctionTypeLoc(TL); |
| 406 | } |
| 407 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 408 | VisitFunctionTypeLoc(TL); |
| 409 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 410 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 411 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 412 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 413 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 414 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 415 | } |
| 416 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 417 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 418 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 419 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 420 | } |
| 421 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 422 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 423 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 424 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 425 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 426 | } |
| 427 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 428 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 429 | } |
| 430 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 431 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 432 | } |
| 433 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 434 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 435 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 436 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 437 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 438 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 439 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 440 | SubstTemplateTypeParmTypeLoc TL) { |
| 441 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 442 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 443 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 444 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 445 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 446 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 447 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 448 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 449 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 450 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 451 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 452 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 453 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
| 454 | Writer.AddSourceRange(TL.getQualifierRange(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 455 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 456 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 457 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 458 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 459 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 460 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
| 461 | Writer.AddSourceRange(TL.getQualifierRange(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 462 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 463 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 464 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 465 | DependentTemplateSpecializationTypeLoc TL) { |
| 466 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
| 467 | Writer.AddSourceRange(TL.getQualifierRange(), Record); |
| 468 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 469 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 470 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 471 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 472 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 473 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 474 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 475 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 476 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 477 | } |
| 478 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 479 | Record.push_back(TL.hasBaseTypeAsWritten()); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 480 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 481 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 482 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 483 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 484 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 485 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 486 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 487 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 488 | |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 489 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 490 | // PCHWriter Implementation |
| 491 | //===----------------------------------------------------------------------===// |
| 492 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 493 | static void EmitBlockID(unsigned ID, const char *Name, |
| 494 | llvm::BitstreamWriter &Stream, |
| 495 | PCHWriter::RecordData &Record) { |
| 496 | Record.clear(); |
| 497 | Record.push_back(ID); |
| 498 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 499 | |
| 500 | // Emit the block name if present. |
| 501 | if (Name == 0 || Name[0] == 0) return; |
| 502 | Record.clear(); |
| 503 | while (*Name) |
| 504 | Record.push_back(*Name++); |
| 505 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 506 | } |
| 507 | |
| 508 | static void EmitRecordID(unsigned ID, const char *Name, |
| 509 | llvm::BitstreamWriter &Stream, |
| 510 | PCHWriter::RecordData &Record) { |
| 511 | Record.clear(); |
| 512 | Record.push_back(ID); |
| 513 | while (*Name) |
| 514 | Record.push_back(*Name++); |
| 515 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
| 519 | PCHWriter::RecordData &Record) { |
| 520 | #define RECORD(X) EmitRecordID(pch::X, #X, Stream, Record) |
| 521 | RECORD(STMT_STOP); |
| 522 | RECORD(STMT_NULL_PTR); |
| 523 | RECORD(STMT_NULL); |
| 524 | RECORD(STMT_COMPOUND); |
| 525 | RECORD(STMT_CASE); |
| 526 | RECORD(STMT_DEFAULT); |
| 527 | RECORD(STMT_LABEL); |
| 528 | RECORD(STMT_IF); |
| 529 | RECORD(STMT_SWITCH); |
| 530 | RECORD(STMT_WHILE); |
| 531 | RECORD(STMT_DO); |
| 532 | RECORD(STMT_FOR); |
| 533 | RECORD(STMT_GOTO); |
| 534 | RECORD(STMT_INDIRECT_GOTO); |
| 535 | RECORD(STMT_CONTINUE); |
| 536 | RECORD(STMT_BREAK); |
| 537 | RECORD(STMT_RETURN); |
| 538 | RECORD(STMT_DECL); |
| 539 | RECORD(STMT_ASM); |
| 540 | RECORD(EXPR_PREDEFINED); |
| 541 | RECORD(EXPR_DECL_REF); |
| 542 | RECORD(EXPR_INTEGER_LITERAL); |
| 543 | RECORD(EXPR_FLOATING_LITERAL); |
| 544 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 545 | RECORD(EXPR_STRING_LITERAL); |
| 546 | RECORD(EXPR_CHARACTER_LITERAL); |
| 547 | RECORD(EXPR_PAREN); |
| 548 | RECORD(EXPR_UNARY_OPERATOR); |
| 549 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 550 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 551 | RECORD(EXPR_CALL); |
| 552 | RECORD(EXPR_MEMBER); |
| 553 | RECORD(EXPR_BINARY_OPERATOR); |
| 554 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 555 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 556 | RECORD(EXPR_IMPLICIT_CAST); |
| 557 | RECORD(EXPR_CSTYLE_CAST); |
| 558 | RECORD(EXPR_COMPOUND_LITERAL); |
| 559 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 560 | RECORD(EXPR_INIT_LIST); |
| 561 | RECORD(EXPR_DESIGNATED_INIT); |
| 562 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 563 | RECORD(EXPR_VA_ARG); |
| 564 | RECORD(EXPR_ADDR_LABEL); |
| 565 | RECORD(EXPR_STMT); |
| 566 | RECORD(EXPR_TYPES_COMPATIBLE); |
| 567 | RECORD(EXPR_CHOOSE); |
| 568 | RECORD(EXPR_GNU_NULL); |
| 569 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 570 | RECORD(EXPR_BLOCK); |
| 571 | RECORD(EXPR_BLOCK_DECL_REF); |
| 572 | RECORD(EXPR_OBJC_STRING_LITERAL); |
| 573 | RECORD(EXPR_OBJC_ENCODE); |
| 574 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 575 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 576 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 577 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 578 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 579 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
| 580 | RECORD(EXPR_OBJC_SUPER_EXPR); |
| 581 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 582 | RECORD(STMT_OBJC_CATCH); |
| 583 | RECORD(STMT_OBJC_FINALLY); |
| 584 | RECORD(STMT_OBJC_AT_TRY); |
| 585 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 586 | RECORD(STMT_OBJC_AT_THROW); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 587 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 588 | RECORD(EXPR_CXX_CONSTRUCT); |
| 589 | RECORD(EXPR_CXX_STATIC_CAST); |
| 590 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 591 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 592 | RECORD(EXPR_CXX_CONST_CAST); |
| 593 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
| 594 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 595 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 596 | #undef RECORD |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 597 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 599 | void PCHWriter::WriteBlockInfoBlock() { |
| 600 | RecordData Record; |
| 601 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 602 | |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 603 | #define BLOCK(X) EmitBlockID(pch::X ## _ID, #X, Stream, Record) |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 604 | #define RECORD(X) EmitRecordID(pch::X, #X, Stream, Record) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 606 | // PCH Top-Level Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 607 | BLOCK(PCH_BLOCK); |
Zhongxing Xu | 51e774d | 2009-06-03 09:23:28 +0000 | [diff] [blame] | 608 | RECORD(ORIGINAL_FILE_NAME); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 609 | RECORD(TYPE_OFFSET); |
| 610 | RECORD(DECL_OFFSET); |
| 611 | RECORD(LANGUAGE_OPTIONS); |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 612 | RECORD(METADATA); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 613 | RECORD(IDENTIFIER_OFFSET); |
| 614 | RECORD(IDENTIFIER_TABLE); |
| 615 | RECORD(EXTERNAL_DEFINITIONS); |
| 616 | RECORD(SPECIAL_TYPES); |
| 617 | RECORD(STATISTICS); |
| 618 | RECORD(TENTATIVE_DEFINITIONS); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 619 | RECORD(UNUSED_STATIC_FUNCS); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 620 | RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); |
| 621 | RECORD(SELECTOR_OFFSETS); |
| 622 | RECORD(METHOD_POOL); |
| 623 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 624 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 625 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 626 | RECORD(STAT_CACHE); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 627 | RECORD(EXT_VECTOR_DECLS); |
Ted Kremenek | 5b4ec63 | 2010-01-22 20:59:36 +0000 | [diff] [blame] | 628 | RECORD(VERSION_CONTROL_BRANCH_REVISION); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 629 | RECORD(UNUSED_STATIC_FUNCS); |
| 630 | RECORD(MACRO_DEFINITION_OFFSETS); |
Sebastian Redl | a93e3b5 | 2010-07-08 22:01:51 +0000 | [diff] [blame^] | 631 | RECORD(CHAINED_METADATA); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 632 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 633 | // SourceManager Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 634 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 635 | RECORD(SM_SLOC_FILE_ENTRY); |
| 636 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 637 | RECORD(SM_SLOC_BUFFER_BLOB); |
| 638 | RECORD(SM_SLOC_INSTANTIATION_ENTRY); |
| 639 | RECORD(SM_LINE_TABLE); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 640 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 641 | // Preprocessor Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 642 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 643 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 644 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 645 | RECORD(PP_TOKEN); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 646 | RECORD(PP_MACRO_INSTANTIATION); |
| 647 | RECORD(PP_MACRO_DEFINITION); |
| 648 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 649 | // Decls and Types block. |
| 650 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 651 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 652 | RECORD(TYPE_COMPLEX); |
| 653 | RECORD(TYPE_POINTER); |
| 654 | RECORD(TYPE_BLOCK_POINTER); |
| 655 | RECORD(TYPE_LVALUE_REFERENCE); |
| 656 | RECORD(TYPE_RVALUE_REFERENCE); |
| 657 | RECORD(TYPE_MEMBER_POINTER); |
| 658 | RECORD(TYPE_CONSTANT_ARRAY); |
| 659 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 660 | RECORD(TYPE_VARIABLE_ARRAY); |
| 661 | RECORD(TYPE_VECTOR); |
| 662 | RECORD(TYPE_EXT_VECTOR); |
| 663 | RECORD(TYPE_FUNCTION_PROTO); |
| 664 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 665 | RECORD(TYPE_TYPEDEF); |
| 666 | RECORD(TYPE_TYPEOF_EXPR); |
| 667 | RECORD(TYPE_TYPEOF); |
| 668 | RECORD(TYPE_RECORD); |
| 669 | RECORD(TYPE_ENUM); |
| 670 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | a53d2cb | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 671 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 672 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 673 | RECORD(DECL_ATTR); |
| 674 | RECORD(DECL_TRANSLATION_UNIT); |
| 675 | RECORD(DECL_TYPEDEF); |
| 676 | RECORD(DECL_ENUM); |
| 677 | RECORD(DECL_RECORD); |
| 678 | RECORD(DECL_ENUM_CONSTANT); |
| 679 | RECORD(DECL_FUNCTION); |
| 680 | RECORD(DECL_OBJC_METHOD); |
| 681 | RECORD(DECL_OBJC_INTERFACE); |
| 682 | RECORD(DECL_OBJC_PROTOCOL); |
| 683 | RECORD(DECL_OBJC_IVAR); |
| 684 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
| 685 | RECORD(DECL_OBJC_CLASS); |
| 686 | RECORD(DECL_OBJC_FORWARD_PROTOCOL); |
| 687 | RECORD(DECL_OBJC_CATEGORY); |
| 688 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 689 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 690 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 691 | RECORD(DECL_OBJC_PROPERTY); |
| 692 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 693 | RECORD(DECL_FIELD); |
| 694 | RECORD(DECL_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 695 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 696 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 697 | RECORD(DECL_FILE_SCOPE_ASM); |
| 698 | RECORD(DECL_BLOCK); |
| 699 | RECORD(DECL_CONTEXT_LEXICAL); |
| 700 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 701 | // Statements and Exprs can occur in the Decls and Types block. |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 702 | AddStmtsExprs(Stream, Record); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 703 | #undef RECORD |
| 704 | #undef BLOCK |
| 705 | Stream.ExitBlock(); |
| 706 | } |
| 707 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 708 | /// \brief Adjusts the given filename to only write out the portion of the |
| 709 | /// filename that is not part of the system root directory. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | /// |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 711 | /// \param Filename the file name to adjust. |
| 712 | /// |
| 713 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 714 | /// the returned filename will be adjusted by this system root. |
| 715 | /// |
| 716 | /// \returns either the original filename (if it needs no adjustment) or the |
| 717 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | static const char * |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 719 | adjustFilenameForRelocatablePCH(const char *Filename, const char *isysroot) { |
| 720 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 721 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 722 | if (!isysroot) |
| 723 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 725 | // Verify that the filename and the system root have the same prefix. |
| 726 | unsigned Pos = 0; |
| 727 | for (; Filename[Pos] && isysroot[Pos]; ++Pos) |
| 728 | if (Filename[Pos] != isysroot[Pos]) |
| 729 | return Filename; // Prefixes don't match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 731 | // We hit the end of the filename before we hit the end of the system root. |
| 732 | if (!Filename[Pos]) |
| 733 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 735 | // If the file name has a '/' at the current position, skip over the '/'. |
| 736 | // We distinguish sysroot-based includes from absolute includes by the |
| 737 | // absence of '/' at the beginning of sysroot-based includes. |
| 738 | if (Filename[Pos] == '/') |
| 739 | ++Pos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 741 | return Filename + Pos; |
| 742 | } |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 743 | |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 744 | /// \brief Write the PCH metadata (e.g., i686-apple-darwin9). |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 745 | void PCHWriter::WriteMetadata(ASTContext &Context, const char *isysroot) { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 746 | using namespace llvm; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 747 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 748 | // Metadata |
| 749 | const TargetInfo &Target = Context.Target; |
| 750 | BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev(); |
| 751 | MetaAbbrev->Add(BitCodeAbbrevOp(pch::METADATA)); |
| 752 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // PCH major |
| 753 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // PCH minor |
| 754 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major |
| 755 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor |
| 756 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
| 757 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Target triple |
| 758 | unsigned MetaAbbrevCode = Stream.EmitAbbrev(MetaAbbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 760 | RecordData Record; |
| 761 | Record.push_back(pch::METADATA); |
| 762 | Record.push_back(pch::VERSION_MAJOR); |
| 763 | Record.push_back(pch::VERSION_MINOR); |
| 764 | Record.push_back(CLANG_VERSION_MAJOR); |
| 765 | Record.push_back(CLANG_VERSION_MINOR); |
| 766 | Record.push_back(isysroot != 0); |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 767 | const std::string &TripleStr = Target.getTriple().getTriple(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 768 | Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, TripleStr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 770 | // Original file name |
| 771 | SourceManager &SM = Context.getSourceManager(); |
| 772 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 773 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
| 774 | FileAbbrev->Add(BitCodeAbbrevOp(pch::ORIGINAL_FILE_NAME)); |
| 775 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 776 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 777 | |
| 778 | llvm::sys::Path MainFilePath(MainFile->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 779 | |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 780 | MainFilePath.makeAbsolute(); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 781 | |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 782 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 783 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 784 | isysroot); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 785 | RecordData Record; |
| 786 | Record.push_back(pch::ORIGINAL_FILE_NAME); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 787 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 788 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 789 | |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 790 | // Repository branch/version information. |
| 791 | BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); |
| 792 | RepoAbbrev->Add(BitCodeAbbrevOp(pch::VERSION_CONTROL_BRANCH_REVISION)); |
| 793 | RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 794 | unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 795 | Record.clear(); |
Ted Kremenek | 5b4ec63 | 2010-01-22 20:59:36 +0000 | [diff] [blame] | 796 | Record.push_back(pch::VERSION_CONTROL_BRANCH_REVISION); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 797 | Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, |
| 798 | getClangFullRepositoryVersion()); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /// \brief Write the LangOptions structure. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 802 | void PCHWriter::WriteLanguageOptions(const LangOptions &LangOpts) { |
| 803 | RecordData Record; |
| 804 | Record.push_back(LangOpts.Trigraphs); |
| 805 | Record.push_back(LangOpts.BCPLComment); // BCPL-style '//' comments. |
| 806 | Record.push_back(LangOpts.DollarIdents); // '$' allowed in identifiers. |
| 807 | Record.push_back(LangOpts.AsmPreprocessor); // Preprocessor in asm mode. |
| 808 | Record.push_back(LangOpts.GNUMode); // True in gnu99 mode false in c99 mode (etc) |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 809 | Record.push_back(LangOpts.GNUKeywords); // Allow GNU-extension keywords |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 810 | Record.push_back(LangOpts.ImplicitInt); // C89 implicit 'int'. |
| 811 | Record.push_back(LangOpts.Digraphs); // C94, C99 and C++ |
| 812 | Record.push_back(LangOpts.HexFloats); // C99 Hexadecimal float constants. |
| 813 | Record.push_back(LangOpts.C99); // C99 Support |
| 814 | Record.push_back(LangOpts.Microsoft); // Microsoft extensions. |
| 815 | Record.push_back(LangOpts.CPlusPlus); // C++ Support |
| 816 | Record.push_back(LangOpts.CPlusPlus0x); // C++0x Support |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 817 | Record.push_back(LangOpts.CXXOperatorNames); // Treat C++ operator names as keywords. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 818 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 819 | Record.push_back(LangOpts.ObjC1); // Objective-C 1 support enabled. |
| 820 | Record.push_back(LangOpts.ObjC2); // Objective-C 2 support enabled. |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 821 | Record.push_back(LangOpts.ObjCNonFragileABI); // Objective-C |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 822 | // modern abi enabled. |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 823 | Record.push_back(LangOpts.ObjCNonFragileABI2); // Objective-C enhanced |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 824 | // modern abi enabled. |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 825 | Record.push_back(LangOpts.NoConstantCFStrings); // non cfstring generation enabled.. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 827 | Record.push_back(LangOpts.PascalStrings); // Allow Pascal strings |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 828 | Record.push_back(LangOpts.WritableStrings); // Allow writable strings |
| 829 | Record.push_back(LangOpts.LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 830 | Record.push_back(LangOpts.AltiVec); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 831 | Record.push_back(LangOpts.Exceptions); // Support exception handling. |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 832 | Record.push_back(LangOpts.SjLjExceptions); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 833 | |
| 834 | Record.push_back(LangOpts.NeXTRuntime); // Use NeXT runtime. |
| 835 | Record.push_back(LangOpts.Freestanding); // Freestanding implementation |
| 836 | Record.push_back(LangOpts.NoBuiltin); // Do not use builtin functions (-fno-builtin) |
| 837 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 838 | // Whether static initializers are protected by locks. |
| 839 | Record.push_back(LangOpts.ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 840 | Record.push_back(LangOpts.POSIXThreads); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 841 | Record.push_back(LangOpts.Blocks); // block extension to C |
| 842 | Record.push_back(LangOpts.EmitAllDecls); // Emit all declarations, even if |
| 843 | // they are unused. |
| 844 | Record.push_back(LangOpts.MathErrno); // Math functions must respect errno |
| 845 | // (modulo the platform support). |
| 846 | |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 847 | Record.push_back(LangOpts.getSignedOverflowBehavior()); |
| 848 | Record.push_back(LangOpts.HeinousExtensions); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 849 | |
| 850 | Record.push_back(LangOpts.Optimize); // Whether __OPTIMIZE__ should be defined. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 851 | Record.push_back(LangOpts.OptimizeSize); // Whether __OPTIMIZE_SIZE__ should be |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 852 | // defined. |
| 853 | Record.push_back(LangOpts.Static); // Should __STATIC__ be defined (as |
| 854 | // opposed to __DYNAMIC__). |
| 855 | Record.push_back(LangOpts.PICLevel); // The value for __PIC__, if non-zero. |
| 856 | |
| 857 | Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be |
| 858 | // used (instead of C99 semantics). |
| 859 | Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined. |
Anders Carlsson | a33d9b4 | 2009-05-13 19:49:53 +0000 | [diff] [blame] | 860 | Record.push_back(LangOpts.AccessControl); // Whether C++ access control should |
| 861 | // be enabled. |
Eli Friedman | 15b9176 | 2009-06-05 07:05:05 +0000 | [diff] [blame] | 862 | Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or |
| 863 | // unsigned type |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 864 | Record.push_back(LangOpts.ShortWChar); // force wchar_t to be unsigned short |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 865 | Record.push_back(LangOpts.getGCMode()); |
| 866 | Record.push_back(LangOpts.getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 867 | Record.push_back(LangOpts.getStackProtectorMode()); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 868 | Record.push_back(LangOpts.InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 869 | Record.push_back(LangOpts.OpenCL); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 870 | Record.push_back(LangOpts.CatchUndefined); |
Anders Carlsson | 92f5822 | 2009-08-22 22:30:33 +0000 | [diff] [blame] | 871 | Record.push_back(LangOpts.ElideConstructors); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 872 | Stream.EmitRecord(pch::LANGUAGE_OPTIONS, Record); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 875 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 876 | // stat cache Serialization |
| 877 | //===----------------------------------------------------------------------===// |
| 878 | |
| 879 | namespace { |
| 880 | // Trait used for the on-disk hash table of stat cache results. |
Benjamin Kramer | bd21828 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 881 | class PCHStatCacheTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 882 | public: |
| 883 | typedef const char * key_type; |
| 884 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 885 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 886 | typedef std::pair<int, struct stat> data_type; |
| 887 | typedef const data_type& data_type_ref; |
| 888 | |
| 889 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 890 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 891 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | |
| 893 | std::pair<unsigned,unsigned> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 894 | EmitKeyDataLength(llvm::raw_ostream& Out, const char *path, |
| 895 | data_type_ref Data) { |
| 896 | unsigned StrLen = strlen(path); |
| 897 | clang::io::Emit16(Out, StrLen); |
| 898 | unsigned DataLen = 1; // result value |
| 899 | if (Data.first == 0) |
| 900 | DataLen += 4 + 4 + 2 + 8 + 8; |
| 901 | clang::io::Emit8(Out, DataLen); |
| 902 | return std::make_pair(StrLen + 1, DataLen); |
| 903 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 904 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 905 | void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) { |
| 906 | Out.write(path, KeyLen); |
| 907 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 909 | void EmitData(llvm::raw_ostream& Out, key_type_ref, |
| 910 | data_type_ref Data, unsigned DataLen) { |
| 911 | using namespace clang::io; |
| 912 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 914 | // Result of stat() |
| 915 | Emit8(Out, Data.first? 1 : 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 916 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 917 | if (Data.first == 0) { |
| 918 | Emit32(Out, (uint32_t) Data.second.st_ino); |
| 919 | Emit32(Out, (uint32_t) Data.second.st_dev); |
| 920 | Emit16(Out, (uint16_t) Data.second.st_mode); |
| 921 | Emit64(Out, (uint64_t) Data.second.st_mtime); |
| 922 | Emit64(Out, (uint64_t) Data.second.st_size); |
| 923 | } |
| 924 | |
| 925 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 926 | } |
| 927 | }; |
| 928 | } // end anonymous namespace |
| 929 | |
| 930 | /// \brief Write the stat() system call cache to the PCH file. |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 931 | void PCHWriter::WriteStatCache(MemorizeStatCalls &StatCalls, |
| 932 | const char *isysroot) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 933 | // Build the on-disk hash table containing information about every |
| 934 | // stat() call. |
| 935 | OnDiskChainedHashTableGenerator<PCHStatCacheTrait> Generator; |
| 936 | unsigned NumStatEntries = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 938 | StatEnd = StatCalls.end(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 939 | Stat != StatEnd; ++Stat, ++NumStatEntries) { |
| 940 | const char *Filename = Stat->first(); |
| 941 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 942 | Generator.insert(Filename, Stat->second); |
| 943 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 945 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 946 | llvm::SmallString<4096> StatCacheData; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 947 | uint32_t BucketOffset; |
| 948 | { |
| 949 | llvm::raw_svector_ostream Out(StatCacheData); |
| 950 | // Make sure that no bucket is at offset 0 |
| 951 | clang::io::Emit32(Out, 0); |
| 952 | BucketOffset = Generator.Emit(Out); |
| 953 | } |
| 954 | |
| 955 | // Create a blob abbreviation |
| 956 | using namespace llvm; |
| 957 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 958 | Abbrev->Add(BitCodeAbbrevOp(pch::STAT_CACHE)); |
| 959 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 960 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 961 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 962 | unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); |
| 963 | |
| 964 | // Write the stat cache |
| 965 | RecordData Record; |
| 966 | Record.push_back(pch::STAT_CACHE); |
| 967 | Record.push_back(BucketOffset); |
| 968 | Record.push_back(NumStatEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 969 | Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 973 | // Source Manager Serialization |
| 974 | //===----------------------------------------------------------------------===// |
| 975 | |
| 976 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 977 | /// file. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 978 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 979 | using namespace llvm; |
| 980 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 981 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_FILE_ENTRY)); |
| 982 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 983 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 984 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 985 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 986 | // FileEntry fields. |
| 987 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 988 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 989 | // HeaderFileInfo fields. |
| 990 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isImport |
| 991 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // DirInfo |
| 992 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumIncludes |
| 993 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // ControllingMacro |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 994 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 995 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 999 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1000 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1001 | using namespace llvm; |
| 1002 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1003 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_BUFFER_ENTRY)); |
| 1004 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1005 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1006 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1007 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1008 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1009 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1013 | /// buffer's blob. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1014 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1015 | using namespace llvm; |
| 1016 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1017 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_BUFFER_BLOB)); |
| 1018 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1019 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | /// \brief Create an abbreviation for the SLocEntry that refers to an |
| 1023 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1024 | static unsigned CreateSLocInstantiationAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1025 | using namespace llvm; |
| 1026 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1027 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_INSTANTIATION_ENTRY)); |
| 1028 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1029 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1030 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1031 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1032 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1033 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /// \brief Writes the block containing the serialized form of the |
| 1037 | /// source manager. |
| 1038 | /// |
| 1039 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1040 | /// blob), indexed based on the file name, so that we only create |
| 1041 | /// entries for files that we actually need. In the common case (no |
| 1042 | /// errors), we probably won't have to create file entries for any of |
| 1043 | /// the files in the AST. |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1044 | void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1045 | const Preprocessor &PP, |
| 1046 | const char *isysroot) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1047 | RecordData Record; |
| 1048 | |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1049 | // Enter the source manager block. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1050 | Stream.EnterSubblock(pch::SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1051 | |
| 1052 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | 828e18c | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1053 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1054 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1055 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
| 1056 | unsigned SLocInstantiationAbbrv = CreateSLocInstantiationAbbrev(Stream); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1057 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1058 | // Write the line table. |
| 1059 | if (SourceMgr.hasLineTable()) { |
| 1060 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1061 | |
| 1062 | // Emit the file names |
| 1063 | Record.push_back(LineTable.getNumFilenames()); |
| 1064 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1065 | // Emit the file name |
| 1066 | const char *Filename = LineTable.getFilename(I); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1067 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1068 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1069 | Record.push_back(FilenameLen); |
| 1070 | if (FilenameLen) |
| 1071 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1072 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1073 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1074 | // Emit the line entries |
| 1075 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1076 | L != LEnd; ++L) { |
| 1077 | // Emit the file ID |
| 1078 | Record.push_back(L->first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1080 | // Emit the line entries |
| 1081 | Record.push_back(L->second.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1082 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1083 | LEEnd = L->second.end(); |
| 1084 | LE != LEEnd; ++LE) { |
| 1085 | Record.push_back(LE->FileOffset); |
| 1086 | Record.push_back(LE->LineNo); |
| 1087 | Record.push_back(LE->FilenameID); |
| 1088 | Record.push_back((unsigned)LE->FileKind); |
| 1089 | Record.push_back(LE->IncludeOffset); |
| 1090 | } |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1091 | } |
Zhongxing Xu | 3d8216a | 2009-05-22 08:38:27 +0000 | [diff] [blame] | 1092 | Stream.EmitRecord(pch::SM_LINE_TABLE, Record); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1095 | // Write out the source location entry table. We skip the first |
| 1096 | // entry, which is always the same dummy entry. |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1097 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1098 | RecordData PreloadSLocs; |
| 1099 | SLocEntryOffsets.reserve(SourceMgr.sloc_entry_size() - 1); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1100 | for (unsigned I = 1, N = SourceMgr.sloc_entry_size(); I != N; ++I) { |
| 1101 | // Get this source location entry. |
| 1102 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getSLocEntry(I); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1103 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1104 | // Record the offset of this source-location entry. |
| 1105 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1106 | |
| 1107 | // Figure out which record code to use. |
| 1108 | unsigned Code; |
| 1109 | if (SLoc->isFile()) { |
| 1110 | if (SLoc->getFile().getContentCache()->Entry) |
| 1111 | Code = pch::SM_SLOC_FILE_ENTRY; |
| 1112 | else |
| 1113 | Code = pch::SM_SLOC_BUFFER_ENTRY; |
| 1114 | } else |
| 1115 | Code = pch::SM_SLOC_INSTANTIATION_ENTRY; |
| 1116 | Record.clear(); |
| 1117 | Record.push_back(Code); |
| 1118 | |
| 1119 | Record.push_back(SLoc->getOffset()); |
| 1120 | if (SLoc->isFile()) { |
| 1121 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1122 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1123 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1124 | Record.push_back(File.hasLineDirectives()); |
| 1125 | |
| 1126 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
| 1127 | if (Content->Entry) { |
| 1128 | // The source location entry is a file. The blob associated |
| 1129 | // with this entry is the file name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1130 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1131 | // Emit size/modification time for this file. |
| 1132 | Record.push_back(Content->Entry->getSize()); |
| 1133 | Record.push_back(Content->Entry->getModificationTime()); |
| 1134 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1135 | // Emit header-search information associated with this file. |
| 1136 | HeaderFileInfo HFI; |
| 1137 | HeaderSearch &HS = PP.getHeaderSearchInfo(); |
| 1138 | if (Content->Entry->getUID() < HS.header_file_size()) |
| 1139 | HFI = HS.header_file_begin()[Content->Entry->getUID()]; |
| 1140 | Record.push_back(HFI.isImport); |
| 1141 | Record.push_back(HFI.DirInfo); |
| 1142 | Record.push_back(HFI.NumIncludes); |
| 1143 | AddIdentifierRef(HFI.ControllingMacro, Record); |
| 1144 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1145 | // Turn the file name into an absolute path, if it isn't already. |
| 1146 | const char *Filename = Content->Entry->getName(); |
| 1147 | llvm::sys::Path FilePath(Filename, strlen(Filename)); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1148 | FilePath.makeAbsolute(); |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1149 | Filename = FilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1151 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1152 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1153 | |
| 1154 | // FIXME: For now, preload all file source locations, so that |
| 1155 | // we get the appropriate File entries in the reader. This is |
| 1156 | // a temporary measure. |
| 1157 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1158 | } else { |
| 1159 | // The source location entry is a buffer. The blob associated |
| 1160 | // with this entry contains the contents of the buffer. |
| 1161 | |
| 1162 | // We add one to the size so that we capture the trailing NULL |
| 1163 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1164 | // the reader side). |
Douglas Gregor | 36c35ba | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1165 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1166 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1167 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1168 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
| 1169 | llvm::StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1170 | Record.clear(); |
| 1171 | Record.push_back(pch::SM_SLOC_BUFFER_BLOB); |
| 1172 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1173 | llvm::StringRef(Buffer->getBufferStart(), |
| 1174 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1175 | |
| 1176 | if (strcmp(Name, "<built-in>") == 0) |
| 1177 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1178 | } |
| 1179 | } else { |
| 1180 | // The source location entry is an instantiation. |
| 1181 | const SrcMgr::InstantiationInfo &Inst = SLoc->getInstantiation(); |
| 1182 | Record.push_back(Inst.getSpellingLoc().getRawEncoding()); |
| 1183 | Record.push_back(Inst.getInstantiationLocStart().getRawEncoding()); |
| 1184 | Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding()); |
| 1185 | |
| 1186 | // Compute the token length for this macro expansion. |
| 1187 | unsigned NextOffset = SourceMgr.getNextOffset(); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1188 | if (I + 1 != N) |
| 1189 | NextOffset = SourceMgr.getSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1190 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
| 1191 | Stream.EmitRecordWithAbbrev(SLocInstantiationAbbrv, Record); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1195 | Stream.ExitBlock(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1196 | |
| 1197 | if (SLocEntryOffsets.empty()) |
| 1198 | return; |
| 1199 | |
| 1200 | // Write the source-location offsets table into the PCH block. This |
| 1201 | // table is used for lazily loading source-location information. |
| 1202 | using namespace llvm; |
| 1203 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1204 | Abbrev->Add(BitCodeAbbrevOp(pch::SOURCE_LOCATION_OFFSETS)); |
| 1205 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
| 1206 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // next offset |
| 1207 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1208 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1210 | Record.clear(); |
| 1211 | Record.push_back(pch::SOURCE_LOCATION_OFFSETS); |
| 1212 | Record.push_back(SLocEntryOffsets.size()); |
| 1213 | Record.push_back(SourceMgr.getNextOffset()); |
| 1214 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | (const char *)&SLocEntryOffsets.front(), |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1216 | SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0])); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1217 | |
| 1218 | // Write the source location entry preloads array, telling the PCH |
| 1219 | // reader which source locations entries it should load eagerly. |
| 1220 | Stream.EmitRecord(pch::SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1223 | //===----------------------------------------------------------------------===// |
| 1224 | // Preprocessor Serialization |
| 1225 | //===----------------------------------------------------------------------===// |
| 1226 | |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1227 | /// \brief Writes the block containing the serialized form of the |
| 1228 | /// preprocessor. |
| 1229 | /// |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1230 | void PCHWriter::WritePreprocessor(const Preprocessor &PP) { |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1231 | RecordData Record; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1232 | |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1233 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1234 | if (PP.getCounterValue() != 0) { |
| 1235 | Record.push_back(PP.getCounterValue()); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1236 | Stream.EmitRecord(pch::PP_COUNTER_VALUE, Record); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1237 | Record.clear(); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | // Enter the preprocessor block. |
| 1241 | Stream.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 2); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1243 | // If the PCH file contains __DATE__ or __TIME__ emit a warning about this. |
| 1244 | // FIXME: use diagnostics subsystem for localization etc. |
| 1245 | if (PP.SawDateOrTime()) |
| 1246 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1248 | // Loop over all the macro definitions that are live at the end of the file, |
| 1249 | // emitting each to the PP section. |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1250 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1251 | for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end(); |
| 1252 | I != E; ++I) { |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1253 | // FIXME: This emits macros in hash table order, we should do it in a stable |
| 1254 | // order so that output is reproducible. |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1255 | MacroInfo *MI = I->second; |
| 1256 | |
| 1257 | // Don't emit builtin macros like __LINE__ to the PCH file unless they have |
| 1258 | // been redefined by the header (in which case they are not isBuiltinMacro). |
| 1259 | if (MI->isBuiltinMacro()) |
| 1260 | continue; |
| 1261 | |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1262 | AddIdentifierRef(I->first, Record); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1263 | MacroOffsets[I->first] = Stream.GetCurrentBitNo(); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1264 | Record.push_back(MI->getDefinitionLoc().getRawEncoding()); |
| 1265 | Record.push_back(MI->isUsed()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1266 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1267 | unsigned Code; |
| 1268 | if (MI->isObjectLike()) { |
| 1269 | Code = pch::PP_MACRO_OBJECT_LIKE; |
| 1270 | } else { |
| 1271 | Code = pch::PP_MACRO_FUNCTION_LIKE; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1272 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1273 | Record.push_back(MI->isC99Varargs()); |
| 1274 | Record.push_back(MI->isGNUVarargs()); |
| 1275 | Record.push_back(MI->getNumArgs()); |
| 1276 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1277 | I != E; ++I) |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1278 | AddIdentifierRef(*I, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1279 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1280 | |
| 1281 | // If we have a detailed preprocessing record, record the macro definition |
| 1282 | // ID that corresponds to this macro. |
| 1283 | if (PPRec) |
| 1284 | Record.push_back(getMacroDefinitionID(PPRec->findMacroDefinition(MI))); |
| 1285 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1286 | Stream.EmitRecord(Code, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1287 | Record.clear(); |
| 1288 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1289 | // Emit the tokens array. |
| 1290 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1291 | // Note that we know that the preprocessor does not have any annotation |
| 1292 | // tokens in it because they are created by the parser, and thus can't be |
| 1293 | // in a macro definition. |
| 1294 | const Token &Tok = MI->getReplacementToken(TokNo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1296 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1297 | Record.push_back(Tok.getLength()); |
| 1298 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1299 | // FIXME: When reading literal tokens, reconstruct the literal pointer if |
| 1300 | // it is needed. |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1301 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1302 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1303 | // FIXME: Should translate token kind to a stable encoding. |
| 1304 | Record.push_back(Tok.getKind()); |
| 1305 | // FIXME: Should translate token flags to a stable encoding. |
| 1306 | Record.push_back(Tok.getFlags()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1307 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1308 | Stream.EmitRecord(pch::PP_TOKEN, Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1309 | Record.clear(); |
| 1310 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1311 | ++NumMacros; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1312 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1313 | |
| 1314 | // If the preprocessor has a preprocessing record, emit it. |
| 1315 | unsigned NumPreprocessingRecords = 0; |
| 1316 | if (PPRec) { |
| 1317 | for (PreprocessingRecord::iterator E = PPRec->begin(), EEnd = PPRec->end(); |
| 1318 | E != EEnd; ++E) { |
| 1319 | Record.clear(); |
| 1320 | |
| 1321 | if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) { |
| 1322 | Record.push_back(NumPreprocessingRecords++); |
| 1323 | AddSourceLocation(MI->getSourceRange().getBegin(), Record); |
| 1324 | AddSourceLocation(MI->getSourceRange().getEnd(), Record); |
| 1325 | AddIdentifierRef(MI->getName(), Record); |
| 1326 | Record.push_back(getMacroDefinitionID(MI->getDefinition())); |
| 1327 | Stream.EmitRecord(pch::PP_MACRO_INSTANTIATION, Record); |
| 1328 | continue; |
| 1329 | } |
| 1330 | |
| 1331 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
| 1332 | // Record this macro definition's location. |
| 1333 | pch::IdentID ID = getMacroDefinitionID(MD); |
| 1334 | if (ID != MacroDefinitionOffsets.size()) { |
| 1335 | if (ID > MacroDefinitionOffsets.size()) |
| 1336 | MacroDefinitionOffsets.resize(ID + 1); |
| 1337 | |
| 1338 | MacroDefinitionOffsets[ID] = Stream.GetCurrentBitNo(); |
| 1339 | } else |
| 1340 | MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1341 | |
| 1342 | Record.push_back(NumPreprocessingRecords++); |
| 1343 | Record.push_back(ID); |
| 1344 | AddSourceLocation(MD->getSourceRange().getBegin(), Record); |
| 1345 | AddSourceLocation(MD->getSourceRange().getEnd(), Record); |
| 1346 | AddIdentifierRef(MD->getName(), Record); |
| 1347 | AddSourceLocation(MD->getLocation(), Record); |
| 1348 | Stream.EmitRecord(pch::PP_MACRO_DEFINITION, Record); |
| 1349 | continue; |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1354 | Stream.ExitBlock(); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1355 | |
| 1356 | // Write the offsets table for the preprocessing record. |
| 1357 | if (NumPreprocessingRecords > 0) { |
| 1358 | // Write the offsets table for identifier IDs. |
| 1359 | using namespace llvm; |
| 1360 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1361 | Abbrev->Add(BitCodeAbbrevOp(pch::MACRO_DEFINITION_OFFSETS)); |
| 1362 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records |
| 1363 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs |
| 1364 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1365 | unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1366 | |
| 1367 | Record.clear(); |
| 1368 | Record.push_back(pch::MACRO_DEFINITION_OFFSETS); |
| 1369 | Record.push_back(NumPreprocessingRecords); |
| 1370 | Record.push_back(MacroDefinitionOffsets.size()); |
| 1371 | Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record, |
| 1372 | (const char *)&MacroDefinitionOffsets.front(), |
| 1373 | MacroDefinitionOffsets.size() * sizeof(uint32_t)); |
| 1374 | } |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1377 | //===----------------------------------------------------------------------===// |
| 1378 | // Type Serialization |
| 1379 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1380 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1381 | /// \brief Write the representation of a type to the PCH stream. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1382 | void PCHWriter::WriteType(QualType T) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1383 | pch::TypeID &ID = TypeIDs[T]; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1384 | if (ID == 0) // we haven't seen this type before. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1385 | ID = NextTypeID++; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1386 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1387 | // Record the offset for this type. |
| 1388 | if (TypeOffsets.size() == ID - pch::NUM_PREDEF_TYPE_IDS) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1389 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1390 | else if (TypeOffsets.size() < ID - pch::NUM_PREDEF_TYPE_IDS) { |
| 1391 | TypeOffsets.resize(ID + 1 - pch::NUM_PREDEF_TYPE_IDS); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1392 | TypeOffsets[ID - pch::NUM_PREDEF_TYPE_IDS] = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | RecordData Record; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1397 | // Emit the type's representation. |
| 1398 | PCHTypeWriter W(*this, Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 1400 | if (T.hasLocalNonFastQualifiers()) { |
| 1401 | Qualifiers Qs = T.getLocalQualifiers(); |
| 1402 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1403 | Record.push_back(Qs.getAsOpaqueValue()); |
| 1404 | W.Code = pch::TYPE_EXT_QUAL; |
| 1405 | } else { |
| 1406 | switch (T->getTypeClass()) { |
| 1407 | // For all of the concrete, non-dependent types, call the |
| 1408 | // appropriate visitor function. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1409 | #define TYPE(Class, Base) \ |
Mike Stump | b716633 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 1410 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1411 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1412 | #include "clang/AST/TypeNodes.def" |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1413 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | // Emit the serialized record. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1417 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1418 | |
| 1419 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1420 | FlushStmts(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1423 | //===----------------------------------------------------------------------===// |
| 1424 | // Declaration Serialization |
| 1425 | //===----------------------------------------------------------------------===// |
| 1426 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1427 | /// \brief Write the block containing all of the declaration IDs |
| 1428 | /// lexically declared within the given DeclContext. |
| 1429 | /// |
| 1430 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 1431 | /// bistream, or 0 if no block was written. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1432 | uint64_t PCHWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1433 | DeclContext *DC) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1434 | if (DC->decls_empty()) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1435 | return 0; |
| 1436 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1437 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1438 | RecordData Record; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1439 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 1440 | D != DEnd; ++D) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1441 | AddDeclRef(*D, Record); |
| 1442 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1443 | ++NumLexicalDeclContexts; |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1444 | Stream.EmitRecord(pch::DECL_CONTEXT_LEXICAL, Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1445 | return Offset; |
| 1446 | } |
| 1447 | |
| 1448 | /// \brief Write the block containing all of the declaration IDs |
| 1449 | /// visible from the given DeclContext. |
| 1450 | /// |
| 1451 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
| 1452 | /// bistream, or 0 if no block was written. |
| 1453 | uint64_t PCHWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 1454 | DeclContext *DC) { |
| 1455 | if (DC->getPrimaryContext() != DC) |
| 1456 | return 0; |
| 1457 | |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 1458 | // Since there is no name lookup into functions or methods, don't bother to |
| 1459 | // build a visible-declarations table for these entities. |
| 1460 | if (DC->isFunctionOrMethod()) |
| 1461 | return 0; |
| 1462 | |
| 1463 | // If not in C++, we perform name lookup for the translation unit via the |
| 1464 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 1465 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 1466 | // friend declarations, is there a way to do this without writing the table ? |
| 1467 | if (DC->isTranslationUnit() && !Context.getLangOptions().CPlusPlus) |
Douglas Gregor | 58f0699 | 2009-04-18 15:49:20 +0000 | [diff] [blame] | 1468 | return 0; |
| 1469 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1470 | // Force the DeclContext to build a its name-lookup table. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1471 | DC->lookup(DeclarationName()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1472 | |
| 1473 | // Serialize the contents of the mapping used for lookup. Note that, |
| 1474 | // although we have two very different code paths, the serialized |
| 1475 | // representation is the same for both cases: a declaration name, |
| 1476 | // followed by a size, followed by references to the visible |
| 1477 | // declarations that have that name. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1478 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1479 | RecordData Record; |
| 1480 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 1481 | if (!Map) |
| 1482 | return 0; |
| 1483 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1484 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 1485 | D != DEnd; ++D) { |
| 1486 | AddDeclarationName(D->first, Record); |
| 1487 | DeclContext::lookup_result Result = D->second.getLookupResult(Context); |
| 1488 | Record.push_back(Result.second - Result.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1489 | for (; Result.first != Result.second; ++Result.first) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1490 | AddDeclRef(*Result.first, Record); |
| 1491 | } |
| 1492 | |
| 1493 | if (Record.size() == 0) |
| 1494 | return 0; |
| 1495 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1496 | Stream.EmitRecord(pch::DECL_CONTEXT_VISIBLE, Record); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1497 | ++NumVisibleDeclContexts; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1498 | return Offset; |
| 1499 | } |
| 1500 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1501 | //===----------------------------------------------------------------------===// |
| 1502 | // Global Method Pool and Selector Serialization |
| 1503 | //===----------------------------------------------------------------------===// |
| 1504 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1505 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1506 | // Trait used for the on-disk hash table used in the method pool. |
Benjamin Kramer | bd21828 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 1507 | class PCHMethodPoolTrait { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1508 | PCHWriter &Writer; |
| 1509 | |
| 1510 | public: |
| 1511 | typedef Selector key_type; |
| 1512 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1513 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1514 | typedef std::pair<ObjCMethodList, ObjCMethodList> data_type; |
| 1515 | typedef const data_type& data_type_ref; |
| 1516 | |
| 1517 | explicit PCHMethodPoolTrait(PCHWriter &Writer) : Writer(Writer) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1518 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1519 | static unsigned ComputeHash(Selector Sel) { |
| 1520 | unsigned N = Sel.getNumArgs(); |
| 1521 | if (N == 0) |
| 1522 | ++N; |
| 1523 | unsigned R = 5381; |
| 1524 | for (unsigned I = 0; I != N; ++I) |
| 1525 | if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I)) |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1526 | R = llvm::HashString(II->getName(), R); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1527 | return R; |
| 1528 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1529 | |
| 1530 | std::pair<unsigned,unsigned> |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1531 | EmitKeyDataLength(llvm::raw_ostream& Out, Selector Sel, |
| 1532 | data_type_ref Methods) { |
| 1533 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 1534 | clang::io::Emit16(Out, KeyLen); |
| 1535 | unsigned DataLen = 2 + 2; // 2 bytes for each of the method counts |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1536 | for (const ObjCMethodList *Method = &Methods.first; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1537 | Method = Method->Next) |
| 1538 | if (Method->Method) |
| 1539 | DataLen += 4; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1540 | for (const ObjCMethodList *Method = &Methods.second; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1541 | Method = Method->Next) |
| 1542 | if (Method->Method) |
| 1543 | DataLen += 4; |
| 1544 | clang::io::Emit16(Out, DataLen); |
| 1545 | return std::make_pair(KeyLen, DataLen); |
| 1546 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1547 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1548 | void EmitKey(llvm::raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1549 | uint64_t Start = Out.tell(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1550 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 1551 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1552 | unsigned N = Sel.getNumArgs(); |
| 1553 | clang::io::Emit16(Out, N); |
| 1554 | if (N == 0) |
| 1555 | N = 1; |
| 1556 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1557 | clang::io::Emit32(Out, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1558 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 1559 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1561 | void EmitData(llvm::raw_ostream& Out, key_type_ref, |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1562 | data_type_ref Methods, unsigned DataLen) { |
| 1563 | uint64_t Start = Out.tell(); (void)Start; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1564 | unsigned NumInstanceMethods = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1565 | for (const ObjCMethodList *Method = &Methods.first; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1566 | Method = Method->Next) |
| 1567 | if (Method->Method) |
| 1568 | ++NumInstanceMethods; |
| 1569 | |
| 1570 | unsigned NumFactoryMethods = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1571 | for (const ObjCMethodList *Method = &Methods.second; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1572 | Method = Method->Next) |
| 1573 | if (Method->Method) |
| 1574 | ++NumFactoryMethods; |
| 1575 | |
| 1576 | clang::io::Emit16(Out, NumInstanceMethods); |
| 1577 | clang::io::Emit16(Out, NumFactoryMethods); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | for (const ObjCMethodList *Method = &Methods.first; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1579 | Method = Method->Next) |
| 1580 | if (Method->Method) |
| 1581 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1582 | for (const ObjCMethodList *Method = &Methods.second; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1583 | Method = Method->Next) |
| 1584 | if (Method->Method) |
| 1585 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1586 | |
| 1587 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1588 | } |
| 1589 | }; |
| 1590 | } // end anonymous namespace |
| 1591 | |
| 1592 | /// \brief Write the method pool into the PCH file. |
| 1593 | /// |
| 1594 | /// The method pool contains both instance and factory methods, stored |
| 1595 | /// in an on-disk hash table indexed by the selector. |
| 1596 | void PCHWriter::WriteMethodPool(Sema &SemaRef) { |
| 1597 | using namespace llvm; |
| 1598 | |
| 1599 | // Create and write out the blob that contains the instance and |
| 1600 | // factor method pools. |
| 1601 | bool Empty = true; |
| 1602 | { |
| 1603 | OnDiskChainedHashTableGenerator<PCHMethodPoolTrait> Generator; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1604 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1605 | // Create the on-disk hash table representation. Start by |
| 1606 | // iterating through the instance method pool. |
| 1607 | PCHMethodPoolTrait::key_type Key; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1608 | unsigned NumSelectorsInMethodPool = 0; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1609 | for (llvm::DenseMap<Selector, ObjCMethodList>::iterator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | Instance = SemaRef.InstanceMethodPool.begin(), |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1611 | InstanceEnd = SemaRef.InstanceMethodPool.end(); |
| 1612 | Instance != InstanceEnd; ++Instance) { |
| 1613 | // Check whether there is a factory method with the same |
| 1614 | // selector. |
| 1615 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Factory |
| 1616 | = SemaRef.FactoryMethodPool.find(Instance->first); |
| 1617 | |
| 1618 | if (Factory == SemaRef.FactoryMethodPool.end()) |
| 1619 | Generator.insert(Instance->first, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | std::make_pair(Instance->second, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1621 | ObjCMethodList())); |
| 1622 | else |
| 1623 | Generator.insert(Instance->first, |
| 1624 | std::make_pair(Instance->second, Factory->second)); |
| 1625 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1626 | ++NumSelectorsInMethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1627 | Empty = false; |
| 1628 | } |
| 1629 | |
| 1630 | // Now iterate through the factory method pool, to pick up any |
| 1631 | // selectors that weren't already in the instance method pool. |
| 1632 | for (llvm::DenseMap<Selector, ObjCMethodList>::iterator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | Factory = SemaRef.FactoryMethodPool.begin(), |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1634 | FactoryEnd = SemaRef.FactoryMethodPool.end(); |
| 1635 | Factory != FactoryEnd; ++Factory) { |
| 1636 | // Check whether there is an instance method with the same |
| 1637 | // selector. If so, there is no work to do here. |
| 1638 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Instance |
| 1639 | = SemaRef.InstanceMethodPool.find(Factory->first); |
| 1640 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1641 | if (Instance == SemaRef.InstanceMethodPool.end()) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1642 | Generator.insert(Factory->first, |
| 1643 | std::make_pair(ObjCMethodList(), Factory->second)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1644 | ++NumSelectorsInMethodPool; |
| 1645 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1646 | |
| 1647 | Empty = false; |
| 1648 | } |
| 1649 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1650 | if (Empty && SelectorOffsets.empty()) |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1651 | return; |
| 1652 | |
| 1653 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1654 | llvm::SmallString<4096> MethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1655 | uint32_t BucketOffset; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1656 | SelectorOffsets.resize(SelVector.size()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1657 | { |
| 1658 | PCHMethodPoolTrait Trait(*this); |
| 1659 | llvm::raw_svector_ostream Out(MethodPool); |
| 1660 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1661 | clang::io::Emit32(Out, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1662 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1663 | |
| 1664 | // For every selector that we have seen but which was not |
| 1665 | // written into the hash table, write the selector itself and |
| 1666 | // record it's offset. |
| 1667 | for (unsigned I = 0, N = SelVector.size(); I != N; ++I) |
| 1668 | if (SelectorOffsets[I] == 0) |
| 1669 | Trait.EmitKey(Out, SelVector[I], 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | // Create a blob abbreviation |
| 1673 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1674 | Abbrev->Add(BitCodeAbbrevOp(pch::METHOD_POOL)); |
| 1675 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1676 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1677 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1678 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1679 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1680 | // Write the method pool |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1681 | RecordData Record; |
| 1682 | Record.push_back(pch::METHOD_POOL); |
| 1683 | Record.push_back(BucketOffset); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1684 | Record.push_back(NumSelectorsInMethodPool); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1685 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1686 | |
| 1687 | // Create a blob abbreviation for the selector table offsets. |
| 1688 | Abbrev = new BitCodeAbbrev(); |
| 1689 | Abbrev->Add(BitCodeAbbrevOp(pch::SELECTOR_OFFSETS)); |
| 1690 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index |
| 1691 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1692 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1693 | |
| 1694 | // Write the selector offsets table. |
| 1695 | Record.clear(); |
| 1696 | Record.push_back(pch::SELECTOR_OFFSETS); |
| 1697 | Record.push_back(SelectorOffsets.size()); |
| 1698 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 1699 | (const char *)&SelectorOffsets.front(), |
| 1700 | SelectorOffsets.size() * 4); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1701 | } |
| 1702 | } |
| 1703 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1704 | //===----------------------------------------------------------------------===// |
| 1705 | // Identifier Table Serialization |
| 1706 | //===----------------------------------------------------------------------===// |
| 1707 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1708 | namespace { |
Benjamin Kramer | bd21828 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 1709 | class PCHIdentifierTableTrait { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1710 | PCHWriter &Writer; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1711 | Preprocessor &PP; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1712 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1713 | /// \brief Determines whether this is an "interesting" identifier |
| 1714 | /// that needs a full IdentifierInfo structure written into the hash |
| 1715 | /// table. |
| 1716 | static bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 1717 | return II->isPoisoned() || |
| 1718 | II->isExtensionToken() || |
| 1719 | II->hasMacroDefinition() || |
| 1720 | II->getObjCOrBuiltinID() || |
| 1721 | II->getFETokenInfo<void>(); |
| 1722 | } |
| 1723 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1724 | public: |
| 1725 | typedef const IdentifierInfo* key_type; |
| 1726 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1727 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1728 | typedef pch::IdentID data_type; |
| 1729 | typedef data_type data_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1730 | |
| 1731 | PCHIdentifierTableTrait(PCHWriter &Writer, Preprocessor &PP) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1732 | : Writer(Writer), PP(PP) { } |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1733 | |
| 1734 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1735 | return llvm::HashString(II->getName()); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1736 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | |
| 1738 | std::pair<unsigned,unsigned> |
| 1739 | EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1740 | pch::IdentID ID) { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 1741 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1742 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
| 1743 | if (isInterestingIdentifier(II)) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1744 | DataLen += 2; // 2 bytes for builtin ID, flags |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1745 | if (II->hasMacroDefinition() && |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1746 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro()) |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1747 | DataLen += 4; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1748 | for (IdentifierResolver::iterator D = IdentifierResolver::begin(II), |
| 1749 | DEnd = IdentifierResolver::end(); |
| 1750 | D != DEnd; ++D) |
| 1751 | DataLen += sizeof(pch::DeclID); |
| 1752 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1753 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 1754 | // We emit the key length after the data length so that every |
| 1755 | // string is preceded by a 16-bit length. This matches the PTH |
| 1756 | // format for storing identifiers. |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 1757 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1758 | return std::make_pair(KeyLen, DataLen); |
| 1759 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
| 1761 | void EmitKey(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1762 | unsigned KeyLen) { |
| 1763 | // Record the location of the key data. This is used when generating |
| 1764 | // the mapping from persistent IDs to strings. |
| 1765 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 1766 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1767 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | |
| 1769 | void EmitData(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1770 | pch::IdentID ID, unsigned) { |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1771 | if (!isInterestingIdentifier(II)) { |
| 1772 | clang::io::Emit32(Out, ID << 1); |
| 1773 | return; |
| 1774 | } |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1775 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1776 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1777 | uint32_t Bits = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1778 | bool hasMacroDefinition = |
| 1779 | II->hasMacroDefinition() && |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1780 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro(); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1781 | Bits = (uint32_t)II->getObjCOrBuiltinID(); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 1782 | Bits = (Bits << 1) | unsigned(hasMacroDefinition); |
| 1783 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 1784 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
| 1785 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1786 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1787 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1788 | if (hasMacroDefinition) |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1789 | clang::io::Emit32(Out, Writer.getMacroOffset(II)); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1790 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1791 | // Emit the declaration IDs in reverse order, because the |
| 1792 | // IdentifierResolver provides the declarations as they would be |
| 1793 | // visible (e.g., the function "stat" would come before the struct |
| 1794 | // "stat"), but IdentifierResolver::AddDeclToIdentifierChain() |
| 1795 | // adds declarations to the end of the list (so we need to see the |
| 1796 | // struct "status" before the function "status"). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1797 | llvm::SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II), |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1798 | IdentifierResolver::end()); |
| 1799 | for (llvm::SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
| 1800 | DEnd = Decls.rend(); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1801 | D != DEnd; ++D) |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1802 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1803 | } |
| 1804 | }; |
| 1805 | } // end anonymous namespace |
| 1806 | |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1807 | /// \brief Write the identifier table into the PCH file. |
| 1808 | /// |
| 1809 | /// The identifier table consists of a blob containing string data |
| 1810 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 1811 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1812 | void PCHWriter::WriteIdentifierTable(Preprocessor &PP) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1813 | using namespace llvm; |
| 1814 | |
| 1815 | // Create and write out the blob that contains the identifier |
| 1816 | // strings. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1817 | { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1818 | OnDiskChainedHashTableGenerator<PCHIdentifierTableTrait> Generator; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1819 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1820 | // Look for any identifiers that were named while processing the |
| 1821 | // headers, but are otherwise not needed. We add these to the hash |
| 1822 | // table to enable checking of the predefines buffer in the case |
| 1823 | // where the user adds new macro definitions when building the PCH |
| 1824 | // file. |
| 1825 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 1826 | IDEnd = PP.getIdentifierTable().end(); |
| 1827 | ID != IDEnd; ++ID) |
| 1828 | getIdentifierRef(ID->second); |
| 1829 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1830 | // Create the on-disk hash table representation. |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1831 | IdentifierOffsets.resize(IdentifierIDs.size()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1832 | for (llvm::DenseMap<const IdentifierInfo *, pch::IdentID>::iterator |
| 1833 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 1834 | ID != IDEnd; ++ID) { |
| 1835 | assert(ID->first && "NULL identifier in identifier table"); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 1836 | Generator.insert(ID->first, ID->second); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1837 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1838 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1839 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1840 | llvm::SmallString<4096> IdentifierTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1841 | uint32_t BucketOffset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1842 | { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1843 | PCHIdentifierTableTrait Trait(*this, PP); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1844 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1845 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1846 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1847 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | // Create a blob abbreviation |
| 1851 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1852 | Abbrev->Add(BitCodeAbbrevOp(pch::IDENTIFIER_TABLE)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1853 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1854 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1855 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1856 | |
| 1857 | // Write the identifier table |
| 1858 | RecordData Record; |
| 1859 | Record.push_back(pch::IDENTIFIER_TABLE); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1860 | Record.push_back(BucketOffset); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1861 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1865 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1866 | Abbrev->Add(BitCodeAbbrevOp(pch::IDENTIFIER_OFFSET)); |
| 1867 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
| 1868 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1869 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1870 | |
| 1871 | RecordData Record; |
| 1872 | Record.push_back(pch::IDENTIFIER_OFFSET); |
| 1873 | Record.push_back(IdentifierOffsets.size()); |
| 1874 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
| 1875 | (const char *)&IdentifierOffsets.front(), |
| 1876 | IdentifierOffsets.size() * sizeof(uint32_t)); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1879 | //===----------------------------------------------------------------------===// |
| 1880 | // General Serialization Routines |
| 1881 | //===----------------------------------------------------------------------===// |
| 1882 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1883 | /// \brief Write a record containing the given attributes. |
| 1884 | void PCHWriter::WriteAttributeRecord(const Attr *Attr) { |
| 1885 | RecordData Record; |
| 1886 | for (; Attr; Attr = Attr->getNext()) { |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 1887 | Record.push_back(Attr->getKind()); // FIXME: stable encoding, target attrs |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1888 | Record.push_back(Attr->isInherited()); |
| 1889 | switch (Attr->getKind()) { |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 1890 | default: |
| 1891 | assert(0 && "Does not support PCH writing for this attribute yet!"); |
| 1892 | break; |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1893 | case attr::Alias: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1894 | AddString(cast<AliasAttr>(Attr)->getAliasee(), Record); |
| 1895 | break; |
| 1896 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1897 | case attr::AlignMac68k: |
Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 1898 | break; |
| 1899 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1900 | case attr::Aligned: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1901 | Record.push_back(cast<AlignedAttr>(Attr)->getAlignment()); |
| 1902 | break; |
| 1903 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1904 | case attr::AlwaysInline: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1905 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1906 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1907 | case attr::AnalyzerNoReturn: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1908 | break; |
| 1909 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1910 | case attr::Annotate: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1911 | AddString(cast<AnnotateAttr>(Attr)->getAnnotation(), Record); |
| 1912 | break; |
| 1913 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1914 | case attr::AsmLabel: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1915 | AddString(cast<AsmLabelAttr>(Attr)->getLabel(), Record); |
| 1916 | break; |
| 1917 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1918 | case attr::BaseCheck: |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1919 | break; |
| 1920 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1921 | case attr::Blocks: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1922 | Record.push_back(cast<BlocksAttr>(Attr)->getType()); // FIXME: stable |
| 1923 | break; |
| 1924 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1925 | case attr::CDecl: |
Eli Friedman | 8f4c59e | 2009-11-09 18:38:53 +0000 | [diff] [blame] | 1926 | break; |
| 1927 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1928 | case attr::Cleanup: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1929 | AddDeclRef(cast<CleanupAttr>(Attr)->getFunctionDecl(), Record); |
| 1930 | break; |
| 1931 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1932 | case attr::Const: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1933 | break; |
| 1934 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1935 | case attr::Constructor: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1936 | Record.push_back(cast<ConstructorAttr>(Attr)->getPriority()); |
| 1937 | break; |
| 1938 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1939 | case attr::DLLExport: |
| 1940 | case attr::DLLImport: |
| 1941 | case attr::Deprecated: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1942 | break; |
| 1943 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1944 | case attr::Destructor: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1945 | Record.push_back(cast<DestructorAttr>(Attr)->getPriority()); |
| 1946 | break; |
| 1947 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1948 | case attr::FastCall: |
| 1949 | case attr::Final: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1950 | break; |
| 1951 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1952 | case attr::Format: { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1953 | const FormatAttr *Format = cast<FormatAttr>(Attr); |
| 1954 | AddString(Format->getType(), Record); |
| 1955 | Record.push_back(Format->getFormatIdx()); |
| 1956 | Record.push_back(Format->getFirstArg()); |
| 1957 | break; |
| 1958 | } |
| 1959 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1960 | case attr::FormatArg: { |
Fariborz Jahanian | 5b16092 | 2009-05-20 17:41:43 +0000 | [diff] [blame] | 1961 | const FormatArgAttr *Format = cast<FormatArgAttr>(Attr); |
| 1962 | Record.push_back(Format->getFormatIdx()); |
| 1963 | break; |
| 1964 | } |
| 1965 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1966 | case attr::Sentinel : { |
Fariborz Jahanian | 5b53005 | 2009-05-13 18:09:35 +0000 | [diff] [blame] | 1967 | const SentinelAttr *Sentinel = cast<SentinelAttr>(Attr); |
| 1968 | Record.push_back(Sentinel->getSentinel()); |
| 1969 | Record.push_back(Sentinel->getNullPos()); |
| 1970 | break; |
| 1971 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1973 | case attr::GNUInline: |
| 1974 | case attr::Hiding: |
| 1975 | case attr::IBAction: |
| 1976 | case attr::IBOutlet: |
| 1977 | case attr::Malloc: |
| 1978 | case attr::NoDebug: |
| 1979 | case attr::NoInline: |
| 1980 | case attr::NoReturn: |
| 1981 | case attr::NoThrow: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1982 | break; |
| 1983 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1984 | case attr::IBOutletCollection: { |
Ted Kremenek | 857e918 | 2010-05-19 17:38:06 +0000 | [diff] [blame] | 1985 | const IBOutletCollectionAttr *ICA = cast<IBOutletCollectionAttr>(Attr); |
| 1986 | AddDeclRef(ICA->getClass(), Record); |
| 1987 | break; |
| 1988 | } |
| 1989 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1990 | case attr::NonNull: { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1991 | const NonNullAttr *NonNull = cast<NonNullAttr>(Attr); |
| 1992 | Record.push_back(NonNull->size()); |
| 1993 | Record.insert(Record.end(), NonNull->begin(), NonNull->end()); |
| 1994 | break; |
| 1995 | } |
| 1996 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 1997 | case attr::CFReturnsNotRetained: |
| 1998 | case attr::CFReturnsRetained: |
| 1999 | case attr::NSReturnsNotRetained: |
| 2000 | case attr::NSReturnsRetained: |
| 2001 | case attr::ObjCException: |
| 2002 | case attr::ObjCNSObject: |
| 2003 | case attr::Overloadable: |
| 2004 | case attr::Override: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2005 | break; |
| 2006 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2007 | case attr::MaxFieldAlignment: |
Daniel Dunbar | 8a2c92c | 2010-05-27 01:12:46 +0000 | [diff] [blame] | 2008 | Record.push_back(cast<MaxFieldAlignmentAttr>(Attr)->getAlignment()); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2009 | break; |
| 2010 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2011 | case attr::Packed: |
Anders Carlsson | a860e75 | 2009-08-08 18:23:56 +0000 | [diff] [blame] | 2012 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2013 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2014 | case attr::Pure: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2015 | break; |
| 2016 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2017 | case attr::Regparm: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2018 | Record.push_back(cast<RegparmAttr>(Attr)->getNumParams()); |
| 2019 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2020 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2021 | case attr::ReqdWorkGroupSize: |
Nate Begeman | 6f3d838 | 2009-06-26 06:32:41 +0000 | [diff] [blame] | 2022 | Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getXDim()); |
| 2023 | Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getYDim()); |
| 2024 | Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getZDim()); |
| 2025 | break; |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2026 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2027 | case attr::Section: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2028 | AddString(cast<SectionAttr>(Attr)->getName(), Record); |
| 2029 | break; |
| 2030 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2031 | case attr::StdCall: |
| 2032 | case attr::TransparentUnion: |
| 2033 | case attr::Unavailable: |
| 2034 | case attr::Unused: |
| 2035 | case attr::Used: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2036 | break; |
| 2037 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2038 | case attr::Visibility: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2039 | // FIXME: stable encoding |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2040 | Record.push_back(cast<VisibilityAttr>(Attr)->getVisibility()); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2041 | break; |
| 2042 | |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 2043 | case attr::WarnUnusedResult: |
| 2044 | case attr::Weak: |
| 2045 | case attr::WeakRef: |
| 2046 | case attr::WeakImport: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2047 | break; |
| 2048 | } |
| 2049 | } |
| 2050 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2051 | Stream.EmitRecord(pch::DECL_ATTR, Record); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | void PCHWriter::AddString(const std::string &Str, RecordData &Record) { |
| 2055 | Record.push_back(Str.size()); |
| 2056 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 2057 | } |
| 2058 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2059 | /// \brief Note that the identifier II occurs at the given offset |
| 2060 | /// within the identifier table. |
| 2061 | void PCHWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2062 | IdentifierOffsets[IdentifierIDs[II] - 1] = Offset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2065 | /// \brief Note that the selector Sel occurs at the given offset |
| 2066 | /// within the method pool/selector table. |
| 2067 | void PCHWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
| 2068 | unsigned ID = SelectorIDs[Sel]; |
| 2069 | assert(ID && "Unknown selector"); |
| 2070 | SelectorOffsets[ID - 1] = Offset; |
| 2071 | } |
| 2072 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2073 | PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream) |
| 2074 | : Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2075 | CollectedStmts(&StmtsToEmit), NumStatements(0), NumMacros(0), |
| 2076 | NumLexicalDeclContexts(0), NumVisibleDeclContexts(0) { } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2077 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2078 | void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Sebastian Redl | a93e3b5 | 2010-07-08 22:01:51 +0000 | [diff] [blame^] | 2079 | const PCHReader *Chain, const char *isysroot) { |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2080 | using namespace llvm; |
| 2081 | |
Douglas Gregor | e778504 | 2009-04-20 15:53:59 +0000 | [diff] [blame] | 2082 | ASTContext &Context = SemaRef.Context; |
| 2083 | Preprocessor &PP = SemaRef.PP; |
| 2084 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2085 | // Emit the file header. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2086 | Stream.Emit((unsigned)'C', 8); |
| 2087 | Stream.Emit((unsigned)'P', 8); |
| 2088 | Stream.Emit((unsigned)'C', 8); |
| 2089 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2090 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 2091 | WriteBlockInfoBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2092 | |
| 2093 | // The translation unit is the first declaration we'll emit. |
| 2094 | DeclIDs[Context.getTranslationUnitDecl()] = 1; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2095 | DeclTypesToEmit.push(Context.getTranslationUnitDecl()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2096 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2097 | // Make sure that we emit IdentifierInfos (and any attached |
| 2098 | // declarations) for builtins. |
| 2099 | { |
| 2100 | IdentifierTable &Table = PP.getIdentifierTable(); |
| 2101 | llvm::SmallVector<const char *, 32> BuiltinNames; |
| 2102 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
| 2103 | Context.getLangOptions().NoBuiltin); |
| 2104 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 2105 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 2106 | } |
| 2107 | |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2108 | // Build a record containing all of the tentative definitions in this file, in |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 2109 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2110 | // headers. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2111 | RecordData TentativeDefinitions; |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 2112 | for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) { |
| 2113 | AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions); |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2114 | } |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2115 | |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2116 | // Build a record containing all of the static unused functions in this file. |
| 2117 | RecordData UnusedStaticFuncs; |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2118 | for (unsigned i=0, e = SemaRef.UnusedStaticFuncs.size(); i !=e; ++i) |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2119 | AddDeclRef(SemaRef.UnusedStaticFuncs[i], UnusedStaticFuncs); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2120 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2121 | // Build a record containing all of the locally-scoped external |
| 2122 | // declarations in this header file. Generally, this record will be |
| 2123 | // empty. |
| 2124 | RecordData LocallyScopedExternalDecls; |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2125 | // FIXME: This is filling in the PCH file in densemap order which is |
| 2126 | // nondeterminstic! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2127 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2128 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 2129 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
| 2130 | TD != TDEnd; ++TD) |
| 2131 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 2132 | |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2133 | // Build a record containing all of the ext_vector declarations. |
| 2134 | RecordData ExtVectorDecls; |
| 2135 | for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) |
| 2136 | AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls); |
| 2137 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2138 | // Build a record containing all of the VTable uses information. |
| 2139 | RecordData VTableUses; |
| 2140 | VTableUses.push_back(SemaRef.VTableUses.size()); |
| 2141 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 2142 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 2143 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 2144 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 2145 | } |
| 2146 | |
| 2147 | // Build a record containing all of dynamic classes declarations. |
| 2148 | RecordData DynamicClasses; |
| 2149 | for (unsigned I = 0, N = SemaRef.DynamicClasses.size(); I != N; ++I) |
| 2150 | AddDeclRef(SemaRef.DynamicClasses[I], DynamicClasses); |
| 2151 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2152 | // Write the remaining PCH contents. |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2153 | RecordData Record; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2154 | Stream.EnterSubblock(pch::PCH_BLOCK_ID, 5); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2155 | WriteMetadata(Context, isysroot); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2156 | WriteLanguageOptions(Context.getLangOptions()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2157 | if (StatCalls && !isysroot) |
| 2158 | WriteStatCache(*StatCalls, isysroot); |
| 2159 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 2160 | // Write the record of special types. |
| 2161 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2162 | |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 2163 | AddTypeRef(Context.getBuiltinVaListType(), Record); |
| 2164 | AddTypeRef(Context.getObjCIdType(), Record); |
| 2165 | AddTypeRef(Context.getObjCSelType(), Record); |
| 2166 | AddTypeRef(Context.getObjCProtoType(), Record); |
| 2167 | AddTypeRef(Context.getObjCClassType(), Record); |
| 2168 | AddTypeRef(Context.getRawCFConstantStringType(), Record); |
| 2169 | AddTypeRef(Context.getRawObjCFastEnumerationStateType(), Record); |
| 2170 | AddTypeRef(Context.getFILEType(), Record); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2171 | AddTypeRef(Context.getjmp_bufType(), Record); |
| 2172 | AddTypeRef(Context.getsigjmp_bufType(), Record); |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2173 | AddTypeRef(Context.ObjCIdRedefinitionType, Record); |
| 2174 | AddTypeRef(Context.ObjCClassRedefinitionType, Record); |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2175 | AddTypeRef(Context.getRawBlockdescriptorType(), Record); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2176 | AddTypeRef(Context.getRawBlockdescriptorExtendedType(), Record); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2177 | AddTypeRef(Context.ObjCSelRedefinitionType, Record); |
| 2178 | AddTypeRef(Context.getRawNSConstantStringType(), Record); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2179 | Record.push_back(Context.isInt128Installed()); |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 2180 | Stream.EmitRecord(pch::SPECIAL_TYPES, Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2181 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2182 | // Keep writing types and declarations until all types and |
| 2183 | // declarations have been written. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2184 | Stream.EnterSubblock(pch::DECLTYPES_BLOCK_ID, 3); |
| 2185 | WriteDeclsBlockAbbrevs(); |
| 2186 | while (!DeclTypesToEmit.empty()) { |
| 2187 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 2188 | DeclTypesToEmit.pop(); |
| 2189 | if (DOT.isType()) |
| 2190 | WriteType(DOT.getType()); |
| 2191 | else |
| 2192 | WriteDecl(Context, DOT.getDecl()); |
| 2193 | } |
| 2194 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2195 | |
Douglas Gregor | 813a97b | 2009-10-17 17:25:45 +0000 | [diff] [blame] | 2196 | WritePreprocessor(PP); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2197 | WriteMethodPool(SemaRef); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2198 | WriteIdentifierTable(PP); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2199 | |
| 2200 | // Write the type offsets array |
| 2201 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2202 | Abbrev->Add(BitCodeAbbrevOp(pch::TYPE_OFFSET)); |
| 2203 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
| 2204 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2205 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2206 | Record.clear(); |
| 2207 | Record.push_back(pch::TYPE_OFFSET); |
| 2208 | Record.push_back(TypeOffsets.size()); |
| 2209 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2210 | (const char *)&TypeOffsets.front(), |
Chris Lattner | c732f5a | 2009-04-27 18:24:17 +0000 | [diff] [blame] | 2211 | TypeOffsets.size() * sizeof(TypeOffsets[0])); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2213 | // Write the declaration offsets array |
| 2214 | Abbrev = new BitCodeAbbrev(); |
| 2215 | Abbrev->Add(BitCodeAbbrevOp(pch::DECL_OFFSET)); |
| 2216 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
| 2217 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2218 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2219 | Record.clear(); |
| 2220 | Record.push_back(pch::DECL_OFFSET); |
| 2221 | Record.push_back(DeclOffsets.size()); |
| 2222 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2223 | (const char *)&DeclOffsets.front(), |
Chris Lattner | c732f5a | 2009-04-27 18:24:17 +0000 | [diff] [blame] | 2224 | DeclOffsets.size() * sizeof(DeclOffsets[0])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2225 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2226 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2227 | if (!ExternalDefinitions.empty()) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2228 | Stream.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2229 | |
| 2230 | // Write the record containing tentative definitions. |
| 2231 | if (!TentativeDefinitions.empty()) |
| 2232 | Stream.EmitRecord(pch::TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2233 | |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2234 | // Write the record containing unused static functions. |
| 2235 | if (!UnusedStaticFuncs.empty()) |
| 2236 | Stream.EmitRecord(pch::UNUSED_STATIC_FUNCS, UnusedStaticFuncs); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2237 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2238 | // Write the record containing locally-scoped external definitions. |
| 2239 | if (!LocallyScopedExternalDecls.empty()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2240 | Stream.EmitRecord(pch::LOCALLY_SCOPED_EXTERNAL_DECLS, |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2241 | LocallyScopedExternalDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2242 | |
| 2243 | // Write the record containing ext_vector type names. |
| 2244 | if (!ExtVectorDecls.empty()) |
| 2245 | Stream.EmitRecord(pch::EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2246 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2247 | // Write the record containing VTable uses information. |
| 2248 | if (!VTableUses.empty()) |
| 2249 | Stream.EmitRecord(pch::VTABLE_USES, VTableUses); |
| 2250 | |
| 2251 | // Write the record containing dynamic classes declarations. |
| 2252 | if (!DynamicClasses.empty()) |
| 2253 | Stream.EmitRecord(pch::DYNAMIC_CLASSES, DynamicClasses); |
| 2254 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2255 | // Some simple statistics |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2256 | Record.clear(); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2257 | Record.push_back(NumStatements); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2258 | Record.push_back(NumMacros); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2259 | Record.push_back(NumLexicalDeclContexts); |
| 2260 | Record.push_back(NumVisibleDeclContexts); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2261 | Stream.EmitRecord(pch::STATISTICS, Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2262 | Stream.ExitBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | void PCHWriter::AddSourceLocation(SourceLocation Loc, RecordData &Record) { |
| 2266 | Record.push_back(Loc.getRawEncoding()); |
| 2267 | } |
| 2268 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2269 | void PCHWriter::AddSourceRange(SourceRange Range, RecordData &Record) { |
| 2270 | AddSourceLocation(Range.getBegin(), Record); |
| 2271 | AddSourceLocation(Range.getEnd(), Record); |
| 2272 | } |
| 2273 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2274 | void PCHWriter::AddAPInt(const llvm::APInt &Value, RecordData &Record) { |
| 2275 | Record.push_back(Value.getBitWidth()); |
| 2276 | unsigned N = Value.getNumWords(); |
| 2277 | const uint64_t* Words = Value.getRawData(); |
| 2278 | for (unsigned I = 0; I != N; ++I) |
| 2279 | Record.push_back(Words[I]); |
| 2280 | } |
| 2281 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2282 | void PCHWriter::AddAPSInt(const llvm::APSInt &Value, RecordData &Record) { |
| 2283 | Record.push_back(Value.isUnsigned()); |
| 2284 | AddAPInt(Value, Record); |
| 2285 | } |
| 2286 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2287 | void PCHWriter::AddAPFloat(const llvm::APFloat &Value, RecordData &Record) { |
| 2288 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 2289 | } |
| 2290 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2291 | void PCHWriter::AddIdentifierRef(const IdentifierInfo *II, RecordData &Record) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2292 | Record.push_back(getIdentifierRef(II)); |
| 2293 | } |
| 2294 | |
| 2295 | pch::IdentID PCHWriter::getIdentifierRef(const IdentifierInfo *II) { |
| 2296 | if (II == 0) |
| 2297 | return 0; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2298 | |
| 2299 | pch::IdentID &ID = IdentifierIDs[II]; |
| 2300 | if (ID == 0) |
| 2301 | ID = IdentifierIDs.size(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2302 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2305 | pch::IdentID PCHWriter::getMacroDefinitionID(MacroDefinition *MD) { |
| 2306 | if (MD == 0) |
| 2307 | return 0; |
| 2308 | |
| 2309 | pch::IdentID &ID = MacroDefinitions[MD]; |
| 2310 | if (ID == 0) |
| 2311 | ID = MacroDefinitions.size(); |
| 2312 | return ID; |
| 2313 | } |
| 2314 | |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2315 | void PCHWriter::AddSelectorRef(const Selector SelRef, RecordData &Record) { |
| 2316 | if (SelRef.getAsOpaquePtr() == 0) { |
| 2317 | Record.push_back(0); |
| 2318 | return; |
| 2319 | } |
| 2320 | |
| 2321 | pch::SelectorID &SID = SelectorIDs[SelRef]; |
| 2322 | if (SID == 0) { |
| 2323 | SID = SelectorIDs.size(); |
| 2324 | SelVector.push_back(SelRef); |
| 2325 | } |
| 2326 | Record.push_back(SID); |
| 2327 | } |
| 2328 | |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 2329 | void PCHWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordData &Record) { |
| 2330 | AddDeclRef(Temp->getDestructor(), Record); |
| 2331 | } |
| 2332 | |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 2333 | void PCHWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
| 2334 | const TemplateArgumentLocInfo &Arg, |
| 2335 | RecordData &Record) { |
| 2336 | switch (Kind) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2337 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 2338 | AddStmt(Arg.getAsExpr()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2339 | break; |
| 2340 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 2341 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2342 | break; |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2343 | case TemplateArgument::Template: |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 2344 | AddSourceRange(Arg.getTemplateQualifierRange(), Record); |
| 2345 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2346 | break; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2347 | case TemplateArgument::Null: |
| 2348 | case TemplateArgument::Integral: |
| 2349 | case TemplateArgument::Declaration: |
| 2350 | case TemplateArgument::Pack: |
| 2351 | break; |
| 2352 | } |
| 2353 | } |
| 2354 | |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 2355 | void PCHWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
| 2356 | RecordData &Record) { |
| 2357 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 2358 | |
| 2359 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 2360 | bool InfoHasSameExpr |
| 2361 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 2362 | Record.push_back(InfoHasSameExpr); |
| 2363 | if (InfoHasSameExpr) |
| 2364 | return; // Avoid storing the same expr twice. |
| 2365 | } |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 2366 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 2367 | Record); |
| 2368 | } |
| 2369 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2370 | void PCHWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordData &Record) { |
| 2371 | if (TInfo == 0) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2372 | AddTypeRef(QualType(), Record); |
| 2373 | return; |
| 2374 | } |
| 2375 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2376 | AddTypeRef(TInfo->getType(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2377 | TypeLocWriter TLW(*this, Record); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2378 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2379 | TLW.Visit(TL); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2382 | void PCHWriter::AddTypeRef(QualType T, RecordData &Record) { |
| 2383 | if (T.isNull()) { |
| 2384 | Record.push_back(pch::PREDEF_TYPE_NULL_ID); |
| 2385 | return; |
| 2386 | } |
| 2387 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2388 | unsigned FastQuals = T.getLocalFastQualifiers(); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2389 | T.removeFastQualifiers(); |
| 2390 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2391 | if (T.hasLocalNonFastQualifiers()) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2392 | pch::TypeID &ID = TypeIDs[T]; |
| 2393 | if (ID == 0) { |
| 2394 | // We haven't seen these qualifiers applied to this type before. |
| 2395 | // Assign it a new ID. This is the only time we enqueue a |
| 2396 | // qualified type, and it has no CV qualifiers. |
| 2397 | ID = NextTypeID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2398 | DeclTypesToEmit.push(T); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2399 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2400 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2401 | // Encode the type qualifiers in the type reference. |
| 2402 | Record.push_back((ID << Qualifiers::FastWidth) | FastQuals); |
| 2403 | return; |
| 2404 | } |
| 2405 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2406 | assert(!T.hasLocalQualifiers()); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2407 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2408 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr())) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2409 | pch::TypeID ID = 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2410 | switch (BT->getKind()) { |
| 2411 | case BuiltinType::Void: ID = pch::PREDEF_TYPE_VOID_ID; break; |
| 2412 | case BuiltinType::Bool: ID = pch::PREDEF_TYPE_BOOL_ID; break; |
| 2413 | case BuiltinType::Char_U: ID = pch::PREDEF_TYPE_CHAR_U_ID; break; |
| 2414 | case BuiltinType::UChar: ID = pch::PREDEF_TYPE_UCHAR_ID; break; |
| 2415 | case BuiltinType::UShort: ID = pch::PREDEF_TYPE_USHORT_ID; break; |
| 2416 | case BuiltinType::UInt: ID = pch::PREDEF_TYPE_UINT_ID; break; |
| 2417 | case BuiltinType::ULong: ID = pch::PREDEF_TYPE_ULONG_ID; break; |
| 2418 | case BuiltinType::ULongLong: ID = pch::PREDEF_TYPE_ULONGLONG_ID; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 2419 | case BuiltinType::UInt128: ID = pch::PREDEF_TYPE_UINT128_ID; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2420 | case BuiltinType::Char_S: ID = pch::PREDEF_TYPE_CHAR_S_ID; break; |
| 2421 | case BuiltinType::SChar: ID = pch::PREDEF_TYPE_SCHAR_ID; break; |
| 2422 | case BuiltinType::WChar: ID = pch::PREDEF_TYPE_WCHAR_ID; break; |
| 2423 | case BuiltinType::Short: ID = pch::PREDEF_TYPE_SHORT_ID; break; |
| 2424 | case BuiltinType::Int: ID = pch::PREDEF_TYPE_INT_ID; break; |
| 2425 | case BuiltinType::Long: ID = pch::PREDEF_TYPE_LONG_ID; break; |
| 2426 | case BuiltinType::LongLong: ID = pch::PREDEF_TYPE_LONGLONG_ID; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 2427 | case BuiltinType::Int128: ID = pch::PREDEF_TYPE_INT128_ID; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2428 | case BuiltinType::Float: ID = pch::PREDEF_TYPE_FLOAT_ID; break; |
| 2429 | case BuiltinType::Double: ID = pch::PREDEF_TYPE_DOUBLE_ID; break; |
| 2430 | case BuiltinType::LongDouble: ID = pch::PREDEF_TYPE_LONGDOUBLE_ID; break; |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 2431 | case BuiltinType::NullPtr: ID = pch::PREDEF_TYPE_NULLPTR_ID; break; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 2432 | case BuiltinType::Char16: ID = pch::PREDEF_TYPE_CHAR16_ID; break; |
| 2433 | case BuiltinType::Char32: ID = pch::PREDEF_TYPE_CHAR32_ID; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2434 | case BuiltinType::Overload: ID = pch::PREDEF_TYPE_OVERLOAD_ID; break; |
| 2435 | case BuiltinType::Dependent: ID = pch::PREDEF_TYPE_DEPENDENT_ID; break; |
Steve Naroff | de2e22d | 2009-07-15 18:40:39 +0000 | [diff] [blame] | 2436 | case BuiltinType::ObjCId: ID = pch::PREDEF_TYPE_OBJC_ID; break; |
| 2437 | case BuiltinType::ObjCClass: ID = pch::PREDEF_TYPE_OBJC_CLASS; break; |
Fariborz Jahanian | 13dcd00 | 2009-11-21 19:53:08 +0000 | [diff] [blame] | 2438 | case BuiltinType::ObjCSel: ID = pch::PREDEF_TYPE_OBJC_SEL; break; |
Anders Carlsson | e89d159 | 2009-06-26 18:41:36 +0000 | [diff] [blame] | 2439 | case BuiltinType::UndeducedAuto: |
| 2440 | assert(0 && "Should not see undeduced auto here"); |
| 2441 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2444 | Record.push_back((ID << Qualifiers::FastWidth) | FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2445 | return; |
| 2446 | } |
| 2447 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2448 | pch::TypeID &ID = TypeIDs[T]; |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2449 | if (ID == 0) { |
| 2450 | // We haven't seen this type before. Assign it a new ID and put it |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2451 | // into the queue of types to emit. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2452 | ID = NextTypeID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2453 | DeclTypesToEmit.push(T); |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2454 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2455 | |
| 2456 | // Encode the type qualifiers in the type reference. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2457 | Record.push_back((ID << Qualifiers::FastWidth) | FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | void PCHWriter::AddDeclRef(const Decl *D, RecordData &Record) { |
| 2461 | if (D == 0) { |
| 2462 | Record.push_back(0); |
| 2463 | return; |
| 2464 | } |
| 2465 | |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2466 | pch::DeclID &ID = DeclIDs[D]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2467 | if (ID == 0) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2468 | // We haven't seen this declaration before. Give it a new ID and |
| 2469 | // enqueue it in the list of declarations to emit. |
| 2470 | ID = DeclIDs.size(); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2471 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | Record.push_back(ID); |
| 2475 | } |
| 2476 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2477 | pch::DeclID PCHWriter::getDeclID(const Decl *D) { |
| 2478 | if (D == 0) |
| 2479 | return 0; |
| 2480 | |
| 2481 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 2482 | return DeclIDs[D]; |
| 2483 | } |
| 2484 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2485 | void PCHWriter::AddDeclarationName(DeclarationName Name, RecordData &Record) { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 2486 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2487 | Record.push_back(Name.getNameKind()); |
| 2488 | switch (Name.getNameKind()) { |
| 2489 | case DeclarationName::Identifier: |
| 2490 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 2491 | break; |
| 2492 | |
| 2493 | case DeclarationName::ObjCZeroArgSelector: |
| 2494 | case DeclarationName::ObjCOneArgSelector: |
| 2495 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2496 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2497 | break; |
| 2498 | |
| 2499 | case DeclarationName::CXXConstructorName: |
| 2500 | case DeclarationName::CXXDestructorName: |
| 2501 | case DeclarationName::CXXConversionFunctionName: |
| 2502 | AddTypeRef(Name.getCXXNameType(), Record); |
| 2503 | break; |
| 2504 | |
| 2505 | case DeclarationName::CXXOperatorName: |
| 2506 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 2507 | break; |
| 2508 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2509 | case DeclarationName::CXXLiteralOperatorName: |
| 2510 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 2511 | break; |
| 2512 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2513 | case DeclarationName::CXXUsingDirective: |
| 2514 | // No extra data to emit |
| 2515 | break; |
| 2516 | } |
| 2517 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2518 | |
| 2519 | void PCHWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
| 2520 | RecordData &Record) { |
| 2521 | // Nested name specifiers usually aren't too long. I think that 8 would |
| 2522 | // typically accomodate the vast majority. |
| 2523 | llvm::SmallVector<NestedNameSpecifier *, 8> NestedNames; |
| 2524 | |
| 2525 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 2526 | while (NNS) { |
| 2527 | NestedNames.push_back(NNS); |
| 2528 | NNS = NNS->getPrefix(); |
| 2529 | } |
| 2530 | |
| 2531 | Record.push_back(NestedNames.size()); |
| 2532 | while(!NestedNames.empty()) { |
| 2533 | NNS = NestedNames.pop_back_val(); |
| 2534 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 2535 | Record.push_back(Kind); |
| 2536 | switch (Kind) { |
| 2537 | case NestedNameSpecifier::Identifier: |
| 2538 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 2539 | break; |
| 2540 | |
| 2541 | case NestedNameSpecifier::Namespace: |
| 2542 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 2543 | break; |
| 2544 | |
| 2545 | case NestedNameSpecifier::TypeSpec: |
| 2546 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2547 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 2548 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 2549 | break; |
| 2550 | |
| 2551 | case NestedNameSpecifier::Global: |
| 2552 | // Don't need to write an associated value. |
| 2553 | break; |
| 2554 | } |
| 2555 | } |
| 2556 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 2557 | |
| 2558 | void PCHWriter::AddTemplateName(TemplateName Name, RecordData &Record) { |
| 2559 | TemplateName::NameKind Kind = Name.getKind(); |
| 2560 | Record.push_back(Kind); |
| 2561 | switch (Kind) { |
| 2562 | case TemplateName::Template: |
| 2563 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 2564 | break; |
| 2565 | |
| 2566 | case TemplateName::OverloadedTemplate: { |
| 2567 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 2568 | Record.push_back(OvT->size()); |
| 2569 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 2570 | I != E; ++I) |
| 2571 | AddDeclRef(*I, Record); |
| 2572 | break; |
| 2573 | } |
| 2574 | |
| 2575 | case TemplateName::QualifiedTemplate: { |
| 2576 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 2577 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 2578 | Record.push_back(QualT->hasTemplateKeyword()); |
| 2579 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 2580 | break; |
| 2581 | } |
| 2582 | |
| 2583 | case TemplateName::DependentTemplate: { |
| 2584 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 2585 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 2586 | Record.push_back(DepT->isIdentifier()); |
| 2587 | if (DepT->isIdentifier()) |
| 2588 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 2589 | else |
| 2590 | Record.push_back(DepT->getOperator()); |
| 2591 | break; |
| 2592 | } |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | void PCHWriter::AddTemplateArgument(const TemplateArgument &Arg, |
| 2597 | RecordData &Record) { |
| 2598 | Record.push_back(Arg.getKind()); |
| 2599 | switch (Arg.getKind()) { |
| 2600 | case TemplateArgument::Null: |
| 2601 | break; |
| 2602 | case TemplateArgument::Type: |
| 2603 | AddTypeRef(Arg.getAsType(), Record); |
| 2604 | break; |
| 2605 | case TemplateArgument::Declaration: |
| 2606 | AddDeclRef(Arg.getAsDecl(), Record); |
| 2607 | break; |
| 2608 | case TemplateArgument::Integral: |
| 2609 | AddAPSInt(*Arg.getAsIntegral(), Record); |
| 2610 | AddTypeRef(Arg.getIntegralType(), Record); |
| 2611 | break; |
| 2612 | case TemplateArgument::Template: |
| 2613 | AddTemplateName(Arg.getAsTemplate(), Record); |
| 2614 | break; |
| 2615 | case TemplateArgument::Expression: |
| 2616 | AddStmt(Arg.getAsExpr()); |
| 2617 | break; |
| 2618 | case TemplateArgument::Pack: |
| 2619 | Record.push_back(Arg.pack_size()); |
| 2620 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 2621 | I != E; ++I) |
| 2622 | AddTemplateArgument(*I, Record); |
| 2623 | break; |
| 2624 | } |
| 2625 | } |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2626 | |
| 2627 | void |
| 2628 | PCHWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
| 2629 | RecordData &Record) { |
| 2630 | assert(TemplateParams && "No TemplateParams!"); |
| 2631 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 2632 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 2633 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 2634 | Record.push_back(TemplateParams->size()); |
| 2635 | for (TemplateParameterList::const_iterator |
| 2636 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 2637 | P != PEnd; ++P) |
| 2638 | AddDeclRef(*P, Record); |
| 2639 | } |
| 2640 | |
| 2641 | /// \brief Emit a template argument list. |
| 2642 | void |
| 2643 | PCHWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
| 2644 | RecordData &Record) { |
| 2645 | assert(TemplateArgs && "No TemplateArgs!"); |
| 2646 | Record.push_back(TemplateArgs->flat_size()); |
| 2647 | for (int i=0, e = TemplateArgs->flat_size(); i != e; ++i) |
| 2648 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 2649 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 2650 | |
| 2651 | |
| 2652 | void |
| 2653 | PCHWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordData &Record) { |
| 2654 | Record.push_back(Set.size()); |
| 2655 | for (UnresolvedSetImpl::const_iterator |
| 2656 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 2657 | AddDeclRef(I.getDecl(), Record); |
| 2658 | Record.push_back(I.getAccess()); |
| 2659 | } |
| 2660 | } |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 2661 | |
| 2662 | void PCHWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
| 2663 | RecordData &Record) { |
| 2664 | Record.push_back(Base.isVirtual()); |
| 2665 | Record.push_back(Base.isBaseOfClass()); |
| 2666 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
| 2667 | AddTypeRef(Base.getType(), Record); |
| 2668 | AddSourceRange(Base.getSourceRange(), Record); |
| 2669 | } |