Sebastian Redl | d6522cf | 2010-08-18 23:56:31 +0000 | [diff] [blame] | 1 | //===--- ASTWriter.cpp - AST File Writer ----------------------------------===// |
Douglas Gregor | ef84c4b | 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 | // |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 10 | // This file defines the ASTWriter class, which writes AST files. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sebastian Redl | 1914c6f | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTWriter.h" |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 15 | #include "clang/Serialization/ASTSerializationListener.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 17 | #include "clang/Sema/Sema.h" |
| 18 | #include "clang/Sema/IdentifierResolver.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclContextInternals.h" |
John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclTemplate.h" |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclFriend.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 27 | #include "clang/AST/TypeLocVisitor.h" |
Sebastian Redl | f5b1346 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 28 | #include "clang/Serialization/ASTReader.h" |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 29 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 30 | #include "clang/Lex/PreprocessingRecord.h" |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 31 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 3fa455a | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 32 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 34 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 35 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 37 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 38 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 39 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 40 | #include "clang/Basic/VersionTuple.h" |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/APFloat.h" |
| 42 | #include "llvm/ADT/APInt.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 43 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 44 | #include "llvm/Bitcode/BitstreamWriter.h" |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 45 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 46 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 47 | #include "llvm/Support/Path.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 48 | #include <algorithm> |
Chris Lattner | 225dd6c | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 49 | #include <cstdio> |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 50 | #include <string.h> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 51 | #include <utility> |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 52 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 53 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 54 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 55 | template <typename T, typename Allocator> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 56 | static StringRef data(const std::vector<T, Allocator> &v) { |
| 57 | if (v.empty()) return StringRef(); |
| 58 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 59 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 60 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 61 | |
| 62 | template <typename T> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 63 | static StringRef data(const SmallVectorImpl<T> &v) { |
| 64 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 65 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 68 | //===----------------------------------------------------------------------===// |
| 69 | // Type serialization |
| 70 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 72 | namespace { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 73 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 74 | ASTWriter &Writer; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 75 | ASTWriter::RecordDataImpl &Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 76 | |
| 77 | public: |
| 78 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 79 | TypeCode Code; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 80 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 81 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 82 | : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 83 | |
| 84 | void VisitArrayType(const ArrayType *T); |
| 85 | void VisitFunctionType(const FunctionType *T); |
| 86 | void VisitTagType(const TagType *T); |
| 87 | |
| 88 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 89 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 90 | #include "clang/AST/TypeNodes.def" |
| 91 | }; |
| 92 | } |
| 93 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 94 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 95 | assert(false && "Built-in types are never serialized"); |
| 96 | } |
| 97 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 98 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 99 | Writer.AddTypeRef(T->getElementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 100 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 103 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 104 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 105 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 108 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 110 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 113 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 114 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
| 115 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 116 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 119 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 120 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 121 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 124 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 126 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 127 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 130 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 131 | Writer.AddTypeRef(T->getElementType(), Record); |
| 132 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 133 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 136 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 137 | VisitArrayType(T); |
| 138 | Writer.AddAPInt(T->getSize(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 139 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 142 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 143 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 144 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 147 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 148 | VisitArrayType(T); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 149 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 150 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 151 | Writer.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 152 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 155 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 156 | Writer.AddTypeRef(T->getElementType(), Record); |
| 157 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 158 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 159 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 162 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 163 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 164 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 167 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 168 | Writer.AddTypeRef(T->getResultType(), Record); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 169 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 170 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 171 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 172 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 173 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 174 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 175 | Record.push_back(C.getProducesResult()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 178 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 179 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 180 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 183 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 184 | VisitFunctionType(T); |
| 185 | Record.push_back(T->getNumArgs()); |
| 186 | for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) |
| 187 | Writer.AddTypeRef(T->getArgType(I), Record); |
| 188 | Record.push_back(T->isVariadic()); |
| 189 | Record.push_back(T->getTypeQuals()); |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 190 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 191 | Record.push_back(T->getExceptionSpecType()); |
| 192 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 193 | Record.push_back(T->getNumExceptions()); |
| 194 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 195 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 196 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 197 | Writer.AddStmt(T->getNoexceptExpr()); |
| 198 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 199 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 202 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 203 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 204 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 205 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 206 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 207 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 208 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 209 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 210 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 211 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 214 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 215 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 216 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 219 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 220 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 221 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 224 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 225 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 226 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 229 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 230 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 231 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 232 | Record.push_back(T->getUTTKind()); |
| 233 | Code = TYPE_UNARY_TRANSFORM; |
| 234 | } |
| 235 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 236 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 237 | Writer.AddTypeRef(T->getDeducedType(), Record); |
| 238 | Code = TYPE_AUTO; |
| 239 | } |
| 240 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 241 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 242 | Record.push_back(T->isDependentType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 243 | Writer.AddDeclRef(T->getDecl(), Record); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 245 | "Cannot serialize in the middle of a type definition"); |
| 246 | } |
| 247 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 248 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 249 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 250 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 253 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 254 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 255 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 256 | } |
| 257 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 258 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 259 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 260 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 261 | Record.push_back(T->getAttrKind()); |
| 262 | Code = TYPE_ATTRIBUTED; |
| 263 | } |
| 264 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 266 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 267 | const SubstTemplateTypeParmType *T) { |
| 268 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 269 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 270 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 274 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 275 | const SubstTemplateTypeParmPackType *T) { |
| 276 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 277 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 278 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 279 | } |
| 280 | |
| 281 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 282 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 283 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 284 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 285 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 286 | Record.push_back(T->getNumArgs()); |
| 287 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 288 | ArgI != ArgE; ++ArgI) |
| 289 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 290 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 291 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 292 | : T->getCanonicalTypeInternal(), |
| 293 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 294 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 298 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 299 | VisitArrayType(T); |
| 300 | Writer.AddStmt(T->getSizeExpr()); |
| 301 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 302 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 306 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 307 | const DependentSizedExtVectorType *T) { |
| 308 | // FIXME: Serialize this type (C++ only) |
| 309 | assert(false && "Cannot serialize dependent sized extended vector types"); |
| 310 | } |
| 311 | |
| 312 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 313 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 314 | Record.push_back(T->getDepth()); |
| 315 | Record.push_back(T->getIndex()); |
| 316 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 317 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 318 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 322 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 323 | Record.push_back(T->getKeyword()); |
| 324 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 325 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 326 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 327 | : T->getCanonicalTypeInternal(), |
| 328 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 329 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 333 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 334 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 335 | Record.push_back(T->getKeyword()); |
| 336 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 337 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 338 | Record.push_back(T->getNumArgs()); |
| 339 | for (DependentTemplateSpecializationType::iterator |
| 340 | I = T->begin(), E = T->end(); I != E; ++I) |
| 341 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 342 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 345 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 346 | Writer.AddTypeRef(T->getPattern(), Record); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 347 | if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) |
| 348 | Record.push_back(*NumExpansions + 1); |
| 349 | else |
| 350 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 351 | Code = TYPE_PACK_EXPANSION; |
| 352 | } |
| 353 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 354 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 355 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 356 | Code = TYPE_PAREN; |
| 357 | } |
| 358 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 359 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 360 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 361 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 362 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 363 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 366 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 367 | Writer.AddDeclRef(T->getDecl(), Record); |
John McCall | 2408e32 | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 368 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 369 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 372 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 1c28331 | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 373 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 374 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 377 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 378 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 379 | Record.push_back(T->getNumProtocols()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 380 | for (ObjCObjectType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 4fc95aa | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 381 | E = T->qual_end(); I != E; ++I) |
| 382 | Writer.AddDeclRef(*I, Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 383 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 386 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 387 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 389 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 390 | } |
| 391 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 392 | namespace { |
| 393 | |
| 394 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 395 | ASTWriter &Writer; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 396 | ASTWriter::RecordDataImpl &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 397 | |
| 398 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 399 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 400 | : Writer(Writer), Record(Record) { } |
| 401 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 402 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 403 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 404 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 405 | #include "clang/AST/TypeLocNodes.def" |
| 406 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 407 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 408 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | } |
| 412 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 413 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 414 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 415 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 416 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 417 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 418 | if (TL.needsExtraLocalData()) { |
| 419 | Record.push_back(TL.getWrittenTypeSpec()); |
| 420 | Record.push_back(TL.getWrittenSignSpec()); |
| 421 | Record.push_back(TL.getWrittenWidthSpec()); |
| 422 | Record.push_back(TL.hasModeAttr()); |
| 423 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 424 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 425 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 426 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 427 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 428 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 429 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 430 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 431 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 432 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 433 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 434 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 435 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 436 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 437 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 438 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 439 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 440 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 441 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 442 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 443 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 444 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 445 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 446 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 447 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 448 | if (TL.getSizeExpr()) |
| 449 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 450 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 451 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 452 | VisitArrayTypeLoc(TL); |
| 453 | } |
| 454 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 455 | VisitArrayTypeLoc(TL); |
| 456 | } |
| 457 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 458 | VisitArrayTypeLoc(TL); |
| 459 | } |
| 460 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 461 | DependentSizedArrayTypeLoc TL) { |
| 462 | VisitArrayTypeLoc(TL); |
| 463 | } |
| 464 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 465 | DependentSizedExtVectorTypeLoc TL) { |
| 466 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 467 | } |
| 468 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 469 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 470 | } |
| 471 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 472 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 473 | } |
| 474 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 475 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
| 476 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 477 | Record.push_back(TL.getTrailingReturn()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 478 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 479 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 480 | } |
| 481 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 482 | VisitFunctionTypeLoc(TL); |
| 483 | } |
| 484 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 485 | VisitFunctionTypeLoc(TL); |
| 486 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 487 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 488 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 489 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 490 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 491 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 492 | } |
| 493 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 494 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 495 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 496 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 497 | } |
| 498 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 499 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 500 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 501 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 502 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 503 | } |
| 504 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 505 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 506 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 507 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 508 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 509 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 510 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 511 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 512 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 513 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 514 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 515 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 516 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 517 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 518 | } |
| 519 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 520 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 521 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 522 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 523 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 524 | if (TL.hasAttrOperand()) { |
| 525 | SourceRange range = TL.getAttrOperandParensRange(); |
| 526 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 527 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 528 | } |
| 529 | if (TL.hasAttrExprOperand()) { |
| 530 | Expr *operand = TL.getAttrExprOperand(); |
| 531 | Record.push_back(operand ? 1 : 0); |
| 532 | if (operand) Writer.AddStmt(operand); |
| 533 | } else if (TL.hasAttrEnumOperand()) { |
| 534 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 535 | } |
| 536 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 537 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 538 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 539 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 540 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 541 | SubstTemplateTypeParmTypeLoc TL) { |
| 542 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 543 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 544 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 545 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 546 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 547 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 548 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 549 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 550 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 551 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 552 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 553 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 554 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 555 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 556 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 557 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 558 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 559 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 560 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 561 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 562 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 563 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 564 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 565 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 566 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 567 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 568 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 569 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 570 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 571 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 572 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 573 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 574 | DependentTemplateSpecializationTypeLoc TL) { |
| 575 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 576 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 577 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 578 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 579 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 580 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 581 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 582 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 583 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 584 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 585 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 586 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 587 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 588 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 589 | } |
| 590 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 591 | Record.push_back(TL.hasBaseTypeAsWritten()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 592 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 593 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 594 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 595 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 596 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 597 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 598 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 599 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 600 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 601 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 602 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 603 | //===----------------------------------------------------------------------===// |
| 604 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 605 | static void EmitBlockID(unsigned ID, const char *Name, |
| 606 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 607 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 608 | Record.clear(); |
| 609 | Record.push_back(ID); |
| 610 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 611 | |
| 612 | // Emit the block name if present. |
| 613 | if (Name == 0 || Name[0] == 0) return; |
| 614 | Record.clear(); |
| 615 | while (*Name) |
| 616 | Record.push_back(*Name++); |
| 617 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 618 | } |
| 619 | |
| 620 | static void EmitRecordID(unsigned ID, const char *Name, |
| 621 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 622 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 623 | Record.clear(); |
| 624 | Record.push_back(ID); |
| 625 | while (*Name) |
| 626 | Record.push_back(*Name++); |
| 627 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 631 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 632 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 633 | RECORD(STMT_STOP); |
| 634 | RECORD(STMT_NULL_PTR); |
| 635 | RECORD(STMT_NULL); |
| 636 | RECORD(STMT_COMPOUND); |
| 637 | RECORD(STMT_CASE); |
| 638 | RECORD(STMT_DEFAULT); |
| 639 | RECORD(STMT_LABEL); |
| 640 | RECORD(STMT_IF); |
| 641 | RECORD(STMT_SWITCH); |
| 642 | RECORD(STMT_WHILE); |
| 643 | RECORD(STMT_DO); |
| 644 | RECORD(STMT_FOR); |
| 645 | RECORD(STMT_GOTO); |
| 646 | RECORD(STMT_INDIRECT_GOTO); |
| 647 | RECORD(STMT_CONTINUE); |
| 648 | RECORD(STMT_BREAK); |
| 649 | RECORD(STMT_RETURN); |
| 650 | RECORD(STMT_DECL); |
| 651 | RECORD(STMT_ASM); |
| 652 | RECORD(EXPR_PREDEFINED); |
| 653 | RECORD(EXPR_DECL_REF); |
| 654 | RECORD(EXPR_INTEGER_LITERAL); |
| 655 | RECORD(EXPR_FLOATING_LITERAL); |
| 656 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 657 | RECORD(EXPR_STRING_LITERAL); |
| 658 | RECORD(EXPR_CHARACTER_LITERAL); |
| 659 | RECORD(EXPR_PAREN); |
| 660 | RECORD(EXPR_UNARY_OPERATOR); |
| 661 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 662 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 663 | RECORD(EXPR_CALL); |
| 664 | RECORD(EXPR_MEMBER); |
| 665 | RECORD(EXPR_BINARY_OPERATOR); |
| 666 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 667 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 668 | RECORD(EXPR_IMPLICIT_CAST); |
| 669 | RECORD(EXPR_CSTYLE_CAST); |
| 670 | RECORD(EXPR_COMPOUND_LITERAL); |
| 671 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 672 | RECORD(EXPR_INIT_LIST); |
| 673 | RECORD(EXPR_DESIGNATED_INIT); |
| 674 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 675 | RECORD(EXPR_VA_ARG); |
| 676 | RECORD(EXPR_ADDR_LABEL); |
| 677 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 678 | RECORD(EXPR_CHOOSE); |
| 679 | RECORD(EXPR_GNU_NULL); |
| 680 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 681 | RECORD(EXPR_BLOCK); |
| 682 | RECORD(EXPR_BLOCK_DECL_REF); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 683 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 684 | RECORD(EXPR_OBJC_STRING_LITERAL); |
| 685 | RECORD(EXPR_OBJC_ENCODE); |
| 686 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 687 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 688 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 689 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 690 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 691 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 692 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 693 | RECORD(STMT_OBJC_CATCH); |
| 694 | RECORD(STMT_OBJC_FINALLY); |
| 695 | RECORD(STMT_OBJC_AT_TRY); |
| 696 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 697 | RECORD(STMT_OBJC_AT_THROW); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 698 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 699 | RECORD(EXPR_CXX_CONSTRUCT); |
| 700 | RECORD(EXPR_CXX_STATIC_CAST); |
| 701 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 702 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 703 | RECORD(EXPR_CXX_CONST_CAST); |
| 704 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
| 705 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 706 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 707 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 708 | RECORD(EXPR_CXX_TYPEID_TYPE); |
| 709 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 710 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 711 | RECORD(EXPR_CXX_THIS); |
| 712 | RECORD(EXPR_CXX_THROW); |
| 713 | RECORD(EXPR_CXX_DEFAULT_ARG); |
| 714 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 715 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 716 | RECORD(EXPR_CXX_NEW); |
| 717 | RECORD(EXPR_CXX_DELETE); |
| 718 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 719 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 720 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 721 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 722 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 723 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 724 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
| 725 | RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); |
| 726 | RECORD(EXPR_CXX_NOEXCEPT); |
| 727 | RECORD(EXPR_OPAQUE_VALUE); |
| 728 | RECORD(EXPR_BINARY_TYPE_TRAIT); |
| 729 | RECORD(EXPR_PACK_EXPANSION); |
| 730 | RECORD(EXPR_SIZEOF_PACK); |
| 731 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 732 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 733 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 736 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 737 | RecordData Record; |
| 738 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 740 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 741 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 743 | // AST Top-Level Block. |
Sebastian Redl | f164204 | 2010-08-18 23:57:22 +0000 | [diff] [blame] | 744 | BLOCK(AST_BLOCK); |
Zhongxing Xu | b027cdf | 2009-06-03 09:23:28 +0000 | [diff] [blame] | 745 | RECORD(ORIGINAL_FILE_NAME); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 746 | RECORD(ORIGINAL_FILE_ID); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 747 | RECORD(TYPE_OFFSET); |
| 748 | RECORD(DECL_OFFSET); |
| 749 | RECORD(LANGUAGE_OPTIONS); |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 750 | RECORD(METADATA); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 751 | RECORD(IDENTIFIER_OFFSET); |
| 752 | RECORD(IDENTIFIER_TABLE); |
| 753 | RECORD(EXTERNAL_DEFINITIONS); |
| 754 | RECORD(SPECIAL_TYPES); |
| 755 | RECORD(STATISTICS); |
| 756 | RECORD(TENTATIVE_DEFINITIONS); |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 757 | RECORD(UNUSED_FILESCOPED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 758 | RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); |
| 759 | RECORD(SELECTOR_OFFSETS); |
| 760 | RECORD(METHOD_POOL); |
| 761 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 762 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 763 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 764 | RECORD(STAT_CACHE); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 765 | RECORD(EXT_VECTOR_DECLS); |
Ted Kremenek | 1743713 | 2010-01-22 20:59:36 +0000 | [diff] [blame] | 766 | RECORD(VERSION_CONTROL_BRANCH_REVISION); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 767 | RECORD(MACRO_DEFINITION_OFFSETS); |
Sebastian Redl | 595c513 | 2010-07-08 22:01:51 +0000 | [diff] [blame] | 768 | RECORD(CHAINED_METADATA); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 769 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 770 | RECORD(TU_UPDATE_LEXICAL); |
| 771 | RECORD(REDECLS_UPDATE_LATEST); |
| 772 | RECORD(SEMA_DECL_REFS); |
| 773 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 774 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 775 | RECORD(DECL_REPLACEMENTS); |
| 776 | RECORD(UPDATE_VISIBLE); |
| 777 | RECORD(DECL_UPDATE_OFFSETS); |
| 778 | RECORD(DECL_UPDATES); |
| 779 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 780 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 781 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 782 | RECORD(HEADER_SEARCH_TABLE); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 783 | RECORD(ORIGINAL_PCH_DIR); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 784 | RECORD(FP_PRAGMA_OPTIONS); |
| 785 | RECORD(OPENCL_EXTENSIONS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 786 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 787 | RECORD(FILE_SOURCE_LOCATION_OFFSETS); |
| 788 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 789 | RECORD(MODULE_OFFSET_MAP); |
| 790 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 791 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 792 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 793 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 794 | RECORD(SM_SLOC_FILE_ENTRY); |
| 795 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 796 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 797 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 799 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 800 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 801 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 802 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 803 | RECORD(PP_TOKEN); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 804 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 805 | // Decls and Types block. |
| 806 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 807 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 808 | RECORD(TYPE_COMPLEX); |
| 809 | RECORD(TYPE_POINTER); |
| 810 | RECORD(TYPE_BLOCK_POINTER); |
| 811 | RECORD(TYPE_LVALUE_REFERENCE); |
| 812 | RECORD(TYPE_RVALUE_REFERENCE); |
| 813 | RECORD(TYPE_MEMBER_POINTER); |
| 814 | RECORD(TYPE_CONSTANT_ARRAY); |
| 815 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 816 | RECORD(TYPE_VARIABLE_ARRAY); |
| 817 | RECORD(TYPE_VECTOR); |
| 818 | RECORD(TYPE_EXT_VECTOR); |
| 819 | RECORD(TYPE_FUNCTION_PROTO); |
| 820 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 821 | RECORD(TYPE_TYPEDEF); |
| 822 | RECORD(TYPE_TYPEOF_EXPR); |
| 823 | RECORD(TYPE_TYPEOF); |
| 824 | RECORD(TYPE_RECORD); |
| 825 | RECORD(TYPE_ENUM); |
| 826 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | 94f619a | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 827 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 828 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 829 | RECORD(TYPE_DECLTYPE); |
| 830 | RECORD(TYPE_ELABORATED); |
| 831 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 832 | RECORD(TYPE_UNRESOLVED_USING); |
| 833 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 834 | RECORD(TYPE_OBJC_OBJECT); |
| 835 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 836 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 837 | RECORD(TYPE_DEPENDENT_NAME); |
| 838 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 839 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 840 | RECORD(TYPE_PAREN); |
| 841 | RECORD(TYPE_PACK_EXPANSION); |
| 842 | RECORD(TYPE_ATTRIBUTED); |
| 843 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 844 | RECORD(DECL_TYPEDEF); |
| 845 | RECORD(DECL_ENUM); |
| 846 | RECORD(DECL_RECORD); |
| 847 | RECORD(DECL_ENUM_CONSTANT); |
| 848 | RECORD(DECL_FUNCTION); |
| 849 | RECORD(DECL_OBJC_METHOD); |
| 850 | RECORD(DECL_OBJC_INTERFACE); |
| 851 | RECORD(DECL_OBJC_PROTOCOL); |
| 852 | RECORD(DECL_OBJC_IVAR); |
| 853 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
| 854 | RECORD(DECL_OBJC_CLASS); |
| 855 | RECORD(DECL_OBJC_FORWARD_PROTOCOL); |
| 856 | RECORD(DECL_OBJC_CATEGORY); |
| 857 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 858 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 859 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 860 | RECORD(DECL_OBJC_PROPERTY); |
| 861 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 862 | RECORD(DECL_FIELD); |
| 863 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 864 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 865 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 866 | RECORD(DECL_FILE_SCOPE_ASM); |
| 867 | RECORD(DECL_BLOCK); |
| 868 | RECORD(DECL_CONTEXT_LEXICAL); |
| 869 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 870 | RECORD(DECL_NAMESPACE); |
| 871 | RECORD(DECL_NAMESPACE_ALIAS); |
| 872 | RECORD(DECL_USING); |
| 873 | RECORD(DECL_USING_SHADOW); |
| 874 | RECORD(DECL_USING_DIRECTIVE); |
| 875 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 876 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 877 | RECORD(DECL_LINKAGE_SPEC); |
| 878 | RECORD(DECL_CXX_RECORD); |
| 879 | RECORD(DECL_CXX_METHOD); |
| 880 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 881 | RECORD(DECL_CXX_DESTRUCTOR); |
| 882 | RECORD(DECL_CXX_CONVERSION); |
| 883 | RECORD(DECL_ACCESS_SPEC); |
| 884 | RECORD(DECL_FRIEND); |
| 885 | RECORD(DECL_FRIEND_TEMPLATE); |
| 886 | RECORD(DECL_CLASS_TEMPLATE); |
| 887 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 888 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
| 889 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 890 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 891 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 892 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 893 | RECORD(DECL_STATIC_ASSERT); |
| 894 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 895 | RECORD(DECL_INDIRECTFIELD); |
| 896 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 897 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 898 | // Statements and Exprs can occur in the Decls and Types block. |
| 899 | AddStmtsExprs(Stream, Record); |
| 900 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 901 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 902 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 903 | RECORD(PPD_MACRO_DEFINITION); |
| 904 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 905 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 906 | #undef RECORD |
| 907 | #undef BLOCK |
| 908 | Stream.ExitBlock(); |
| 909 | } |
| 910 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 911 | /// \brief Adjusts the given filename to only write out the portion of the |
| 912 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 914 | /// \param Filename the file name to adjust. |
| 915 | /// |
| 916 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 917 | /// the returned filename will be adjusted by this system root. |
| 918 | /// |
| 919 | /// \returns either the original filename (if it needs no adjustment) or the |
| 920 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 921 | static const char * |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 922 | adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 923 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 925 | if (isysroot.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 926 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 928 | // Verify that the filename and the system root have the same prefix. |
| 929 | unsigned Pos = 0; |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 930 | for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 931 | if (Filename[Pos] != isysroot[Pos]) |
| 932 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 933 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 934 | // We hit the end of the filename before we hit the end of the system root. |
| 935 | if (!Filename[Pos]) |
| 936 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 938 | // If the file name has a '/' at the current position, skip over the '/'. |
| 939 | // We distinguish sysroot-based includes from absolute includes by the |
| 940 | // absence of '/' at the beginning of sysroot-based includes. |
| 941 | if (Filename[Pos] == '/') |
| 942 | ++Pos; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 943 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 944 | return Filename + Pos; |
| 945 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 946 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 947 | /// \brief Write the AST metadata (e.g., i686-apple-darwin9). |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 948 | void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot, |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 949 | const std::string &OutputFile) { |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 950 | using namespace llvm; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 951 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 952 | // Metadata |
| 953 | const TargetInfo &Target = Context.Target; |
| 954 | BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 4d3af3e | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 955 | MetaAbbrev->Add(BitCodeAbbrevOp( |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 956 | Chain ? CHAINED_METADATA : METADATA)); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 957 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST major |
| 958 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST minor |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 959 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major |
| 960 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor |
| 961 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Sebastian Redl | 4d3af3e | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 962 | // Target triple or chained PCH name |
| 963 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 964 | unsigned MetaAbbrevCode = Stream.EmitAbbrev(MetaAbbrev); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 965 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 966 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 967 | Record.push_back(Chain ? CHAINED_METADATA : METADATA); |
| 968 | Record.push_back(VERSION_MAJOR); |
| 969 | Record.push_back(VERSION_MINOR); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 970 | Record.push_back(CLANG_VERSION_MAJOR); |
| 971 | Record.push_back(CLANG_VERSION_MINOR); |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 972 | Record.push_back(!isysroot.empty()); |
Sebastian Redl | 4d3af3e | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 973 | // FIXME: This writes the absolute path for chained headers. |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 974 | const std::string &BlobStr = |
| 975 | Chain ? Chain->getFileName() : Target.getTriple().getTriple(); |
Sebastian Redl | 4d3af3e | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 976 | Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, BlobStr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 978 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 979 | SourceManager &SM = Context.getSourceManager(); |
| 980 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 981 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 982 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE_NAME)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 983 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 984 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 985 | |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 986 | llvm::SmallString<128> MainFilePath(MainFile->getName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 987 | |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 988 | llvm::sys::fs::make_absolute(MainFilePath); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 989 | |
Kovarththanan Rajaratnam | d16d38c | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 990 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 992 | isysroot); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 993 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 994 | Record.push_back(ORIGINAL_FILE_NAME); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 995 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 996 | |
| 997 | Record.clear(); |
| 998 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 999 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1000 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1001 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1002 | // Original PCH directory |
| 1003 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1004 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1005 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1006 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1007 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1008 | |
| 1009 | llvm::SmallString<128> OutputPath(OutputFile); |
| 1010 | |
| 1011 | llvm::sys::fs::make_absolute(OutputPath); |
| 1012 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1013 | |
| 1014 | RecordData Record; |
| 1015 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1016 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1017 | } |
| 1018 | |
Ted Kremenek | 18e066f | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1019 | // Repository branch/version information. |
| 1020 | BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1021 | RepoAbbrev->Add(BitCodeAbbrevOp(VERSION_CONTROL_BRANCH_REVISION)); |
Ted Kremenek | 18e066f | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1022 | RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1023 | unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 1024 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1025 | Record.push_back(VERSION_CONTROL_BRANCH_REVISION); |
Ted Kremenek | 18e066f | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1026 | Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, |
| 1027 | getClangFullRepositoryVersion()); |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | /// \brief Write the LangOptions structure. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1031 | void ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1032 | RecordData Record; |
| 1033 | Record.push_back(LangOpts.Trigraphs); |
| 1034 | Record.push_back(LangOpts.BCPLComment); // BCPL-style '//' comments. |
| 1035 | Record.push_back(LangOpts.DollarIdents); // '$' allowed in identifiers. |
| 1036 | Record.push_back(LangOpts.AsmPreprocessor); // Preprocessor in asm mode. |
| 1037 | Record.push_back(LangOpts.GNUMode); // True in gnu99 mode false in c99 mode (etc) |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1038 | Record.push_back(LangOpts.GNUKeywords); // Allow GNU-extension keywords |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1039 | Record.push_back(LangOpts.ImplicitInt); // C89 implicit 'int'. |
| 1040 | Record.push_back(LangOpts.Digraphs); // C94, C99 and C++ |
| 1041 | Record.push_back(LangOpts.HexFloats); // C99 Hexadecimal float constants. |
| 1042 | Record.push_back(LangOpts.C99); // C99 Support |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 1043 | Record.push_back(LangOpts.C1X); // C1X Support |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1044 | Record.push_back(LangOpts.Microsoft); // Microsoft extensions. |
Michael J. Spencer | 4992ca4b | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1045 | // LangOpts.MSCVersion is ignored because all it does it set a macro, which is |
| 1046 | // already saved elsewhere. |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1047 | Record.push_back(LangOpts.CPlusPlus); // C++ Support |
| 1048 | Record.push_back(LangOpts.CPlusPlus0x); // C++0x Support |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1049 | Record.push_back(LangOpts.CXXOperatorNames); // Treat C++ operator names as keywords. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1051 | Record.push_back(LangOpts.ObjC1); // Objective-C 1 support enabled. |
| 1052 | Record.push_back(LangOpts.ObjC2); // Objective-C 2 support enabled. |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1053 | Record.push_back(LangOpts.ObjCNonFragileABI); // Objective-C |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 1054 | // modern abi enabled. |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1055 | Record.push_back(LangOpts.ObjCNonFragileABI2); // Objective-C enhanced |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 1056 | // modern abi enabled. |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 1057 | Record.push_back(LangOpts.AppleKext); // Apple's kernel extensions ABI |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 1058 | Record.push_back(LangOpts.ObjCDefaultSynthProperties); // Objective-C auto-synthesized |
| 1059 | // properties enabled. |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 1060 | Record.push_back(LangOpts.ObjCInferRelatedResultType); |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 1061 | Record.push_back(LangOpts.NoConstantCFStrings); // non cfstring generation enabled.. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1063 | Record.push_back(LangOpts.PascalStrings); // Allow Pascal strings |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1064 | Record.push_back(LangOpts.WritableStrings); // Allow writable strings |
| 1065 | Record.push_back(LangOpts.LaxVectorConversions); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 1066 | Record.push_back(LangOpts.AltiVec); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1067 | Record.push_back(LangOpts.Exceptions); // Support exception handling. |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 1068 | Record.push_back(LangOpts.ObjCExceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 1069 | Record.push_back(LangOpts.CXXExceptions); |
| 1070 | Record.push_back(LangOpts.SjLjExceptions); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1071 | |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 1072 | Record.push_back(LangOpts.MSBitfields); // MS-compatible structure layout |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1073 | Record.push_back(LangOpts.NeXTRuntime); // Use NeXT runtime. |
| 1074 | Record.push_back(LangOpts.Freestanding); // Freestanding implementation |
| 1075 | Record.push_back(LangOpts.NoBuiltin); // Do not use builtin functions (-fno-builtin) |
| 1076 | |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1077 | // Whether static initializers are protected by locks. |
| 1078 | Record.push_back(LangOpts.ThreadsafeStatics); |
Douglas Gregor | b3286fe | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 1079 | Record.push_back(LangOpts.POSIXThreads); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1080 | Record.push_back(LangOpts.Blocks); // block extension to C |
| 1081 | Record.push_back(LangOpts.EmitAllDecls); // Emit all declarations, even if |
| 1082 | // they are unused. |
| 1083 | Record.push_back(LangOpts.MathErrno); // Math functions must respect errno |
| 1084 | // (modulo the platform support). |
| 1085 | |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 1086 | Record.push_back(LangOpts.getSignedOverflowBehavior()); |
| 1087 | Record.push_back(LangOpts.HeinousExtensions); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1088 | |
| 1089 | Record.push_back(LangOpts.Optimize); // Whether __OPTIMIZE__ should be defined. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | Record.push_back(LangOpts.OptimizeSize); // Whether __OPTIMIZE_SIZE__ should be |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1091 | // defined. |
| 1092 | Record.push_back(LangOpts.Static); // Should __STATIC__ be defined (as |
| 1093 | // opposed to __DYNAMIC__). |
| 1094 | Record.push_back(LangOpts.PICLevel); // The value for __PIC__, if non-zero. |
| 1095 | |
| 1096 | Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be |
| 1097 | // used (instead of C99 semantics). |
| 1098 | Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined. |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 1099 | Record.push_back(LangOpts.Deprecated); // Should __DEPRECATED be defined. |
Anders Carlsson | 5879fbd | 2009-05-13 19:49:53 +0000 | [diff] [blame] | 1100 | Record.push_back(LangOpts.AccessControl); // Whether C++ access control should |
| 1101 | // be enabled. |
Eli Friedman | 9ffd4a9 | 2009-06-05 07:05:05 +0000 | [diff] [blame] | 1102 | Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or |
| 1103 | // unsigned type |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 1104 | Record.push_back(LangOpts.ShortWChar); // force wchar_t to be unsigned short |
Argyrios Kyrtzidis | a88942a | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 1105 | Record.push_back(LangOpts.ShortEnums); // Should the enum type be equivalent |
| 1106 | // to the smallest integer type with |
| 1107 | // enough room. |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1108 | Record.push_back(LangOpts.getGCMode()); |
| 1109 | Record.push_back(LangOpts.getVisibilityMode()); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 1110 | Record.push_back(LangOpts.getStackProtectorMode()); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1111 | Record.push_back(LangOpts.InstantiationDepth); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 1112 | Record.push_back(LangOpts.OpenCL); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 1113 | Record.push_back(LangOpts.CUDA); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 1114 | Record.push_back(LangOpts.CatchUndefined); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1115 | Record.push_back(LangOpts.DefaultFPContract); |
Anders Carlsson | 9cedbef | 2009-08-22 22:30:33 +0000 | [diff] [blame] | 1116 | Record.push_back(LangOpts.ElideConstructors); |
Douglas Gregor | 8ed0c0b | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 1117 | Record.push_back(LangOpts.SpellChecking); |
Roman Divacky | 65b88cd | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 1118 | Record.push_back(LangOpts.MRTD); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1119 | Record.push_back(LangOpts.ObjCAutoRefCount); |
| 1120 | Record.push_back(LangOpts.ObjCInferRelatedReturnType); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1121 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1124 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1125 | // stat cache Serialization |
| 1126 | //===----------------------------------------------------------------------===// |
| 1127 | |
| 1128 | namespace { |
| 1129 | // Trait used for the on-disk hash table of stat cache results. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1130 | class ASTStatCacheTrait { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1131 | public: |
| 1132 | typedef const char * key_type; |
| 1133 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1134 | |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1135 | typedef struct stat data_type; |
| 1136 | typedef const data_type &data_type_ref; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1137 | |
| 1138 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1139 | return llvm::HashString(path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1140 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1141 | |
| 1142 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1143 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1144 | data_type_ref Data) { |
| 1145 | unsigned StrLen = strlen(path); |
| 1146 | clang::io::Emit16(Out, StrLen); |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1147 | unsigned DataLen = 4 + 4 + 2 + 8 + 8; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1148 | clang::io::Emit8(Out, DataLen); |
| 1149 | return std::make_pair(StrLen + 1, DataLen); |
| 1150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1152 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1153 | Out.write(path, KeyLen); |
| 1154 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1155 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1156 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1157 | data_type_ref Data, unsigned DataLen) { |
| 1158 | using namespace clang::io; |
| 1159 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1160 | |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1161 | Emit32(Out, (uint32_t) Data.st_ino); |
| 1162 | Emit32(Out, (uint32_t) Data.st_dev); |
| 1163 | Emit16(Out, (uint16_t) Data.st_mode); |
| 1164 | Emit64(Out, (uint64_t) Data.st_mtime); |
| 1165 | Emit64(Out, (uint64_t) Data.st_size); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1166 | |
| 1167 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1168 | } |
| 1169 | }; |
| 1170 | } // end anonymous namespace |
| 1171 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1172 | /// \brief Write the stat() system call cache to the AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1173 | void ASTWriter::WriteStatCache(MemorizeStatCalls &StatCalls) { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1174 | // Build the on-disk hash table containing information about every |
| 1175 | // stat() call. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1176 | OnDiskChainedHashTableGenerator<ASTStatCacheTrait> Generator; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1177 | unsigned NumStatEntries = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1178 | for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1179 | StatEnd = StatCalls.end(); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1180 | Stat != StatEnd; ++Stat, ++NumStatEntries) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1181 | StringRef Filename = Stat->first(); |
Chris Lattner | d386df4 | 2011-07-14 18:24:21 +0000 | [diff] [blame] | 1182 | Generator.insert(Filename.data(), Stat->second); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1183 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1184 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1185 | // Create the on-disk hash table in a buffer. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1186 | llvm::SmallString<4096> StatCacheData; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1187 | uint32_t BucketOffset; |
| 1188 | { |
| 1189 | llvm::raw_svector_ostream Out(StatCacheData); |
| 1190 | // Make sure that no bucket is at offset 0 |
| 1191 | clang::io::Emit32(Out, 0); |
| 1192 | BucketOffset = Generator.Emit(Out); |
| 1193 | } |
| 1194 | |
| 1195 | // Create a blob abbreviation |
| 1196 | using namespace llvm; |
| 1197 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1198 | Abbrev->Add(BitCodeAbbrevOp(STAT_CACHE)); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1199 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1200 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1201 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1202 | unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1203 | |
| 1204 | // Write the stat cache |
| 1205 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1206 | Record.push_back(STAT_CACHE); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1207 | Record.push_back(BucketOffset); |
| 1208 | Record.push_back(NumStatEntries); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1209 | Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1213 | // Source Manager Serialization |
| 1214 | //===----------------------------------------------------------------------===// |
| 1215 | |
| 1216 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1217 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1218 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1219 | using namespace llvm; |
| 1220 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1221 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1222 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1223 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1224 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1225 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1226 | // FileEntry fields. |
| 1227 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1228 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1229 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1230 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1234 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1235 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1236 | using namespace llvm; |
| 1237 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1238 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1239 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1240 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1241 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1242 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1243 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1244 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1248 | /// buffer's blob. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1249 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1250 | using namespace llvm; |
| 1251 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1252 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1253 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1254 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1257 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1258 | /// expansion. |
| 1259 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1260 | using namespace llvm; |
| 1261 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1262 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1263 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1264 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1265 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1266 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1267 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1268 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1271 | namespace { |
| 1272 | // Trait used for the on-disk hash table of header search information. |
| 1273 | class HeaderFileInfoTrait { |
| 1274 | ASTWriter &Writer; |
| 1275 | HeaderSearch &HS; |
| 1276 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1277 | // Keep track of the framework names we've used during serialization. |
| 1278 | SmallVector<char, 128> FrameworkStringData; |
| 1279 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1280 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1281 | public: |
| 1282 | HeaderFileInfoTrait(ASTWriter &Writer, HeaderSearch &HS) |
| 1283 | : Writer(Writer), HS(HS) { } |
| 1284 | |
| 1285 | typedef const char *key_type; |
| 1286 | typedef key_type key_type_ref; |
| 1287 | |
| 1288 | typedef HeaderFileInfo data_type; |
| 1289 | typedef const data_type &data_type_ref; |
| 1290 | |
| 1291 | static unsigned ComputeHash(const char *path) { |
| 1292 | // The hash is based only on the filename portion of the key, so that the |
| 1293 | // reader can match based on filenames when symlinking or excess path |
| 1294 | // elements ("foo/../", "../") change the form of the name. However, |
| 1295 | // complete path is still the key. |
| 1296 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1297 | } |
| 1298 | |
| 1299 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1300 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1301 | data_type_ref Data) { |
| 1302 | unsigned StrLen = strlen(path); |
| 1303 | clang::io::Emit16(Out, StrLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1304 | unsigned DataLen = 1 + 2 + 4 + 4; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1305 | clang::io::Emit8(Out, DataLen); |
| 1306 | return std::make_pair(StrLen + 1, DataLen); |
| 1307 | } |
| 1308 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1309 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1310 | Out.write(path, KeyLen); |
| 1311 | } |
| 1312 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1313 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1314 | data_type_ref Data, unsigned DataLen) { |
| 1315 | using namespace clang::io; |
| 1316 | uint64_t Start = Out.tell(); (void)Start; |
| 1317 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1318 | unsigned char Flags = (Data.isImport << 5) |
| 1319 | | (Data.isPragmaOnce << 4) |
| 1320 | | (Data.DirInfo << 2) |
| 1321 | | (Data.Resolved << 1) |
| 1322 | | Data.IndexHeaderMapHeader; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1323 | Emit8(Out, (uint8_t)Flags); |
| 1324 | Emit16(Out, (uint16_t) Data.NumIncludes); |
| 1325 | |
| 1326 | if (!Data.ControllingMacro) |
| 1327 | Emit32(Out, (uint32_t)Data.ControllingMacroID); |
| 1328 | else |
| 1329 | Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1330 | |
| 1331 | unsigned Offset = 0; |
| 1332 | if (!Data.Framework.empty()) { |
| 1333 | // If this header refers into a framework, save the framework name. |
| 1334 | llvm::StringMap<unsigned>::iterator Pos |
| 1335 | = FrameworkNameOffset.find(Data.Framework); |
| 1336 | if (Pos == FrameworkNameOffset.end()) { |
| 1337 | Offset = FrameworkStringData.size() + 1; |
| 1338 | FrameworkStringData.append(Data.Framework.begin(), |
| 1339 | Data.Framework.end()); |
| 1340 | FrameworkStringData.push_back(0); |
| 1341 | |
| 1342 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1343 | } else |
| 1344 | Offset = Pos->second; |
| 1345 | } |
| 1346 | Emit32(Out, Offset); |
| 1347 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1348 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1349 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1350 | |
| 1351 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1352 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1353 | }; |
| 1354 | } // end anonymous namespace |
| 1355 | |
| 1356 | /// \brief Write the header search block for the list of files that |
| 1357 | /// |
| 1358 | /// \param HS The header search structure to save. |
| 1359 | /// |
| 1360 | /// \param Chain Whether we're creating a chained AST file. |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1361 | void ASTWriter::WriteHeaderSearch(HeaderSearch &HS, StringRef isysroot) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1362 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1363 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1364 | |
| 1365 | if (FilesByUID.size() > HS.header_file_size()) |
| 1366 | FilesByUID.resize(HS.header_file_size()); |
| 1367 | |
| 1368 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
| 1369 | OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1370 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1371 | unsigned NumHeaderSearchEntries = 0; |
| 1372 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1373 | const FileEntry *File = FilesByUID[UID]; |
| 1374 | if (!File) |
| 1375 | continue; |
| 1376 | |
| 1377 | const HeaderFileInfo &HFI = HS.header_file_begin()[UID]; |
| 1378 | if (HFI.External && Chain) |
| 1379 | continue; |
| 1380 | |
| 1381 | // Turn the file name into an absolute path, if it isn't already. |
| 1382 | const char *Filename = File->getName(); |
| 1383 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1384 | |
| 1385 | // If we performed any translation on the file name at all, we need to |
| 1386 | // save this string, since the generator will refer to it later. |
| 1387 | if (Filename != File->getName()) { |
| 1388 | Filename = strdup(Filename); |
| 1389 | SavedStrings.push_back(Filename); |
| 1390 | } |
| 1391 | |
| 1392 | Generator.insert(Filename, HFI, GeneratorTrait); |
| 1393 | ++NumHeaderSearchEntries; |
| 1394 | } |
| 1395 | |
| 1396 | // Create the on-disk hash table in a buffer. |
| 1397 | llvm::SmallString<4096> TableData; |
| 1398 | uint32_t BucketOffset; |
| 1399 | { |
| 1400 | llvm::raw_svector_ostream Out(TableData); |
| 1401 | // Make sure that no bucket is at offset 0 |
| 1402 | clang::io::Emit32(Out, 0); |
| 1403 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1404 | } |
| 1405 | |
| 1406 | // Create a blob abbreviation |
| 1407 | using namespace llvm; |
| 1408 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1409 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1410 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1411 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1412 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1413 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1414 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1415 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1416 | // Write the header search table |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1417 | RecordData Record; |
| 1418 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1419 | Record.push_back(BucketOffset); |
| 1420 | Record.push_back(NumHeaderSearchEntries); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1421 | Record.push_back(TableData.size()); |
| 1422 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1423 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); |
| 1424 | |
| 1425 | // Free all of the strings we had to duplicate. |
| 1426 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
| 1427 | free((void*)SavedStrings[I]); |
| 1428 | } |
| 1429 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1430 | /// \brief Writes the block containing the serialized form of the |
| 1431 | /// source manager. |
| 1432 | /// |
| 1433 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1434 | /// blob), indexed based on the file name, so that we only create |
| 1435 | /// entries for files that we actually need. In the common case (no |
| 1436 | /// errors), we probably won't have to create file entries for any of |
| 1437 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1438 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1439 | const Preprocessor &PP, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1440 | StringRef isysroot) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1441 | RecordData Record; |
| 1442 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1443 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1444 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1445 | |
| 1446 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1447 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1448 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1449 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1450 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1451 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1452 | // Write out the source location entry table. We skip the first |
| 1453 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1454 | std::vector<uint32_t> SLocEntryOffsets; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1455 | // Write out the offsets of only source location file entries. |
| 1456 | // We will go through them in ASTReader::validateFileEntries(). |
| 1457 | std::vector<uint32_t> SLocFileEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1458 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1459 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1460 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1461 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1462 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1463 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1464 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1465 | // Record the offset of this source-location entry. |
| 1466 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1467 | |
| 1468 | // Figure out which record code to use. |
| 1469 | unsigned Code; |
| 1470 | if (SLoc->isFile()) { |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1471 | if (SLoc->getFile().getContentCache()->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1472 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1473 | SLocFileEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1474 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1475 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1476 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1477 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1478 | Record.clear(); |
| 1479 | Record.push_back(Code); |
| 1480 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1481 | // Starting offset of this entry within this module, so skip the dummy. |
| 1482 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1483 | if (SLoc->isFile()) { |
| 1484 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1485 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1486 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1487 | Record.push_back(File.hasLineDirectives()); |
| 1488 | |
| 1489 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1490 | if (Content->OrigEntry) { |
| 1491 | assert(Content->OrigEntry == Content->ContentsEntry && |
| 1492 | "Writing to AST an overriden file is not supported"); |
| 1493 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1494 | // The source location entry is a file. The blob associated |
| 1495 | // with this entry is the file name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1496 | |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1497 | // Emit size/modification time for this file. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1498 | Record.push_back(Content->OrigEntry->getSize()); |
| 1499 | Record.push_back(Content->OrigEntry->getModificationTime()); |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1500 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1501 | // Turn the file name into an absolute path, if it isn't already. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1502 | const char *Filename = Content->OrigEntry->getName(); |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1503 | llvm::SmallString<128> FilePath(Filename); |
Anders Carlsson | a426705 | 2011-03-08 16:04:35 +0000 | [diff] [blame] | 1504 | |
| 1505 | // Ask the file manager to fixup the relative path for us. This will |
| 1506 | // honor the working directory. |
| 1507 | SourceMgr.getFileManager().FixupRelativePath(FilePath); |
| 1508 | |
| 1509 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1510 | // call to FixupRelativePath should always return an absolute path. |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1511 | llvm::sys::fs::make_absolute(FilePath); |
Kovarththanan Rajaratnam | d16d38c | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1512 | Filename = FilePath.c_str(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1513 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1514 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1515 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1516 | } else { |
| 1517 | // The source location entry is a buffer. The blob associated |
| 1518 | // with this entry contains the contents of the buffer. |
| 1519 | |
| 1520 | // We add one to the size so that we capture the trailing NULL |
| 1521 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1522 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1523 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1524 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1525 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1526 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1527 | StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1528 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1529 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1530 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1531 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1532 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1533 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1534 | if (strcmp(Name, "<built-in>") == 0) { |
| 1535 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1536 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1537 | } |
| 1538 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1539 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1540 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 73ee5d7 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1541 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1542 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
| 1543 | Record.push_back(Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1544 | |
| 1545 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1546 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1547 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1548 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1549 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1550 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1554 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1555 | |
| 1556 | if (SLocEntryOffsets.empty()) |
| 1557 | return; |
| 1558 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1559 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1560 | // table is used for lazily loading source-location information. |
| 1561 | using namespace llvm; |
| 1562 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1563 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1564 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1565 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1566 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1567 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1569 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1570 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1571 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1572 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1573 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1574 | |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1575 | Abbrev = new BitCodeAbbrev(); |
| 1576 | Abbrev->Add(BitCodeAbbrevOp(FILE_SOURCE_LOCATION_OFFSETS)); |
| 1577 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
| 1578 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1579 | unsigned SLocFileOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1580 | |
| 1581 | Record.clear(); |
| 1582 | Record.push_back(FILE_SOURCE_LOCATION_OFFSETS); |
| 1583 | Record.push_back(SLocFileEntryOffsets.size()); |
| 1584 | Stream.EmitRecordWithBlob(SLocFileOffsetsAbbrev, Record, |
| 1585 | data(SLocFileEntryOffsets)); |
| 1586 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1587 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1588 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1589 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1590 | |
| 1591 | // Write the line table. It depends on remapping working, so it must come |
| 1592 | // after the source location offsets. |
| 1593 | if (SourceMgr.hasLineTable()) { |
| 1594 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1595 | |
| 1596 | Record.clear(); |
| 1597 | // Emit the file names |
| 1598 | Record.push_back(LineTable.getNumFilenames()); |
| 1599 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1600 | // Emit the file name |
| 1601 | const char *Filename = LineTable.getFilename(I); |
| 1602 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1603 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1604 | Record.push_back(FilenameLen); |
| 1605 | if (FilenameLen) |
| 1606 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1607 | } |
| 1608 | |
| 1609 | // Emit the line entries |
| 1610 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1611 | L != LEnd; ++L) { |
| 1612 | // Only emit entries for local files. |
| 1613 | if (L->first < 0) |
| 1614 | continue; |
| 1615 | |
| 1616 | // Emit the file ID |
| 1617 | Record.push_back(L->first); |
| 1618 | |
| 1619 | // Emit the line entries |
| 1620 | Record.push_back(L->second.size()); |
| 1621 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1622 | LEEnd = L->second.end(); |
| 1623 | LE != LEEnd; ++LE) { |
| 1624 | Record.push_back(LE->FileOffset); |
| 1625 | Record.push_back(LE->LineNo); |
| 1626 | Record.push_back(LE->FilenameID); |
| 1627 | Record.push_back((unsigned)LE->FileKind); |
| 1628 | Record.push_back(LE->IncludeOffset); |
| 1629 | } |
| 1630 | } |
| 1631 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1632 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1635 | //===----------------------------------------------------------------------===// |
| 1636 | // Preprocessor Serialization |
| 1637 | //===----------------------------------------------------------------------===// |
| 1638 | |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1639 | static int compareMacroDefinitions(const void *XPtr, const void *YPtr) { |
| 1640 | const std::pair<const IdentifierInfo *, MacroInfo *> &X = |
| 1641 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; |
| 1642 | const std::pair<const IdentifierInfo *, MacroInfo *> &Y = |
| 1643 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; |
| 1644 | return X.first->getName().compare(Y.first->getName()); |
| 1645 | } |
| 1646 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1647 | /// \brief Writes the block containing the serialized form of the |
| 1648 | /// preprocessor. |
| 1649 | /// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1650 | void ASTWriter::WritePreprocessor(const Preprocessor &PP) { |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1651 | RecordData Record; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1652 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1653 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1654 | if (PP.getCounterValue() != 0) { |
| 1655 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1656 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1657 | Record.clear(); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1661 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1663 | // If the AST file contains __DATE__ or __TIME__ emit a warning about this. |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1664 | // FIXME: use diagnostics subsystem for localization etc. |
| 1665 | if (PP.SawDateOrTime()) |
| 1666 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1667 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1668 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1669 | // Loop over all the macro definitions that are live at the end of the file, |
| 1670 | // emitting each to the PP section. |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1671 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1672 | |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1673 | // Construct the list of macro definitions that need to be serialized. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1674 | SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1675 | MacrosToEmit; |
| 1676 | llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; |
Douglas Gregor | 68051a7 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1677 | for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), |
| 1678 | E = PP.macro_end(Chain == 0); |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1679 | I != E; ++I) { |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1680 | MacroDefinitionsSeen.insert(I->first); |
| 1681 | MacrosToEmit.push_back(std::make_pair(I->first, I->second)); |
| 1682 | } |
| 1683 | |
| 1684 | // Sort the set of macro definitions that need to be serialized by the |
| 1685 | // name of the macro, to provide a stable ordering. |
| 1686 | llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), |
| 1687 | &compareMacroDefinitions); |
| 1688 | |
Douglas Gregor | 68051a7 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1689 | // Resolve any identifiers that defined macros at the time they were |
| 1690 | // deserialized, adding them to the list of macros to emit (if appropriate). |
| 1691 | for (unsigned I = 0, N = DeserializedMacroNames.size(); I != N; ++I) { |
| 1692 | IdentifierInfo *Name |
| 1693 | = const_cast<IdentifierInfo *>(DeserializedMacroNames[I]); |
| 1694 | if (Name->hasMacroDefinition() && MacroDefinitionsSeen.insert(Name)) |
| 1695 | MacrosToEmit.push_back(std::make_pair(Name, PP.getMacroInfo(Name))); |
| 1696 | } |
| 1697 | |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1698 | for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { |
| 1699 | const IdentifierInfo *Name = MacrosToEmit[I].first; |
| 1700 | MacroInfo *MI = MacrosToEmit[I].second; |
Douglas Gregor | 68051a7 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1701 | if (!MI) |
| 1702 | continue; |
| 1703 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1704 | // Don't emit builtin macros like __LINE__ to the AST file unless they have |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1705 | // been redefined by the header (in which case they are not isBuiltinMacro). |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1706 | // Also skip macros from a AST file if we're chaining. |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 1707 | |
| 1708 | // FIXME: There is a (probably minor) optimization we could do here, if |
| 1709 | // the macro comes from the original PCH but the identifier comes from a |
| 1710 | // chained PCH, by storing the offset into the original PCH rather than |
| 1711 | // writing the macro definition a second time. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1712 | if (MI->isBuiltinMacro() || |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1713 | (Chain && Name->isFromAST() && MI->isFromAST())) |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1714 | continue; |
| 1715 | |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1716 | AddIdentifierRef(Name, Record); |
| 1717 | MacroOffsets[Name] = Stream.GetCurrentBitNo(); |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1718 | Record.push_back(MI->getDefinitionLoc().getRawEncoding()); |
| 1719 | Record.push_back(MI->isUsed()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1720 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1721 | unsigned Code; |
| 1722 | if (MI->isObjectLike()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1723 | Code = PP_MACRO_OBJECT_LIKE; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1724 | } else { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1725 | Code = PP_MACRO_FUNCTION_LIKE; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1726 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1727 | Record.push_back(MI->isC99Varargs()); |
| 1728 | Record.push_back(MI->isGNUVarargs()); |
| 1729 | Record.push_back(MI->getNumArgs()); |
| 1730 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1731 | I != E; ++I) |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1732 | AddIdentifierRef(*I, Record); |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1733 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1734 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1735 | // If we have a detailed preprocessing record, record the macro definition |
| 1736 | // ID that corresponds to this macro. |
| 1737 | if (PPRec) |
| 1738 | Record.push_back(getMacroDefinitionID(PPRec->findMacroDefinition(MI))); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1739 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1740 | Stream.EmitRecord(Code, Record); |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1741 | Record.clear(); |
| 1742 | |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1743 | // Emit the tokens array. |
| 1744 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1745 | // Note that we know that the preprocessor does not have any annotation |
| 1746 | // tokens in it because they are created by the parser, and thus can't be |
| 1747 | // in a macro definition. |
| 1748 | const Token &Tok = MI->getReplacementToken(TokNo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1750 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1751 | Record.push_back(Tok.getLength()); |
| 1752 | |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1753 | // FIXME: When reading literal tokens, reconstruct the literal pointer if |
| 1754 | // it is needed. |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1755 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1756 | // FIXME: Should translate token kind to a stable encoding. |
| 1757 | Record.push_back(Tok.getKind()); |
| 1758 | // FIXME: Should translate token flags to a stable encoding. |
| 1759 | Record.push_back(Tok.getFlags()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1761 | Stream.EmitRecord(PP_TOKEN, Record); |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1762 | Record.clear(); |
| 1763 | } |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1764 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1765 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1766 | Stream.ExitBlock(); |
| 1767 | |
| 1768 | if (PPRec) |
| 1769 | WritePreprocessorDetail(*PPRec); |
| 1770 | } |
| 1771 | |
| 1772 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
| 1773 | if (PPRec.begin(Chain) == PPRec.end(Chain)) |
| 1774 | return; |
| 1775 | |
| 1776 | // Enter the preprocessor block. |
| 1777 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1778 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1779 | // If the preprocessor has a preprocessing record, emit it. |
| 1780 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1781 | using namespace llvm; |
| 1782 | |
| 1783 | // Set up the abbreviation for |
| 1784 | unsigned InclusionAbbrev = 0; |
| 1785 | { |
| 1786 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1787 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
| 1788 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index |
| 1789 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // start location |
| 1790 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // end location |
| 1791 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 1792 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 1793 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
| 1794 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1795 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1796 | } |
| 1797 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1798 | unsigned FirstPreprocessorEntityID |
| 1799 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 1800 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 1801 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1802 | RecordData Record; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1803 | uint64_t BitsInChain = Chain? Chain->TotalModulesSizeInBits : 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1804 | for (PreprocessingRecord::iterator E = PPRec.begin(Chain), |
| 1805 | EEnd = PPRec.end(Chain); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1806 | E != EEnd; |
| 1807 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1808 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1809 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1810 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
| 1811 | // Record this macro definition's location. |
| 1812 | MacroID ID = getMacroDefinitionID(MD); |
| 1813 | |
| 1814 | // Don't write the macro definition if it is from another AST file. |
| 1815 | if (ID < FirstMacroID) |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1816 | continue; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1817 | |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1818 | // Notify the serialization listener that we're serializing this entity. |
| 1819 | if (SerializationListener) |
| 1820 | SerializationListener->SerializedPreprocessedEntity(*E, |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1821 | BitsInChain + Stream.GetCurrentBitNo()); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1822 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1823 | unsigned Position = ID - FirstMacroID; |
| 1824 | if (Position != MacroDefinitionOffsets.size()) { |
| 1825 | if (Position > MacroDefinitionOffsets.size()) |
| 1826 | MacroDefinitionOffsets.resize(Position + 1); |
| 1827 | |
| 1828 | MacroDefinitionOffsets[Position] = Stream.GetCurrentBitNo(); |
| 1829 | } else |
| 1830 | MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo()); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1831 | |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1832 | Record.push_back(NextPreprocessorEntityID); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1833 | Record.push_back(ID); |
| 1834 | AddSourceLocation(MD->getSourceRange().getBegin(), Record); |
| 1835 | AddSourceLocation(MD->getSourceRange().getEnd(), Record); |
| 1836 | AddIdentifierRef(MD->getName(), Record); |
| 1837 | AddSourceLocation(MD->getLocation(), Record); |
| 1838 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 1839 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1840 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1841 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1842 | // Notify the serialization listener that we're serializing this entity. |
| 1843 | if (SerializationListener) |
| 1844 | SerializationListener->SerializedPreprocessedEntity(*E, |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1845 | BitsInChain + Stream.GetCurrentBitNo()); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1846 | |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1847 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1848 | Record.push_back(NextPreprocessorEntityID); |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1849 | AddSourceLocation(ME->getSourceRange().getBegin(), Record); |
| 1850 | AddSourceLocation(ME->getSourceRange().getEnd(), Record); |
| 1851 | AddIdentifierRef(ME->getName(), Record); |
| 1852 | Record.push_back(getMacroDefinitionID(ME->getDefinition())); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1853 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1854 | continue; |
| 1855 | } |
| 1856 | |
| 1857 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 1858 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1859 | Record.push_back(NextPreprocessorEntityID); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1860 | AddSourceLocation(ID->getSourceRange().getBegin(), Record); |
| 1861 | AddSourceLocation(ID->getSourceRange().getEnd(), Record); |
| 1862 | Record.push_back(ID->getFileName().size()); |
| 1863 | Record.push_back(ID->wasInQuotes()); |
| 1864 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
| 1865 | llvm::SmallString<64> Buffer; |
| 1866 | Buffer += ID->getFileName(); |
| 1867 | Buffer += ID->getFile()->getName(); |
| 1868 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 1869 | continue; |
| 1870 | } |
| 1871 | |
| 1872 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 1873 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1874 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1875 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1876 | // Write the offsets table for the preprocessing record. |
| 1877 | if (NumPreprocessingRecords > 0) { |
| 1878 | // Write the offsets table for identifier IDs. |
| 1879 | using namespace llvm; |
| 1880 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1881 | Abbrev->Add(BitCodeAbbrevOp(MACRO_DEFINITION_OFFSETS)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1882 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1883 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1884 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1885 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first macro def |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1886 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1887 | unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1888 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1889 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1890 | Record.push_back(MACRO_DEFINITION_OFFSETS); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1891 | Record.push_back(NumPreprocessingRecords); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1892 | Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1893 | Record.push_back(MacroDefinitionOffsets.size()); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1894 | Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1895 | Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record, |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1896 | data(MacroDefinitionOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1897 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1900 | void ASTWriter::WritePragmaDiagnosticMappings(const Diagnostic &Diag) { |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1901 | RecordData Record; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1902 | for (Diagnostic::DiagStatePointsTy::const_iterator |
| 1903 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 1904 | I != E; ++I) { |
| 1905 | const Diagnostic::DiagStatePoint &point = *I; |
| 1906 | if (point.Loc.isInvalid()) |
| 1907 | continue; |
| 1908 | |
| 1909 | Record.push_back(point.Loc.getRawEncoding()); |
| 1910 | for (Diagnostic::DiagState::iterator |
| 1911 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
| 1912 | unsigned diag = I->first, map = I->second; |
| 1913 | if (map & 0x10) { // mapping from a diagnostic pragma. |
| 1914 | Record.push_back(diag); |
| 1915 | Record.push_back(map & 0x7); |
| 1916 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1917 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1918 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 1919 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 1922 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1923 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 1926 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 1927 | if (CXXBaseSpecifiersOffsets.empty()) |
| 1928 | return; |
| 1929 | |
| 1930 | RecordData Record; |
| 1931 | |
| 1932 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 1933 | using namespace llvm; |
| 1934 | |
| 1935 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1936 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 1937 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 1938 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1939 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1940 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 1941 | // Write the base specifier offsets table. |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 1942 | Record.clear(); |
| 1943 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 1944 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 1945 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1946 | data(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1949 | //===----------------------------------------------------------------------===// |
| 1950 | // Type Serialization |
| 1951 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1952 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1953 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1954 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | a7fbbb0 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 1955 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 1956 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 1957 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 1959 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 1960 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1961 | // Record the offset for this type. |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 1962 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1963 | if (TypeOffsets.size() == Index) |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1964 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1965 | else if (TypeOffsets.size() < Index) { |
| 1966 | TypeOffsets.resize(Index + 1); |
| 1967 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1971 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1972 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1973 | ASTTypeWriter W(*this, Record); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1974 | |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 1975 | if (T.hasLocalNonFastQualifiers()) { |
| 1976 | Qualifiers Qs = T.getLocalQualifiers(); |
| 1977 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1978 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1979 | W.Code = TYPE_EXT_QUAL; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1980 | } else { |
| 1981 | switch (T->getTypeClass()) { |
| 1982 | // For all of the concrete, non-dependent types, call the |
| 1983 | // appropriate visitor function. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1984 | #define TYPE(Class, Base) \ |
Mike Stump | 281d6d7 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 1985 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1986 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1987 | #include "clang/AST/TypeNodes.def" |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1988 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | // Emit the serialized record. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1992 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1993 | |
| 1994 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1995 | FlushStmts(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1998 | //===----------------------------------------------------------------------===// |
| 1999 | // Declaration Serialization |
| 2000 | //===----------------------------------------------------------------------===// |
| 2001 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2002 | /// \brief Write the block containing all of the declaration IDs |
| 2003 | /// lexically declared within the given DeclContext. |
| 2004 | /// |
| 2005 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2006 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2007 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2008 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2009 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2010 | return 0; |
| 2011 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2012 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2013 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2014 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2015 | SmallVector<KindDeclIDPair, 64> Decls; |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2016 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 2017 | D != DEnd; ++D) |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2018 | Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2019 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2020 | ++NumLexicalDeclContexts; |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2021 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2022 | return Offset; |
| 2023 | } |
| 2024 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2025 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2026 | using namespace llvm; |
| 2027 | RecordData Record; |
| 2028 | |
| 2029 | // Write the type offsets array |
| 2030 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2031 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2032 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2033 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2034 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2035 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2036 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2037 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2038 | Record.push_back(TypeOffsets.size()); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2039 | Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2040 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2041 | |
| 2042 | // Write the declaration offsets array |
| 2043 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2044 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2045 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2046 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2047 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2048 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2049 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2050 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2051 | Record.push_back(DeclOffsets.size()); |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2052 | Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2053 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2056 | //===----------------------------------------------------------------------===// |
| 2057 | // Global Method Pool and Selector Serialization |
| 2058 | //===----------------------------------------------------------------------===// |
| 2059 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2060 | namespace { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2061 | // Trait used for the on-disk hash table used in the method pool. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2062 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2063 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2064 | |
| 2065 | public: |
| 2066 | typedef Selector key_type; |
| 2067 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2068 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2069 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2070 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2071 | ObjCMethodList Instance, Factory; |
| 2072 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2073 | typedef const data_type& data_type_ref; |
| 2074 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2075 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2076 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2077 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2078 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2079 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2080 | |
| 2081 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2082 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2083 | data_type_ref Methods) { |
| 2084 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 2085 | clang::io::Emit16(Out, KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2086 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2087 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2088 | Method = Method->Next) |
| 2089 | if (Method->Method) |
| 2090 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2091 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2092 | Method = Method->Next) |
| 2093 | if (Method->Method) |
| 2094 | DataLen += 4; |
| 2095 | clang::io::Emit16(Out, DataLen); |
| 2096 | return std::make_pair(KeyLen, DataLen); |
| 2097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2098 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2099 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2100 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2101 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2102 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2103 | unsigned N = Sel.getNumArgs(); |
| 2104 | clang::io::Emit16(Out, N); |
| 2105 | if (N == 0) |
| 2106 | N = 1; |
| 2107 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2108 | clang::io::Emit32(Out, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2109 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 2110 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2111 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2112 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2113 | data_type_ref Methods, unsigned DataLen) { |
| 2114 | uint64_t Start = Out.tell(); (void)Start; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2115 | clang::io::Emit32(Out, Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2116 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2117 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2118 | Method = Method->Next) |
| 2119 | if (Method->Method) |
| 2120 | ++NumInstanceMethods; |
| 2121 | |
| 2122 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2123 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2124 | Method = Method->Next) |
| 2125 | if (Method->Method) |
| 2126 | ++NumFactoryMethods; |
| 2127 | |
| 2128 | clang::io::Emit16(Out, NumInstanceMethods); |
| 2129 | clang::io::Emit16(Out, NumFactoryMethods); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2130 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2131 | Method = Method->Next) |
| 2132 | if (Method->Method) |
| 2133 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2134 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2135 | Method = Method->Next) |
| 2136 | if (Method->Method) |
| 2137 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2138 | |
| 2139 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2140 | } |
| 2141 | }; |
| 2142 | } // end anonymous namespace |
| 2143 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2144 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2145 | /// |
| 2146 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2147 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2148 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2149 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2150 | using namespace llvm; |
| 2151 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2152 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2153 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2154 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2155 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2156 | // Create and write out the blob that contains selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2157 | { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2158 | OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2159 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2161 | // Create the on-disk hash table representation. We walk through every |
| 2162 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2163 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2164 | for (llvm::DenseMap<Selector, SelectorID>::iterator |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2165 | I = SelectorIDs.begin(), E = SelectorIDs.end(); |
| 2166 | I != E; ++I) { |
| 2167 | Selector S = I->first; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2168 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2169 | ASTMethodPoolTrait::data_type Data = { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2170 | I->second, |
| 2171 | ObjCMethodList(), |
| 2172 | ObjCMethodList() |
| 2173 | }; |
| 2174 | if (F != SemaRef.MethodPool.end()) { |
| 2175 | Data.Instance = F->second.first; |
| 2176 | Data.Factory = F->second.second; |
| 2177 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2178 | // Only write this selector if it's not in an existing AST or something |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2179 | // changed. |
| 2180 | if (Chain && I->second < FirstSelectorID) { |
| 2181 | // Selector already exists. Did it change? |
| 2182 | bool changed = false; |
| 2183 | for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; |
| 2184 | M = M->Next) { |
| 2185 | if (M->Method->getPCHLevel() == 0) |
| 2186 | changed = true; |
| 2187 | } |
| 2188 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; |
| 2189 | M = M->Next) { |
| 2190 | if (M->Method->getPCHLevel() == 0) |
| 2191 | changed = true; |
| 2192 | } |
| 2193 | if (!changed) |
| 2194 | continue; |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2195 | } else if (Data.Instance.Method || Data.Factory.Method) { |
| 2196 | // A new method pool entry. |
| 2197 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2198 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2199 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2202 | // Create the on-disk hash table in a buffer. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2203 | llvm::SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2204 | uint32_t BucketOffset; |
| 2205 | { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2206 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2207 | llvm::raw_svector_ostream Out(MethodPool); |
| 2208 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2209 | clang::io::Emit32(Out, 0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2210 | BucketOffset = Generator.Emit(Out, Trait); |
| 2211 | } |
| 2212 | |
| 2213 | // Create a blob abbreviation |
| 2214 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2215 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2216 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2217 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2218 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2219 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2220 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2221 | // Write the method pool |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2222 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2223 | Record.push_back(METHOD_POOL); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2224 | Record.push_back(BucketOffset); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2225 | Record.push_back(NumTableEntries); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2226 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2227 | |
| 2228 | // Create a blob abbreviation for the selector table offsets. |
| 2229 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2230 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2231 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2232 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2233 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2234 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2235 | |
| 2236 | // Write the selector offsets table. |
| 2237 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2238 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2239 | Record.push_back(SelectorOffsets.size()); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2240 | Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2241 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2242 | data(SelectorOffsets)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2243 | } |
| 2244 | } |
| 2245 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2246 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2247 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2248 | using namespace llvm; |
| 2249 | if (SemaRef.ReferencedSelectors.empty()) |
| 2250 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2251 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2252 | RecordData Record; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2253 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2254 | // Note: this writes out all references even for a dependent AST. But it is |
Sebastian Redl | 51c79d8 | 2010-08-04 22:21:29 +0000 | [diff] [blame] | 2255 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 2256 | // headers, probably not worth it. It's not a correctness issue. |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2257 | for (DenseMap<Selector, SourceLocation>::iterator S = |
| 2258 | SemaRef.ReferencedSelectors.begin(), |
| 2259 | E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { |
| 2260 | Selector Sel = (*S).first; |
| 2261 | SourceLocation Loc = (*S).second; |
| 2262 | AddSelectorRef(Sel, Record); |
| 2263 | AddSourceLocation(Loc, Record); |
| 2264 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2265 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2268 | //===----------------------------------------------------------------------===// |
| 2269 | // Identifier Table Serialization |
| 2270 | //===----------------------------------------------------------------------===// |
| 2271 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2272 | namespace { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2273 | class ASTIdentifierTableTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2274 | ASTWriter &Writer; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2275 | Preprocessor &PP; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2276 | |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2277 | /// \brief Determines whether this is an "interesting" identifier |
| 2278 | /// that needs a full IdentifierInfo structure written into the hash |
| 2279 | /// table. |
| 2280 | static bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 2281 | return II->isPoisoned() || |
| 2282 | II->isExtensionToken() || |
| 2283 | II->hasMacroDefinition() || |
| 2284 | II->getObjCOrBuiltinID() || |
| 2285 | II->getFETokenInfo<void>(); |
| 2286 | } |
| 2287 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2288 | public: |
| 2289 | typedef const IdentifierInfo* key_type; |
| 2290 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2291 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2292 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2293 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2294 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2295 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP) |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2296 | : Writer(Writer), PP(PP) { } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2297 | |
| 2298 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 2299 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2300 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2301 | |
| 2302 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2303 | EmitKeyDataLength(raw_ostream& Out, const IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2304 | IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2305 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2306 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
| 2307 | if (isInterestingIdentifier(II)) { |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2308 | DataLen += 2; // 2 bytes for builtin ID, flags |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2309 | if (II->hasMacroDefinition() && |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2310 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro()) |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2311 | DataLen += 4; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2312 | for (IdentifierResolver::iterator D = IdentifierResolver::begin(II), |
| 2313 | DEnd = IdentifierResolver::end(); |
| 2314 | D != DEnd; ++D) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2315 | DataLen += sizeof(DeclID); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2316 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2317 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 2318 | // We emit the key length after the data length so that every |
| 2319 | // string is preceded by a 16-bit length. This matches the PTH |
| 2320 | // format for storing identifiers. |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2321 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2322 | return std::make_pair(KeyLen, DataLen); |
| 2323 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2324 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2325 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2326 | unsigned KeyLen) { |
| 2327 | // Record the location of the key data. This is used when generating |
| 2328 | // the mapping from persistent IDs to strings. |
| 2329 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2330 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2331 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2332 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2333 | void EmitData(raw_ostream& Out, const IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2334 | IdentID ID, unsigned) { |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2335 | if (!isInterestingIdentifier(II)) { |
| 2336 | clang::io::Emit32(Out, ID << 1); |
| 2337 | return; |
| 2338 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2339 | |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2340 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2341 | uint32_t Bits = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2342 | bool hasMacroDefinition = |
| 2343 | II->hasMacroDefinition() && |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2344 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro(); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2345 | Bits = (uint32_t)II->getObjCOrBuiltinID(); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2346 | Bits = (Bits << 1) | unsigned(hasMacroDefinition); |
| 2347 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 2348 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 2349 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2350 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2351 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2352 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2353 | if (hasMacroDefinition) |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2354 | clang::io::Emit32(Out, Writer.getMacroOffset(II)); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2355 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2356 | // Emit the declaration IDs in reverse order, because the |
| 2357 | // IdentifierResolver provides the declarations as they would be |
| 2358 | // visible (e.g., the function "stat" would come before the struct |
| 2359 | // "stat"), but IdentifierResolver::AddDeclToIdentifierChain() |
| 2360 | // adds declarations to the end of the list (so we need to see the |
| 2361 | // struct "status" before the function "status"). |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2362 | // Only emit declarations that aren't from a chained PCH, though. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2363 | SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II), |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2364 | IdentifierResolver::end()); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2365 | for (SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2366 | DEnd = Decls.rend(); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2367 | D != DEnd; ++D) |
Sebastian Redl | 78f5177 | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 2368 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2369 | } |
| 2370 | }; |
| 2371 | } // end anonymous namespace |
| 2372 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2373 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2374 | /// |
| 2375 | /// The identifier table consists of a blob containing string data |
| 2376 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 2377 | /// that maps identifier IDs to locations within the blob. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2378 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2379 | using namespace llvm; |
| 2380 | |
| 2381 | // Create and write out the blob that contains the identifier |
| 2382 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2383 | { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2384 | OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2385 | ASTIdentifierTableTrait Trait(*this, PP); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2386 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2387 | // Look for any identifiers that were named while processing the |
| 2388 | // headers, but are otherwise not needed. We add these to the hash |
| 2389 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2390 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2391 | // file. |
| 2392 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 2393 | IDEnd = PP.getIdentifierTable().end(); |
| 2394 | ID != IDEnd; ++ID) |
| 2395 | getIdentifierRef(ID->second); |
| 2396 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2397 | // Create the on-disk hash table representation. We only store offsets |
| 2398 | // for identifiers that appear here for the first time. |
| 2399 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2400 | for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2401 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 2402 | ID != IDEnd; ++ID) { |
| 2403 | assert(ID->first && "NULL identifier in identifier table"); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2404 | if (!Chain || !ID->first->isFromAST()) |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2405 | Generator.insert(ID->first, ID->second, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2406 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2407 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2408 | // Create the on-disk hash table in a buffer. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2409 | llvm::SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2410 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2411 | { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2412 | ASTIdentifierTableTrait Trait(*this, PP); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2413 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2414 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2415 | clang::io::Emit32(Out, 0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2416 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | // Create a blob abbreviation |
| 2420 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2421 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2422 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2423 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2424 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2425 | |
| 2426 | // Write the identifier table |
| 2427 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2428 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2429 | Record.push_back(BucketOffset); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2430 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2434 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2435 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2436 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2437 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2438 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2439 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2440 | |
| 2441 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2442 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2443 | Record.push_back(IdentifierOffsets.size()); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2444 | Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2445 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2446 | data(IdentifierOffsets)); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2447 | } |
| 2448 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2449 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2450 | // DeclContext's Name Lookup Table Serialization |
| 2451 | //===----------------------------------------------------------------------===// |
| 2452 | |
| 2453 | namespace { |
| 2454 | // Trait used for the on-disk hash table used in the method pool. |
| 2455 | class ASTDeclContextNameLookupTrait { |
| 2456 | ASTWriter &Writer; |
| 2457 | |
| 2458 | public: |
| 2459 | typedef DeclarationName key_type; |
| 2460 | typedef key_type key_type_ref; |
| 2461 | |
| 2462 | typedef DeclContext::lookup_result data_type; |
| 2463 | typedef const data_type& data_type_ref; |
| 2464 | |
| 2465 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 2466 | |
| 2467 | unsigned ComputeHash(DeclarationName Name) { |
| 2468 | llvm::FoldingSetNodeID ID; |
| 2469 | ID.AddInteger(Name.getNameKind()); |
| 2470 | |
| 2471 | switch (Name.getNameKind()) { |
| 2472 | case DeclarationName::Identifier: |
| 2473 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 2474 | break; |
| 2475 | case DeclarationName::ObjCZeroArgSelector: |
| 2476 | case DeclarationName::ObjCOneArgSelector: |
| 2477 | case DeclarationName::ObjCMultiArgSelector: |
| 2478 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 2479 | break; |
| 2480 | case DeclarationName::CXXConstructorName: |
| 2481 | case DeclarationName::CXXDestructorName: |
| 2482 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2483 | break; |
| 2484 | case DeclarationName::CXXOperatorName: |
| 2485 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 2486 | break; |
| 2487 | case DeclarationName::CXXLiteralOperatorName: |
| 2488 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 2489 | case DeclarationName::CXXUsingDirective: |
| 2490 | break; |
| 2491 | } |
| 2492 | |
| 2493 | return ID.ComputeHash(); |
| 2494 | } |
| 2495 | |
| 2496 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2497 | EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2498 | data_type_ref Lookup) { |
| 2499 | unsigned KeyLen = 1; |
| 2500 | switch (Name.getNameKind()) { |
| 2501 | case DeclarationName::Identifier: |
| 2502 | case DeclarationName::ObjCZeroArgSelector: |
| 2503 | case DeclarationName::ObjCOneArgSelector: |
| 2504 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2505 | case DeclarationName::CXXLiteralOperatorName: |
| 2506 | KeyLen += 4; |
| 2507 | break; |
| 2508 | case DeclarationName::CXXOperatorName: |
| 2509 | KeyLen += 1; |
| 2510 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2511 | case DeclarationName::CXXConstructorName: |
| 2512 | case DeclarationName::CXXDestructorName: |
| 2513 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2514 | case DeclarationName::CXXUsingDirective: |
| 2515 | break; |
| 2516 | } |
| 2517 | clang::io::Emit16(Out, KeyLen); |
| 2518 | |
| 2519 | // 2 bytes for num of decls and 4 for each DeclID. |
| 2520 | unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); |
| 2521 | clang::io::Emit16(Out, DataLen); |
| 2522 | |
| 2523 | return std::make_pair(KeyLen, DataLen); |
| 2524 | } |
| 2525 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2526 | void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2527 | using namespace clang::io; |
| 2528 | |
| 2529 | assert(Name.getNameKind() < 0x100 && "Invalid name kind ?"); |
| 2530 | Emit8(Out, Name.getNameKind()); |
| 2531 | switch (Name.getNameKind()) { |
| 2532 | case DeclarationName::Identifier: |
| 2533 | Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
| 2534 | break; |
| 2535 | case DeclarationName::ObjCZeroArgSelector: |
| 2536 | case DeclarationName::ObjCOneArgSelector: |
| 2537 | case DeclarationName::ObjCMultiArgSelector: |
| 2538 | Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); |
| 2539 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2540 | case DeclarationName::CXXOperatorName: |
| 2541 | assert(Name.getCXXOverloadedOperator() < 0x100 && "Invalid operator ?"); |
| 2542 | Emit8(Out, Name.getCXXOverloadedOperator()); |
| 2543 | break; |
| 2544 | case DeclarationName::CXXLiteralOperatorName: |
| 2545 | Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
| 2546 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2547 | case DeclarationName::CXXConstructorName: |
| 2548 | case DeclarationName::CXXDestructorName: |
| 2549 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2550 | case DeclarationName::CXXUsingDirective: |
| 2551 | break; |
| 2552 | } |
| 2553 | } |
| 2554 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2555 | void EmitData(raw_ostream& Out, key_type_ref, |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2556 | data_type Lookup, unsigned DataLen) { |
| 2557 | uint64_t Start = Out.tell(); (void)Start; |
| 2558 | clang::io::Emit16(Out, Lookup.second - Lookup.first); |
| 2559 | for (; Lookup.first != Lookup.second; ++Lookup.first) |
| 2560 | clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); |
| 2561 | |
| 2562 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 2563 | } |
| 2564 | }; |
| 2565 | } // end anonymous namespace |
| 2566 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2567 | /// \brief Write the block containing all of the declaration IDs |
| 2568 | /// visible from the given DeclContext. |
| 2569 | /// |
| 2570 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2571 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2572 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 2573 | DeclContext *DC) { |
| 2574 | if (DC->getPrimaryContext() != DC) |
| 2575 | return 0; |
| 2576 | |
| 2577 | // Since there is no name lookup into functions or methods, don't bother to |
| 2578 | // build a visible-declarations table for these entities. |
| 2579 | if (DC->isFunctionOrMethod()) |
| 2580 | return 0; |
| 2581 | |
| 2582 | // If not in C++, we perform name lookup for the translation unit via the |
| 2583 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 2584 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 2585 | // friend declarations, is there a way to do this without writing the table ? |
| 2586 | if (DC->isTranslationUnit() && !Context.getLangOptions().CPlusPlus) |
| 2587 | return 0; |
| 2588 | |
| 2589 | // Force the DeclContext to build a its name-lookup table. |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 2590 | if (DC->hasExternalVisibleStorage()) |
| 2591 | DC->MaterializeVisibleDeclsFromExternalStorage(); |
| 2592 | else |
| 2593 | DC->lookup(DeclarationName()); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2594 | |
| 2595 | // Serialize the contents of the mapping used for lookup. Note that, |
| 2596 | // although we have two very different code paths, the serialized |
| 2597 | // representation is the same for both cases: a declaration name, |
| 2598 | // followed by a size, followed by references to the visible |
| 2599 | // declarations that have that name. |
| 2600 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 2601 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 2602 | if (!Map || Map->empty()) |
| 2603 | return 0; |
| 2604 | |
| 2605 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2606 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2607 | |
| 2608 | // Create the on-disk hash table representation. |
| 2609 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2610 | D != DEnd; ++D) { |
| 2611 | DeclarationName Name = D->first; |
| 2612 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
| 2613 | Generator.insert(Name, Result, Trait); |
| 2614 | } |
| 2615 | |
| 2616 | // Create the on-disk hash table in a buffer. |
| 2617 | llvm::SmallString<4096> LookupTable; |
| 2618 | uint32_t BucketOffset; |
| 2619 | { |
| 2620 | llvm::raw_svector_ostream Out(LookupTable); |
| 2621 | // Make sure that no bucket is at offset 0 |
| 2622 | clang::io::Emit32(Out, 0); |
| 2623 | BucketOffset = Generator.Emit(Out, Trait); |
| 2624 | } |
| 2625 | |
| 2626 | // Write the lookup table |
| 2627 | RecordData Record; |
| 2628 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 2629 | Record.push_back(BucketOffset); |
| 2630 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
| 2631 | LookupTable.str()); |
| 2632 | |
| 2633 | Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); |
| 2634 | ++NumVisibleDeclContexts; |
| 2635 | return Offset; |
| 2636 | } |
| 2637 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2638 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 2639 | /// |
| 2640 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 2641 | /// DeclContext in a dependent AST file. As such, they only exist for the TU |
| 2642 | /// (in C++) and for namespaces. |
| 2643 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2644 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 2645 | if (!Map || Map->empty()) |
| 2646 | return; |
| 2647 | |
| 2648 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2649 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2650 | |
| 2651 | // Create the hash table. |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2652 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2653 | D != DEnd; ++D) { |
| 2654 | DeclarationName Name = D->first; |
| 2655 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Sebastian Redl | 9617e7e | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 2656 | // For any name that appears in this table, the results are complete, i.e. |
| 2657 | // they overwrite results from previous PCHs. Merging is always a mess. |
| 2658 | Generator.insert(Name, Result, Trait); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | // Create the on-disk hash table in a buffer. |
| 2662 | llvm::SmallString<4096> LookupTable; |
| 2663 | uint32_t BucketOffset; |
| 2664 | { |
| 2665 | llvm::raw_svector_ostream Out(LookupTable); |
| 2666 | // Make sure that no bucket is at offset 0 |
| 2667 | clang::io::Emit32(Out, 0); |
| 2668 | BucketOffset = Generator.Emit(Out, Trait); |
| 2669 | } |
| 2670 | |
| 2671 | // Write the lookup table |
| 2672 | RecordData Record; |
| 2673 | Record.push_back(UPDATE_VISIBLE); |
| 2674 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 2675 | Record.push_back(BucketOffset); |
| 2676 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); |
| 2677 | } |
| 2678 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2679 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 2680 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 2681 | RecordData Record; |
| 2682 | Record.push_back(Opts.fp_contract); |
| 2683 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 2684 | } |
| 2685 | |
| 2686 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 2687 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
| 2688 | if (!SemaRef.Context.getLangOptions().OpenCL) |
| 2689 | return; |
| 2690 | |
| 2691 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 2692 | RecordData Record; |
| 2693 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 2694 | #include "clang/Basic/OpenCLExtensions.def" |
| 2695 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 2696 | } |
| 2697 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2698 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2699 | // General Serialization Routines |
| 2700 | //===----------------------------------------------------------------------===// |
| 2701 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2702 | /// \brief Write a record containing the given attributes. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 2703 | void ASTWriter::WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 2704 | Record.push_back(Attrs.size()); |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2705 | for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){ |
| 2706 | const Attr * A = *i; |
| 2707 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
| 2708 | AddSourceLocation(A->getLocation(), Record); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2709 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2710 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 2711 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2712 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2715 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2716 | Record.push_back(Str.size()); |
| 2717 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 2718 | } |
| 2719 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 2720 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 2721 | RecordDataImpl &Record) { |
| 2722 | Record.push_back(Version.getMajor()); |
| 2723 | if (llvm::Optional<unsigned> Minor = Version.getMinor()) |
| 2724 | Record.push_back(*Minor + 1); |
| 2725 | else |
| 2726 | Record.push_back(0); |
| 2727 | if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) |
| 2728 | Record.push_back(*Subminor + 1); |
| 2729 | else |
| 2730 | Record.push_back(0); |
| 2731 | } |
| 2732 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2733 | /// \brief Note that the identifier II occurs at the given offset |
| 2734 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2735 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2736 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2737 | // Only store offsets new to this AST file. Other identifier names are looked |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2738 | // up earlier in the chain and thus don't need an offset. |
| 2739 | if (ID >= FirstIdentID) |
| 2740 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2743 | /// \brief Note that the selector Sel occurs at the given offset |
| 2744 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2745 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2746 | unsigned ID = SelectorIDs[Sel]; |
| 2747 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2748 | // Don't record offsets for selectors that are also available in a different |
| 2749 | // file. |
| 2750 | if (ID < FirstSelectorID) |
| 2751 | return; |
| 2752 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2755 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 2756 | : Stream(Stream), Context(0), Chain(0), SerializationListener(0), |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2757 | FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2758 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2759 | FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2760 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2761 | FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID), |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 2762 | CollectedStmts(&StmtsToEmit), |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2763 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 2764 | NumVisibleDeclContexts(0), |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2765 | NextCXXBaseSpecifiersID(1), |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 2766 | DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 2767 | DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), |
| 2768 | DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), |
| 2769 | DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 2770 | DeclTypedefAbbrev(0), |
| 2771 | DeclVarAbbrev(0), DeclFieldAbbrev(0), |
| 2772 | DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2773 | { |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 2774 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2775 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2776 | void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2777 | const std::string &OutputFile, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2778 | StringRef isysroot) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2779 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2780 | Stream.Emit((unsigned)'C', 8); |
| 2781 | Stream.Emit((unsigned)'P', 8); |
| 2782 | Stream.Emit((unsigned)'C', 8); |
| 2783 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2784 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 2785 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2786 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 2787 | Context = &SemaRef.Context; |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 2788 | WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile); |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 2789 | Context = 0; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 2792 | template<typename Vector> |
| 2793 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 2794 | ASTWriter::RecordData &Record) { |
| 2795 | for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end(); |
| 2796 | I != E; ++I) { |
| 2797 | Writer.AddDeclRef(*I, Record); |
| 2798 | } |
| 2799 | } |
| 2800 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2801 | void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2802 | StringRef isysroot, |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2803 | const std::string &OutputFile) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2804 | using namespace llvm; |
| 2805 | |
| 2806 | ASTContext &Context = SemaRef.Context; |
| 2807 | Preprocessor &PP = SemaRef.PP; |
| 2808 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2809 | // Set up predefined declaration IDs. |
| 2810 | DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2811 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 2812 | if (!Chain) { |
| 2813 | // Make sure that we emit IdentifierInfos (and any attached |
| 2814 | // declarations) for builtins. We don't need to do this when we're |
| 2815 | // emitting chained PCH files, because all of the builtins will be |
| 2816 | // in the original PCH file. |
| 2817 | // FIXME: Modules won't like this at all. |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2818 | IdentifierTable &Table = PP.getIdentifierTable(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2819 | SmallVector<const char *, 32> BuiltinNames; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2820 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
| 2821 | Context.getLangOptions().NoBuiltin); |
| 2822 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 2823 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 2824 | } |
| 2825 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2826 | // Build a record containing all of the tentative definitions in this file, in |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 2827 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2828 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2829 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 2830 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 2831 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2832 | // Build a record containing all of the file scoped decls in this file. |
| 2833 | RecordData UnusedFileScopedDecls; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 2834 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 2835 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2836 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 2837 | // Build a record containing all of the delegating constructors we still need |
| 2838 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2839 | RecordData DelegatingCtorDecls; |
Douglas Gregor | bae3120 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 2840 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2841 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 2842 | // Write the set of weak, undeclared identifiers. We always write the |
| 2843 | // entire table, since later PCH files in a PCH chain are only interested in |
| 2844 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2845 | RecordData WeakUndeclaredIdentifiers; |
| 2846 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2847 | for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2848 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 2849 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 2850 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 2851 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 2852 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 2853 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 2854 | } |
| 2855 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2856 | |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2857 | // Build a record containing all of the locally-scoped external |
| 2858 | // declarations in this header file. Generally, this record will be |
| 2859 | // empty. |
| 2860 | RecordData LocallyScopedExternalDecls; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2861 | // FIXME: This is filling in the AST file in densemap order which is |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2862 | // nondeterminstic! |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2863 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2864 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 2865 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 2866 | TD != TDEnd; ++TD) { |
| 2867 | if (TD->second->getPCHLevel() == 0) |
| 2868 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 2869 | } |
| 2870 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2871 | // Build a record containing all of the ext_vector declarations. |
| 2872 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 2873 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2874 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2875 | // Build a record containing all of the VTable uses information. |
| 2876 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 2877 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 2878 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 2879 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 2880 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 2881 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 2882 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | // Build a record containing all of dynamic classes declarations. |
| 2886 | RecordData DynamicClasses; |
Douglas Gregor | 3200219 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 2887 | AddLazyVectorDecls(*this, SemaRef.DynamicClasses, DynamicClasses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2888 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2889 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 2890 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2891 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 2892 | I = SemaRef.PendingInstantiations.begin(), |
| 2893 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 2894 | AddDeclRef(I->first, PendingInstantiations); |
| 2895 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2896 | } |
| 2897 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 2898 | "There are local ones at end of translation unit!"); |
| 2899 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2900 | // Build a record containing some declaration references. |
| 2901 | RecordData SemaDeclRefs; |
| 2902 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 2903 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 2904 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 2905 | } |
| 2906 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2907 | RecordData CUDASpecialDeclRefs; |
| 2908 | if (Context.getcudaConfigureCallDecl()) { |
| 2909 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 2910 | } |
| 2911 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2912 | // Build a record containing all of the known namespaces. |
| 2913 | RecordData KnownNamespaces; |
| 2914 | for (llvm::DenseMap<NamespaceDecl*, bool>::iterator |
| 2915 | I = SemaRef.KnownNamespaces.begin(), |
| 2916 | IEnd = SemaRef.KnownNamespaces.end(); |
| 2917 | I != IEnd; ++I) { |
| 2918 | if (!I->second) |
| 2919 | AddDeclRef(I->first, KnownNamespaces); |
| 2920 | } |
| 2921 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2922 | // Write the remaining AST contents. |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2923 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2924 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2925 | WriteMetadata(Context, isysroot, OutputFile); |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2926 | WriteLanguageOptions(Context.getLangOptions()); |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2927 | if (StatCalls && isysroot.empty()) |
Douglas Gregor | 11cfd94 | 2010-07-12 23:48:14 +0000 | [diff] [blame] | 2928 | WriteStatCache(*StatCalls); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2929 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Douglas Gregor | 2df17cb | 2011-08-01 16:54:33 +0000 | [diff] [blame] | 2930 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 2931 | if (Chain) { |
| 2932 | // Write the mapping information describing our module dependencies and how |
| 2933 | // each of those modules were mapped into our own offset/ID space, so that |
| 2934 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 2935 | // The map consists solely of a blob with the following format: |
| 2936 | // *(module-name-len:i16 module-name:len*i8 |
| 2937 | // source-location-offset:i32 |
| 2938 | // identifier-id:i32 |
| 2939 | // preprocessed-entity-id:i32 |
| 2940 | // macro-definition-id:i32 |
| 2941 | // selector-id:i32 |
| 2942 | // declaration-id:i32 |
| 2943 | // c++-base-specifiers-id:i32 |
| 2944 | // type-id:i32) |
| 2945 | // |
| 2946 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2947 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 2948 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2949 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2950 | llvm::SmallString<2048> Buffer; |
| 2951 | { |
| 2952 | llvm::raw_svector_ostream Out(Buffer); |
| 2953 | for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), |
| 2954 | MEnd = Chain->ModuleMgr.end(); |
| 2955 | M != MEnd; ++M) { |
| 2956 | StringRef FileName = (*M)->FileName; |
| 2957 | io::Emit16(Out, FileName.size()); |
| 2958 | Out.write(FileName.data(), FileName.size()); |
| 2959 | io::Emit32(Out, (*M)->SLocEntryBaseOffset); |
| 2960 | io::Emit32(Out, (*M)->BaseIdentifierID); |
| 2961 | io::Emit32(Out, (*M)->BasePreprocessedEntityID); |
| 2962 | io::Emit32(Out, (*M)->BaseMacroDefinitionID); |
| 2963 | io::Emit32(Out, (*M)->BaseSelectorID); |
| 2964 | io::Emit32(Out, (*M)->BaseDeclID); |
| 2965 | io::Emit32(Out, (*M)->BaseTypeIndex); |
| 2966 | } |
| 2967 | } |
| 2968 | Record.clear(); |
| 2969 | Record.push_back(MODULE_OFFSET_MAP); |
| 2970 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 2971 | Buffer.data(), Buffer.size()); |
| 2972 | } |
| 2973 | |
| 2974 | // Create a lexical update block containing all of the declarations in the |
| 2975 | // translation unit that do not come from other AST files. |
| 2976 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
| 2977 | SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
| 2978 | for (DeclContext::decl_iterator I = TU->noload_decls_begin(), |
| 2979 | E = TU->noload_decls_end(); |
| 2980 | I != E; ++I) { |
| 2981 | if ((*I)->getPCHLevel() == 0) |
| 2982 | NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); |
| 2983 | else if ((*I)->isChangedSinceDeserialization()) |
| 2984 | (void)GetDeclRef(*I); // Make sure it's written, but don't record it. |
| 2985 | } |
| 2986 | |
| 2987 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 2988 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 2989 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 2990 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 2991 | Record.clear(); |
| 2992 | Record.push_back(TU_UPDATE_LEXICAL); |
| 2993 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 2994 | data(NewGlobalDecls)); |
| 2995 | |
| 2996 | // And a visible updates block for the translation unit. |
| 2997 | Abv = new llvm::BitCodeAbbrev(); |
| 2998 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 2999 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3000 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 3001 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3002 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 3003 | WriteDeclContextVisibleUpdate(TU); |
| 3004 | |
| 3005 | // If the translation unit has an anonymous namespace, and we don't already |
| 3006 | // have an update block for it, write it as an update block. |
| 3007 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 3008 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
| 3009 | if (Record.empty()) { |
| 3010 | Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE); |
| 3011 | AddDeclRef(NS, Record); |
| 3012 | } |
| 3013 | } |
| 3014 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3015 | // Form the record of special types. |
| 3016 | RecordData SpecialTypes; |
| 3017 | AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes); |
Douglas Gregor | 09c4aa8 | 2011-08-11 22:04:35 +0000 | [diff] [blame] | 3018 | AddTypeRef(Context.ObjCIdTypedefType, SpecialTypes); |
| 3019 | AddTypeRef(Context.ObjCSelTypedefType, SpecialTypes); |
| 3020 | AddTypeRef(Context.ObjCProtoType, SpecialTypes); |
| 3021 | AddTypeRef(Context.ObjCClassTypedefType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3022 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3023 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 3024 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 3025 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 3026 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 3027 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3028 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3029 | SpecialTypes.push_back(Context.isInt128Installed()); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3030 | |
Douglas Gregor | 1970d88 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3031 | // Keep writing types and declarations until all types and |
| 3032 | // declarations have been written. |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3033 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3034 | WriteDeclsBlockAbbrevs(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 3035 | for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), |
| 3036 | E = DeclsToRewrite.end(); |
| 3037 | I != E; ++I) |
| 3038 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3039 | while (!DeclTypesToEmit.empty()) { |
| 3040 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 3041 | DeclTypesToEmit.pop(); |
| 3042 | if (DOT.isType()) |
| 3043 | WriteType(DOT.getType()); |
| 3044 | else |
| 3045 | WriteDecl(Context, DOT.getDecl()); |
| 3046 | } |
| 3047 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3048 | |
Douglas Gregor | 4505315 | 2009-10-17 17:25:45 +0000 | [diff] [blame] | 3049 | WritePreprocessor(PP); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3050 | WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3051 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3052 | WriteReferencedSelectorsPool(SemaRef); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 3053 | WriteIdentifierTable(PP); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3054 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 3055 | WriteOpenCLExtensions(SemaRef); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3056 | |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3057 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3058 | WritePragmaDiagnosticMappings(Context.getDiagnostics()); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3059 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 3060 | WriteCXXBaseSpecifiersOffsets(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3061 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3062 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 3063 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 3064 | /// Build a record containing first declarations from a chained PCH and the |
| 3065 | /// most recent declarations in this AST that they point to. |
| 3066 | RecordData FirstLatestDeclIDs; |
| 3067 | for (FirstLatestDeclMap::iterator I = FirstLatestDecls.begin(), |
| 3068 | E = FirstLatestDecls.end(); |
| 3069 | I != E; ++I) { |
| 3070 | assert(I->first->getPCHLevel() > I->second->getPCHLevel() && |
| 3071 | "Expected first & second to be in different PCHs"); |
| 3072 | AddDeclRef(I->first, FirstLatestDeclIDs); |
| 3073 | AddDeclRef(I->second, FirstLatestDeclIDs); |
| 3074 | } |
| 3075 | |
| 3076 | if (!FirstLatestDeclIDs.empty()) |
| 3077 | Stream.EmitRecord(REDECLS_UPDATE_LATEST, FirstLatestDeclIDs); |
| 3078 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3079 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3080 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3081 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3082 | |
| 3083 | // Write the record containing tentative definitions. |
| 3084 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3085 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3086 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3087 | // Write the record containing unused file scoped decls. |
| 3088 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3089 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3090 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3091 | // Write the record containing weak undeclared identifiers. |
| 3092 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3093 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3094 | WeakUndeclaredIdentifiers); |
| 3095 | |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3096 | // Write the record containing locally-scoped external definitions. |
| 3097 | if (!LocallyScopedExternalDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3098 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3099 | LocallyScopedExternalDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3100 | |
| 3101 | // Write the record containing ext_vector type names. |
| 3102 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3103 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3104 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3105 | // Write the record containing VTable uses information. |
| 3106 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3107 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3108 | |
| 3109 | // Write the record containing dynamic classes declarations. |
| 3110 | if (!DynamicClasses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3111 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3112 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3113 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3114 | if (!PendingInstantiations.empty()) |
| 3115 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3116 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3117 | // Write the record containing declaration references of Sema. |
| 3118 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3119 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3120 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3121 | // Write the record containing CUDA-specific declaration references. |
| 3122 | if (!CUDASpecialDeclRefs.empty()) |
| 3123 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3124 | |
| 3125 | // Write the delegating constructors. |
| 3126 | if (!DelegatingCtorDecls.empty()) |
| 3127 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3128 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3129 | // Write the known namespaces. |
| 3130 | if (!KnownNamespaces.empty()) |
| 3131 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
| 3132 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 3133 | // Write the visible updates to DeclContexts. |
| 3134 | for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |
| 3135 | I = UpdatedDeclContexts.begin(), |
| 3136 | E = UpdatedDeclContexts.end(); |
| 3137 | I != E; ++I) |
| 3138 | WriteDeclContextVisibleUpdate(*I); |
| 3139 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3140 | WriteDeclUpdatesBlocks(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame^] | 3141 | WriteDeclReplacementsBlock(); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3142 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3143 | // Some simple statistics |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3144 | Record.clear(); |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3145 | Record.push_back(NumStatements); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 3146 | Record.push_back(NumMacros); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3147 | Record.push_back(NumLexicalDeclContexts); |
| 3148 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3149 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3150 | Stream.ExitBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3151 | } |
| 3152 | |
Argyrios Kyrtzidis | 97bfda9 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3153 | void ASTWriter::WriteDeclUpdatesBlocks() { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3154 | if (DeclUpdates.empty()) |
| 3155 | return; |
| 3156 | |
| 3157 | RecordData OffsetsRecord; |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3158 | Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3159 | for (DeclUpdateMap::iterator |
| 3160 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3161 | const Decl *D = I->first; |
| 3162 | UpdateRecord &URec = I->second; |
| 3163 | |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 3164 | if (DeclsToRewrite.count(D)) |
| 3165 | continue; // The decl will be written completely,no need to store updates. |
| 3166 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3167 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 3168 | Stream.EmitRecord(DECL_UPDATES, URec); |
| 3169 | |
| 3170 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 3171 | OffsetsRecord.push_back(Offset); |
| 3172 | } |
| 3173 | Stream.ExitBlock(); |
| 3174 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); |
| 3175 | } |
| 3176 | |
Argyrios Kyrtzidis | 97bfda9 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3177 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3178 | if (ReplacedDecls.empty()) |
| 3179 | return; |
| 3180 | |
| 3181 | RecordData Record; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3182 | for (SmallVector<std::pair<DeclID, uint64_t>, 16>::iterator |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3183 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
| 3184 | Record.push_back(I->first); |
| 3185 | Record.push_back(I->second); |
| 3186 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3187 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3188 | } |
| 3189 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3190 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3191 | Record.push_back(Loc.getRawEncoding()); |
| 3192 | } |
| 3193 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3194 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3195 | AddSourceLocation(Range.getBegin(), Record); |
| 3196 | AddSourceLocation(Range.getEnd(), Record); |
| 3197 | } |
| 3198 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3199 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3200 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3201 | const uint64_t *Words = Value.getRawData(); |
| 3202 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3205 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3206 | Record.push_back(Value.isUnsigned()); |
| 3207 | AddAPInt(Value, Record); |
| 3208 | } |
| 3209 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3210 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 3211 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 3212 | } |
| 3213 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3214 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3215 | Record.push_back(getIdentifierRef(II)); |
| 3216 | } |
| 3217 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3218 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3219 | if (II == 0) |
| 3220 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3221 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3222 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3223 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3224 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3225 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3226 | } |
| 3227 | |
Sebastian Redl | 50e2658 | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 3228 | MacroID ASTWriter::getMacroDefinitionID(MacroDefinition *MD) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3229 | if (MD == 0) |
| 3230 | return 0; |
Sebastian Redl | 50e2658 | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 3231 | |
| 3232 | MacroID &ID = MacroDefinitions[MD]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3233 | if (ID == 0) |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3234 | ID = NextMacroID++; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3235 | return ID; |
| 3236 | } |
| 3237 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3238 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3239 | Record.push_back(getSelectorRef(SelRef)); |
| 3240 | } |
| 3241 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3242 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3243 | if (Sel.getAsOpaquePtr() == 0) { |
| 3244 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3247 | SelectorID &SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3248 | if (SID == 0 && Chain) { |
| 3249 | // This might trigger a ReadSelector callback, which will set the ID for |
| 3250 | // this selector. |
| 3251 | Chain->LoadSelector(Sel); |
| 3252 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3253 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3254 | SID = NextSelectorID++; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3255 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3256 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3259 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 3260 | AddDeclRef(Temp->getDestructor(), Record); |
| 3261 | } |
| 3262 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3263 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
| 3264 | CXXBaseSpecifier const *BasesEnd, |
| 3265 | RecordDataImpl &Record) { |
| 3266 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 3267 | CXXBaseSpecifiersToWrite.push_back( |
| 3268 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 3269 | Bases, BasesEnd)); |
| 3270 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 3271 | } |
| 3272 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3273 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3274 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3275 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3276 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3277 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3278 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3279 | break; |
| 3280 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3281 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3282 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3283 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3284 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3285 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3286 | break; |
| 3287 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3288 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3289 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3290 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3291 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3292 | case TemplateArgument::Null: |
| 3293 | case TemplateArgument::Integral: |
| 3294 | case TemplateArgument::Declaration: |
| 3295 | case TemplateArgument::Pack: |
| 3296 | break; |
| 3297 | } |
| 3298 | } |
| 3299 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3300 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3301 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3302 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3303 | |
| 3304 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 3305 | bool InfoHasSameExpr |
| 3306 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 3307 | Record.push_back(InfoHasSameExpr); |
| 3308 | if (InfoHasSameExpr) |
| 3309 | return; // Avoid storing the same expr twice. |
| 3310 | } |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3311 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 3312 | Record); |
| 3313 | } |
| 3314 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3315 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 3316 | RecordDataImpl &Record) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3317 | if (TInfo == 0) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3318 | AddTypeRef(QualType(), Record); |
| 3319 | return; |
| 3320 | } |
| 3321 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3322 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 3323 | } |
| 3324 | |
| 3325 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 3326 | AddTypeRef(TL.getType(), Record); |
| 3327 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3328 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3329 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3330 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3331 | } |
| 3332 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3333 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 3334 | Record.push_back(GetOrCreateTypeID(T)); |
| 3335 | } |
| 3336 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3337 | TypeID ASTWriter::GetOrCreateTypeID( QualType T) { |
| 3338 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3339 | std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); |
| 3340 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3341 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3342 | TypeID ASTWriter::getTypeID(QualType T) const { |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3343 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3344 | std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); |
Argyrios Kyrtzidis | e394f2c | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { |
| 3348 | if (T.isNull()) |
| 3349 | return TypeIdx(); |
| 3350 | assert(!T.getLocalFastQualifiers()); |
| 3351 | |
Argyrios Kyrtzidis | a7fbbb0 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 3352 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3353 | if (Idx.getIndex() == 0) { |
Douglas Gregor | 1970d88 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3354 | // We haven't seen this type before. Assign it a new ID and put it |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3355 | // into the queue of types to emit. |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3356 | Idx = TypeIdx(NextTypeID++); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3357 | DeclTypesToEmit.push(T); |
Douglas Gregor | 1970d88 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3358 | } |
Argyrios Kyrtzidis | e394f2c | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3359 | return Idx; |
| 3360 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3361 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3362 | TypeIdx ASTWriter::getTypeIdx(QualType T) const { |
Argyrios Kyrtzidis | e394f2c | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3363 | if (T.isNull()) |
| 3364 | return TypeIdx(); |
| 3365 | assert(!T.getLocalFastQualifiers()); |
| 3366 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3367 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3368 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 3369 | return I->second; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3372 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3373 | Record.push_back(GetDeclRef(D)); |
| 3374 | } |
| 3375 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3376 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3377 | if (D == 0) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3378 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3379 | } |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3380 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3381 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3382 | if (ID == 0) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3383 | // We haven't seen this declaration before. Give it a new ID and |
| 3384 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3385 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3386 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3387 | } else if (ID < FirstDeclID && D->isChangedSinceDeserialization()) { |
| 3388 | // We don't add it to the replacement collection here, because we don't |
| 3389 | // have the offset yet. |
| 3390 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
| 3391 | // Reset the flag, so that we don't add this decl multiple times. |
| 3392 | const_cast<Decl *>(D)->setChangedSinceDeserialization(false); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3393 | } |
| 3394 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3395 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3396 | } |
| 3397 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3398 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3399 | if (D == 0) |
| 3400 | return 0; |
| 3401 | |
| 3402 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 3403 | return DeclIDs[D]; |
| 3404 | } |
| 3405 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3406 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 3407 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3408 | Record.push_back(Name.getNameKind()); |
| 3409 | switch (Name.getNameKind()) { |
| 3410 | case DeclarationName::Identifier: |
| 3411 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 3412 | break; |
| 3413 | |
| 3414 | case DeclarationName::ObjCZeroArgSelector: |
| 3415 | case DeclarationName::ObjCOneArgSelector: |
| 3416 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3417 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3418 | break; |
| 3419 | |
| 3420 | case DeclarationName::CXXConstructorName: |
| 3421 | case DeclarationName::CXXDestructorName: |
| 3422 | case DeclarationName::CXXConversionFunctionName: |
| 3423 | AddTypeRef(Name.getCXXNameType(), Record); |
| 3424 | break; |
| 3425 | |
| 3426 | case DeclarationName::CXXOperatorName: |
| 3427 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 3428 | break; |
| 3429 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3430 | case DeclarationName::CXXLiteralOperatorName: |
| 3431 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 3432 | break; |
| 3433 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3434 | case DeclarationName::CXXUsingDirective: |
| 3435 | // No extra data to emit |
| 3436 | break; |
| 3437 | } |
| 3438 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3439 | |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3440 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3441 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3442 | switch (Name.getNameKind()) { |
| 3443 | case DeclarationName::CXXConstructorName: |
| 3444 | case DeclarationName::CXXDestructorName: |
| 3445 | case DeclarationName::CXXConversionFunctionName: |
| 3446 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 3447 | break; |
| 3448 | |
| 3449 | case DeclarationName::CXXOperatorName: |
| 3450 | AddSourceLocation( |
| 3451 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 3452 | Record); |
| 3453 | AddSourceLocation( |
| 3454 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 3455 | Record); |
| 3456 | break; |
| 3457 | |
| 3458 | case DeclarationName::CXXLiteralOperatorName: |
| 3459 | AddSourceLocation( |
| 3460 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 3461 | Record); |
| 3462 | break; |
| 3463 | |
| 3464 | case DeclarationName::Identifier: |
| 3465 | case DeclarationName::ObjCZeroArgSelector: |
| 3466 | case DeclarationName::ObjCOneArgSelector: |
| 3467 | case DeclarationName::ObjCMultiArgSelector: |
| 3468 | case DeclarationName::CXXUsingDirective: |
| 3469 | break; |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3474 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3475 | AddDeclarationName(NameInfo.getName(), Record); |
| 3476 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 3477 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 3478 | } |
| 3479 | |
| 3480 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3481 | RecordDataImpl &Record) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3482 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3483 | Record.push_back(Info.NumTemplParamLists); |
| 3484 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 3485 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 3486 | } |
| 3487 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3488 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3489 | RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3490 | // Nested name specifiers usually aren't too long. I think that 8 would |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 3491 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3492 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3493 | |
| 3494 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 3495 | while (NNS) { |
| 3496 | NestedNames.push_back(NNS); |
| 3497 | NNS = NNS->getPrefix(); |
| 3498 | } |
| 3499 | |
| 3500 | Record.push_back(NestedNames.size()); |
| 3501 | while(!NestedNames.empty()) { |
| 3502 | NNS = NestedNames.pop_back_val(); |
| 3503 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 3504 | Record.push_back(Kind); |
| 3505 | switch (Kind) { |
| 3506 | case NestedNameSpecifier::Identifier: |
| 3507 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 3508 | break; |
| 3509 | |
| 3510 | case NestedNameSpecifier::Namespace: |
| 3511 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 3512 | break; |
| 3513 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 3514 | case NestedNameSpecifier::NamespaceAlias: |
| 3515 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 3516 | break; |
| 3517 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3518 | case NestedNameSpecifier::TypeSpec: |
| 3519 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3520 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 3521 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 3522 | break; |
| 3523 | |
| 3524 | case NestedNameSpecifier::Global: |
| 3525 | // Don't need to write an associated value. |
| 3526 | break; |
| 3527 | } |
| 3528 | } |
| 3529 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3531 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 3532 | RecordDataImpl &Record) { |
| 3533 | // Nested name specifiers usually aren't too long. I think that 8 would |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 3534 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3535 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3536 | |
| 3537 | // Push each of the nested-name-specifiers's onto a stack for |
| 3538 | // serialization in reverse order. |
| 3539 | while (NNS) { |
| 3540 | NestedNames.push_back(NNS); |
| 3541 | NNS = NNS.getPrefix(); |
| 3542 | } |
| 3543 | |
| 3544 | Record.push_back(NestedNames.size()); |
| 3545 | while(!NestedNames.empty()) { |
| 3546 | NNS = NestedNames.pop_back_val(); |
| 3547 | NestedNameSpecifier::SpecifierKind Kind |
| 3548 | = NNS.getNestedNameSpecifier()->getKind(); |
| 3549 | Record.push_back(Kind); |
| 3550 | switch (Kind) { |
| 3551 | case NestedNameSpecifier::Identifier: |
| 3552 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 3553 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3554 | break; |
| 3555 | |
| 3556 | case NestedNameSpecifier::Namespace: |
| 3557 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 3558 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3559 | break; |
| 3560 | |
| 3561 | case NestedNameSpecifier::NamespaceAlias: |
| 3562 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 3563 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3564 | break; |
| 3565 | |
| 3566 | case NestedNameSpecifier::TypeSpec: |
| 3567 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3568 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 3569 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 3570 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 3571 | break; |
| 3572 | |
| 3573 | case NestedNameSpecifier::Global: |
| 3574 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 3575 | break; |
| 3576 | } |
| 3577 | } |
| 3578 | } |
| 3579 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3580 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3581 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3582 | Record.push_back(Kind); |
| 3583 | switch (Kind) { |
| 3584 | case TemplateName::Template: |
| 3585 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 3586 | break; |
| 3587 | |
| 3588 | case TemplateName::OverloadedTemplate: { |
| 3589 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 3590 | Record.push_back(OvT->size()); |
| 3591 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 3592 | I != E; ++I) |
| 3593 | AddDeclRef(*I, Record); |
| 3594 | break; |
| 3595 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3596 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3597 | case TemplateName::QualifiedTemplate: { |
| 3598 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 3599 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 3600 | Record.push_back(QualT->hasTemplateKeyword()); |
| 3601 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 3602 | break; |
| 3603 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3604 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3605 | case TemplateName::DependentTemplate: { |
| 3606 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 3607 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 3608 | Record.push_back(DepT->isIdentifier()); |
| 3609 | if (DepT->isIdentifier()) |
| 3610 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 3611 | else |
| 3612 | Record.push_back(DepT->getOperator()); |
| 3613 | break; |
| 3614 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 3615 | |
| 3616 | case TemplateName::SubstTemplateTemplateParm: { |
| 3617 | SubstTemplateTemplateParmStorage *subst |
| 3618 | = Name.getAsSubstTemplateTemplateParm(); |
| 3619 | AddDeclRef(subst->getParameter(), Record); |
| 3620 | AddTemplateName(subst->getReplacement(), Record); |
| 3621 | break; |
| 3622 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3623 | |
| 3624 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 3625 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 3626 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 3627 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 3628 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 3629 | break; |
| 3630 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3631 | } |
| 3632 | } |
| 3633 | |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3634 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3635 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3636 | Record.push_back(Arg.getKind()); |
| 3637 | switch (Arg.getKind()) { |
| 3638 | case TemplateArgument::Null: |
| 3639 | break; |
| 3640 | case TemplateArgument::Type: |
| 3641 | AddTypeRef(Arg.getAsType(), Record); |
| 3642 | break; |
| 3643 | case TemplateArgument::Declaration: |
| 3644 | AddDeclRef(Arg.getAsDecl(), Record); |
| 3645 | break; |
| 3646 | case TemplateArgument::Integral: |
| 3647 | AddAPSInt(*Arg.getAsIntegral(), Record); |
| 3648 | AddTypeRef(Arg.getIntegralType(), Record); |
| 3649 | break; |
| 3650 | case TemplateArgument::Template: |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3651 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 3652 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3653 | case TemplateArgument::TemplateExpansion: |
| 3654 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3655 | if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
| 3656 | Record.push_back(*NumExpansions + 1); |
| 3657 | else |
| 3658 | Record.push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3659 | break; |
| 3660 | case TemplateArgument::Expression: |
| 3661 | AddStmt(Arg.getAsExpr()); |
| 3662 | break; |
| 3663 | case TemplateArgument::Pack: |
| 3664 | Record.push_back(Arg.pack_size()); |
| 3665 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 3666 | I != E; ++I) |
| 3667 | AddTemplateArgument(*I, Record); |
| 3668 | break; |
| 3669 | } |
| 3670 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3671 | |
| 3672 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3673 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3674 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3675 | assert(TemplateParams && "No TemplateParams!"); |
| 3676 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 3677 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 3678 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 3679 | Record.push_back(TemplateParams->size()); |
| 3680 | for (TemplateParameterList::const_iterator |
| 3681 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 3682 | P != PEnd; ++P) |
| 3683 | AddDeclRef(*P, Record); |
| 3684 | } |
| 3685 | |
| 3686 | /// \brief Emit a template argument list. |
| 3687 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3688 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3689 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3690 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 3691 | Record.push_back(TemplateArgs->size()); |
| 3692 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3693 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 3694 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 3695 | |
| 3696 | |
| 3697 | void |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3698 | ASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 3699 | Record.push_back(Set.size()); |
| 3700 | for (UnresolvedSetImpl::const_iterator |
| 3701 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 3702 | AddDeclRef(I.getDecl(), Record); |
| 3703 | Record.push_back(I.getAccess()); |
| 3704 | } |
| 3705 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3706 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3707 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3708 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3709 | Record.push_back(Base.isVirtual()); |
| 3710 | Record.push_back(Base.isBaseOfClass()); |
| 3711 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 3712 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 3713 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3714 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 3715 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 3716 | : SourceLocation(), |
| 3717 | Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3718 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3719 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3720 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 3721 | RecordData Record; |
| 3722 | for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { |
| 3723 | Record.clear(); |
| 3724 | |
| 3725 | // Record the offset of this base-specifier set. |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3726 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3727 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 3728 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 3729 | else { |
| 3730 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 3731 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 3732 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 3733 | } |
| 3734 | |
| 3735 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 3736 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 3737 | Record.push_back(BEnd - B); |
| 3738 | for (; B != BEnd; ++B) |
| 3739 | AddCXXBaseSpecifier(*B, Record); |
| 3740 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | d585304 | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 3741 | |
| 3742 | // Flush any expressions that were written as part of the base specifiers. |
| 3743 | FlushStmts(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | CXXBaseSpecifiersToWrite.clear(); |
| 3747 | } |
| 3748 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 3749 | void ASTWriter::AddCXXCtorInitializers( |
| 3750 | const CXXCtorInitializer * const *CtorInitializers, |
| 3751 | unsigned NumCtorInitializers, |
| 3752 | RecordDataImpl &Record) { |
| 3753 | Record.push_back(NumCtorInitializers); |
| 3754 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 3755 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3756 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3757 | if (Init->isBaseInitializer()) { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3758 | Record.push_back(CTOR_INITIALIZER_BASE); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3759 | AddTypeSourceInfo(Init->getBaseClassInfo(), Record); |
| 3760 | Record.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3761 | } else if (Init->isDelegatingInitializer()) { |
| 3762 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
| 3763 | AddDeclRef(Init->getTargetConstructor(), Record); |
| 3764 | } else if (Init->isMemberInitializer()){ |
| 3765 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 3766 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3767 | } else { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3768 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 3769 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3770 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 3771 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3772 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 3773 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3774 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 3775 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 3776 | Record.push_back(Init->isWritten()); |
| 3777 | if (Init->isWritten()) { |
| 3778 | Record.push_back(Init->getSourceOrder()); |
| 3779 | } else { |
| 3780 | Record.push_back(Init->getNumArrayIndices()); |
| 3781 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 3782 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 3783 | } |
| 3784 | } |
| 3785 | } |
| 3786 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3787 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
| 3788 | assert(D->DefinitionData); |
| 3789 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
| 3790 | Record.push_back(Data.UserDeclaredConstructor); |
| 3791 | Record.push_back(Data.UserDeclaredCopyConstructor); |
| 3792 | Record.push_back(Data.UserDeclaredCopyAssignment); |
| 3793 | Record.push_back(Data.UserDeclaredDestructor); |
| 3794 | Record.push_back(Data.Aggregate); |
| 3795 | Record.push_back(Data.PlainOldData); |
| 3796 | Record.push_back(Data.Empty); |
| 3797 | Record.push_back(Data.Polymorphic); |
| 3798 | Record.push_back(Data.Abstract); |
Chandler Carruth | 583edf8 | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 3799 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | b196374 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 3800 | Record.push_back(Data.HasNoNonEmptyBases); |
| 3801 | Record.push_back(Data.HasPrivateFields); |
| 3802 | Record.push_back(Data.HasProtectedFields); |
| 3803 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 61226d3 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 3804 | Record.push_back(Data.HasMutableFields); |
Alexis Hunt | f479f1b | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 3805 | Record.push_back(Data.HasTrivialDefaultConstructor); |
Richard Smith | 111af8d | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 3806 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3807 | Record.push_back(Data.HasTrivialCopyConstructor); |
Chandler Carruth | ad7d404 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 3808 | Record.push_back(Data.HasTrivialMoveConstructor); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3809 | Record.push_back(Data.HasTrivialCopyAssignment); |
Chandler Carruth | ad7d404 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 3810 | Record.push_back(Data.HasTrivialMoveAssignment); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3811 | Record.push_back(Data.HasTrivialDestructor); |
Chandler Carruth | e71d062 | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 3812 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3813 | Record.push_back(Data.ComputedVisibleConversions); |
Alexis Hunt | ea6f032 | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 3814 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3815 | Record.push_back(Data.DeclaredDefaultConstructor); |
| 3816 | Record.push_back(Data.DeclaredCopyConstructor); |
| 3817 | Record.push_back(Data.DeclaredCopyAssignment); |
| 3818 | Record.push_back(Data.DeclaredDestructor); |
| 3819 | |
| 3820 | Record.push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3821 | if (Data.NumBases > 0) |
| 3822 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 3823 | Record); |
| 3824 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3825 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 3826 | Record.push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3827 | if (Data.NumVBases > 0) |
| 3828 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 3829 | Record); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3830 | |
| 3831 | AddUnresolvedSet(Data.Conversions, Record); |
| 3832 | AddUnresolvedSet(Data.VisibleConversions, Record); |
| 3833 | // Data.Definition is the owning decl, no need to write it. |
| 3834 | AddDeclRef(Data.FirstFriend, Record); |
| 3835 | } |
| 3836 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3837 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3838 | assert(Reader && "Cannot remove chain"); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3839 | assert(!Chain && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3840 | assert(FirstDeclID == NextDeclID && |
| 3841 | FirstTypeID == NextTypeID && |
| 3842 | FirstIdentID == NextIdentID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3843 | FirstSelectorID == NextSelectorID && |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3844 | FirstMacroID == NextMacroID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3845 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3846 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3847 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3848 | |
| 3849 | FirstDeclID += Chain->getTotalNumDecls(); |
| 3850 | FirstTypeID += Chain->getTotalNumTypes(); |
| 3851 | FirstIdentID += Chain->getTotalNumIdentifiers(); |
| 3852 | FirstSelectorID += Chain->getTotalNumSelectors(); |
| 3853 | FirstMacroID += Chain->getTotalNumMacroDefinitions(); |
| 3854 | NextDeclID = FirstDeclID; |
| 3855 | NextTypeID = FirstTypeID; |
| 3856 | NextIdentID = FirstIdentID; |
| 3857 | NextSelectorID = FirstSelectorID; |
| 3858 | NextMacroID = FirstMacroID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3861 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3862 | IdentifierIDs[II] = ID; |
Douglas Gregor | 68051a7 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 3863 | if (II->hasMacroDefinition()) |
| 3864 | DeserializedMacroNames.push_back(II); |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3867 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3868 | // Always take the highest-numbered type index. This copes with an interesting |
| 3869 | // case for chained AST writing where we schedule writing the type and then, |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3870 | // later, deserialize the type from another AST. In this case, we want to |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3871 | // keep the higher-numbered entry so that we can properly write it out to |
| 3872 | // the AST file. |
| 3873 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 3874 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 3875 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3876 | } |
| 3877 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3878 | void ASTWriter::DeclRead(DeclID ID, const Decl *D) { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3879 | DeclIDs[D] = ID; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3880 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3881 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3882 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3883 | SelectorIDs[S] = ID; |
| 3884 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3885 | |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3886 | void ASTWriter::MacroDefinitionRead(serialization::MacroID ID, |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3887 | MacroDefinition *MD) { |
| 3888 | MacroDefinitions[MD] = ID; |
| 3889 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 3890 | |
| 3891 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
| 3892 | assert(D->isDefinition()); |
| 3893 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 3894 | // We are interested when a PCH decl is modified. |
| 3895 | if (RD->getPCHLevel() > 0) { |
| 3896 | // A forward reference was mutated into a definition. Rewrite it. |
| 3897 | // FIXME: This happens during template instantiation, should we |
| 3898 | // have created a new definition decl instead ? |
Argyrios Kyrtzidis | 4729972 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 3899 | RewriteDecl(RD); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | for (CXXRecordDecl::redecl_iterator |
| 3903 | I = RD->redecls_begin(), E = RD->redecls_end(); I != E; ++I) { |
| 3904 | CXXRecordDecl *Redecl = cast<CXXRecordDecl>(*I); |
| 3905 | if (Redecl == RD) |
| 3906 | continue; |
| 3907 | |
| 3908 | // We are interested when a PCH decl is modified. |
| 3909 | if (Redecl->getPCHLevel() > 0) { |
| 3910 | UpdateRecord &Record = DeclUpdates[Redecl]; |
| 3911 | Record.push_back(UPD_CXX_SET_DEFINITIONDATA); |
| 3912 | assert(Redecl->DefinitionData); |
| 3913 | assert(Redecl->DefinitionData->Definition == D); |
| 3914 | AddDeclRef(D, Record); // the DefinitionDecl |
| 3915 | } |
| 3916 | } |
| 3917 | } |
| 3918 | } |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 3919 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
| 3920 | // TU and namespaces are handled elsewhere. |
| 3921 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 3922 | return; |
| 3923 | |
| 3924 | if (!(D->getPCHLevel() == 0 && cast<Decl>(DC)->getPCHLevel() > 0)) |
| 3925 | return; // Not a source decl added to a DeclContext from PCH. |
| 3926 | |
| 3927 | AddUpdatedDeclContext(DC); |
| 3928 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 3929 | |
| 3930 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
| 3931 | assert(D->isImplicit()); |
| 3932 | if (!(D->getPCHLevel() == 0 && RD->getPCHLevel() > 0)) |
| 3933 | return; // Not a source member added to a class from PCH. |
| 3934 | if (!isa<CXXMethodDecl>(D)) |
| 3935 | return; // We are interested in lazily declared implicit methods. |
| 3936 | |
| 3937 | // A decl coming from PCH was modified. |
| 3938 | assert(RD->isDefinition()); |
| 3939 | UpdateRecord &Record = DeclUpdates[RD]; |
| 3940 | Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); |
| 3941 | AddDeclRef(D, Record); |
| 3942 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 3943 | |
| 3944 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 3945 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | ef80a01 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 3946 | // The specializations set is kept in the canonical template. |
| 3947 | TD = TD->getCanonicalDecl(); |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 3948 | if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0)) |
| 3949 | return; // Not a source specialization added to a template from PCH. |
| 3950 | |
| 3951 | UpdateRecord &Record = DeclUpdates[TD]; |
| 3952 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
| 3953 | AddDeclRef(D, Record); |
| 3954 | } |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3955 | |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 3956 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 3957 | const FunctionDecl *D) { |
| 3958 | // The specializations set is kept in the canonical template. |
| 3959 | TD = TD->getCanonicalDecl(); |
| 3960 | if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0)) |
| 3961 | return; // Not a source specialization added to a template from PCH. |
| 3962 | |
| 3963 | UpdateRecord &Record = DeclUpdates[TD]; |
| 3964 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
| 3965 | AddDeclRef(D, Record); |
| 3966 | } |
| 3967 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 3968 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
| 3969 | if (D->getPCHLevel() == 0) |
| 3970 | return; // Declaration not imported from PCH. |
| 3971 | |
| 3972 | // Implicit decl from a PCH was defined. |
| 3973 | // FIXME: Should implicit definition be a separate FunctionDecl? |
| 3974 | RewriteDecl(D); |
| 3975 | } |
| 3976 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 3977 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
| 3978 | if (D->getPCHLevel() == 0) |
| 3979 | return; |
| 3980 | |
| 3981 | // Since the actual instantiation is delayed, this really means that we need |
| 3982 | // to update the instantiation location. |
| 3983 | UpdateRecord &Record = DeclUpdates[D]; |
| 3984 | Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); |
| 3985 | AddSourceLocation( |
| 3986 | D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); |
| 3987 | } |
| 3988 | |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3989 | ASTSerializationListener::~ASTSerializationListener() { } |