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" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 16 | #include "clang/Sema/Sema.h" |
| 17 | #include "clang/Sema/IdentifierResolver.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
| 19 | #include "clang/AST/Decl.h" |
| 20 | #include "clang/AST/DeclContextInternals.h" |
John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclTemplate.h" |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclFriend.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 23 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 24 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 25 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocVisitor.h" |
Sebastian Redl | f5b1346 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 27 | #include "clang/Serialization/ASTReader.h" |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 28 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 29 | #include "clang/Lex/PreprocessingRecord.h" |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 3fa455a | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 31 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 33 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 34 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 37 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 38 | #include "clang/Basic/TargetOptions.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) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 95 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 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()); |
Richard Smith | 5e58029 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 189 | Record.push_back(T->hasTrailingReturn()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 190 | Record.push_back(T->getTypeQuals()); |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 191 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 192 | Record.push_back(T->getExceptionSpecType()); |
| 193 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 194 | Record.push_back(T->getNumExceptions()); |
| 195 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 196 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 197 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 198 | Writer.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 199 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
| 200 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
| 201 | Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 202 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
| 203 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 204 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 205 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 208 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 209 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 210 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 211 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 212 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 213 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 214 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 215 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 216 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 217 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 220 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 221 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 222 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 225 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 226 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 227 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 230 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 231 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 232 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 233 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 236 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 237 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 238 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 239 | Record.push_back(T->getUTTKind()); |
| 240 | Code = TYPE_UNARY_TRANSFORM; |
| 241 | } |
| 242 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 243 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 244 | Writer.AddTypeRef(T->getDeducedType(), Record); |
| 245 | Code = TYPE_AUTO; |
| 246 | } |
| 247 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 248 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 249 | Record.push_back(T->isDependentType()); |
Douglas Gregor | f3bccd7 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 250 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 252 | "Cannot serialize in the middle of a type definition"); |
| 253 | } |
| 254 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 255 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 256 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 257 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 260 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 261 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 262 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 263 | } |
| 264 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 265 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 266 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 267 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 268 | Record.push_back(T->getAttrKind()); |
| 269 | Code = TYPE_ATTRIBUTED; |
| 270 | } |
| 271 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 273 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 274 | const SubstTemplateTypeParmType *T) { |
| 275 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 276 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 277 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 281 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 282 | const SubstTemplateTypeParmPackType *T) { |
| 283 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 284 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 285 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 286 | } |
| 287 | |
| 288 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 289 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 290 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 291 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 292 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 293 | Record.push_back(T->getNumArgs()); |
| 294 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 295 | ArgI != ArgE; ++ArgI) |
| 296 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 297 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 298 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 299 | : T->getCanonicalTypeInternal(), |
| 300 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 301 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 305 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 306 | VisitArrayType(T); |
| 307 | Writer.AddStmt(T->getSizeExpr()); |
| 308 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 309 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 313 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 314 | const DependentSizedExtVectorType *T) { |
| 315 | // FIXME: Serialize this type (C++ only) |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 316 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 320 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 321 | Record.push_back(T->getDepth()); |
| 322 | Record.push_back(T->getIndex()); |
| 323 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 324 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 325 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 329 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 330 | Record.push_back(T->getKeyword()); |
| 331 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 332 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 333 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 334 | : T->getCanonicalTypeInternal(), |
| 335 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 336 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 340 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 341 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 342 | Record.push_back(T->getKeyword()); |
| 343 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 344 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 345 | Record.push_back(T->getNumArgs()); |
| 346 | for (DependentTemplateSpecializationType::iterator |
| 347 | I = T->begin(), E = T->end(); I != E; ++I) |
| 348 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 349 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 352 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 353 | Writer.AddTypeRef(T->getPattern(), Record); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 354 | if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) |
| 355 | Record.push_back(*NumExpansions + 1); |
| 356 | else |
| 357 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 358 | Code = TYPE_PACK_EXPANSION; |
| 359 | } |
| 360 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 361 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 362 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 363 | Code = TYPE_PAREN; |
| 364 | } |
| 365 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 366 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 367 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 368 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 369 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 370 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 373 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Douglas Gregor | 9f21889 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 374 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
John McCall | 2408e32 | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 375 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 376 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 379 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | f3bccd7 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 380 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 381 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 384 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 385 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 386 | Record.push_back(T->getNumProtocols()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 387 | for (ObjCObjectType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 4fc95aa | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 388 | E = T->qual_end(); I != E; ++I) |
| 389 | Writer.AddDeclRef(*I, Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 390 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 393 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 394 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 396 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 399 | void |
| 400 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
| 401 | Writer.AddTypeRef(T->getValueType(), Record); |
| 402 | Code = TYPE_ATOMIC; |
| 403 | } |
| 404 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 405 | namespace { |
| 406 | |
| 407 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 408 | ASTWriter &Writer; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 409 | ASTWriter::RecordDataImpl &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 410 | |
| 411 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 412 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 413 | : Writer(Writer), Record(Record) { } |
| 414 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 415 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 416 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 417 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 418 | #include "clang/AST/TypeLocNodes.def" |
| 419 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 420 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 421 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 422 | }; |
| 423 | |
| 424 | } |
| 425 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 426 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 427 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 428 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 429 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 430 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 431 | if (TL.needsExtraLocalData()) { |
| 432 | Record.push_back(TL.getWrittenTypeSpec()); |
| 433 | Record.push_back(TL.getWrittenSignSpec()); |
| 434 | Record.push_back(TL.getWrittenWidthSpec()); |
| 435 | Record.push_back(TL.hasModeAttr()); |
| 436 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 437 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 438 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 439 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 440 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 441 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 442 | Writer.AddSourceLocation(TL.getStarLoc(), 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::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 445 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 446 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 447 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 448 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 449 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 450 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 451 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 452 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 453 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 454 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 455 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 456 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 457 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 458 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 459 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 460 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 461 | if (TL.getSizeExpr()) |
| 462 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 463 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 464 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 465 | VisitArrayTypeLoc(TL); |
| 466 | } |
| 467 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 468 | VisitArrayTypeLoc(TL); |
| 469 | } |
| 470 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 471 | VisitArrayTypeLoc(TL); |
| 472 | } |
| 473 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 474 | DependentSizedArrayTypeLoc TL) { |
| 475 | VisitArrayTypeLoc(TL); |
| 476 | } |
| 477 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 478 | DependentSizedExtVectorTypeLoc TL) { |
| 479 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 480 | } |
| 481 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 482 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 483 | } |
| 484 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 485 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 486 | } |
| 487 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 488 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 489 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 490 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 491 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 492 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 493 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 494 | } |
| 495 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 496 | VisitFunctionTypeLoc(TL); |
| 497 | } |
| 498 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 499 | VisitFunctionTypeLoc(TL); |
| 500 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 501 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 502 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 503 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 504 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 505 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 506 | } |
| 507 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 508 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 509 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 510 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 511 | } |
| 512 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 513 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 514 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 515 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 516 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 517 | } |
| 518 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 519 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 520 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 521 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 522 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 523 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 524 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 525 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 526 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 527 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 528 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 529 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 530 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 531 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 532 | } |
| 533 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 534 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 535 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 536 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 537 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 538 | if (TL.hasAttrOperand()) { |
| 539 | SourceRange range = TL.getAttrOperandParensRange(); |
| 540 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 541 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 542 | } |
| 543 | if (TL.hasAttrExprOperand()) { |
| 544 | Expr *operand = TL.getAttrExprOperand(); |
| 545 | Record.push_back(operand ? 1 : 0); |
| 546 | if (operand) Writer.AddStmt(operand); |
| 547 | } else if (TL.hasAttrEnumOperand()) { |
| 548 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 549 | } |
| 550 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 551 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 552 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 553 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 554 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 555 | SubstTemplateTypeParmTypeLoc TL) { |
| 556 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 557 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 558 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 559 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 560 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 561 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 562 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 563 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 564 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 565 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 566 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 567 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 568 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 569 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 570 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 571 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 572 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 573 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 574 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 575 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 576 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 577 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 578 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 579 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 580 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 581 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 582 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 583 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 584 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 585 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 586 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 587 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 588 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 589 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 590 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 591 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 592 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 593 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 594 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 595 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 596 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 597 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 598 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 599 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 600 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 601 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 602 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 603 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 604 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 605 | } |
| 606 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 607 | Record.push_back(TL.hasBaseTypeAsWritten()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 608 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 609 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 610 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 611 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 612 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 613 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 614 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 615 | } |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 616 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 617 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 618 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 619 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 620 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 621 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 622 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 623 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 624 | //===----------------------------------------------------------------------===// |
| 625 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 626 | static void EmitBlockID(unsigned ID, const char *Name, |
| 627 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 628 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 629 | Record.clear(); |
| 630 | Record.push_back(ID); |
| 631 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 632 | |
| 633 | // Emit the block name if present. |
| 634 | if (Name == 0 || Name[0] == 0) return; |
| 635 | Record.clear(); |
| 636 | while (*Name) |
| 637 | Record.push_back(*Name++); |
| 638 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 639 | } |
| 640 | |
| 641 | static void EmitRecordID(unsigned ID, const char *Name, |
| 642 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 643 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 644 | Record.clear(); |
| 645 | Record.push_back(ID); |
| 646 | while (*Name) |
| 647 | Record.push_back(*Name++); |
| 648 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 652 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 653 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 654 | RECORD(STMT_STOP); |
| 655 | RECORD(STMT_NULL_PTR); |
| 656 | RECORD(STMT_NULL); |
| 657 | RECORD(STMT_COMPOUND); |
| 658 | RECORD(STMT_CASE); |
| 659 | RECORD(STMT_DEFAULT); |
| 660 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 661 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 662 | RECORD(STMT_IF); |
| 663 | RECORD(STMT_SWITCH); |
| 664 | RECORD(STMT_WHILE); |
| 665 | RECORD(STMT_DO); |
| 666 | RECORD(STMT_FOR); |
| 667 | RECORD(STMT_GOTO); |
| 668 | RECORD(STMT_INDIRECT_GOTO); |
| 669 | RECORD(STMT_CONTINUE); |
| 670 | RECORD(STMT_BREAK); |
| 671 | RECORD(STMT_RETURN); |
| 672 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 673 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 674 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 675 | RECORD(EXPR_PREDEFINED); |
| 676 | RECORD(EXPR_DECL_REF); |
| 677 | RECORD(EXPR_INTEGER_LITERAL); |
| 678 | RECORD(EXPR_FLOATING_LITERAL); |
| 679 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 680 | RECORD(EXPR_STRING_LITERAL); |
| 681 | RECORD(EXPR_CHARACTER_LITERAL); |
| 682 | RECORD(EXPR_PAREN); |
| 683 | RECORD(EXPR_UNARY_OPERATOR); |
| 684 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 685 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 686 | RECORD(EXPR_CALL); |
| 687 | RECORD(EXPR_MEMBER); |
| 688 | RECORD(EXPR_BINARY_OPERATOR); |
| 689 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 690 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 691 | RECORD(EXPR_IMPLICIT_CAST); |
| 692 | RECORD(EXPR_CSTYLE_CAST); |
| 693 | RECORD(EXPR_COMPOUND_LITERAL); |
| 694 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 695 | RECORD(EXPR_INIT_LIST); |
| 696 | RECORD(EXPR_DESIGNATED_INIT); |
| 697 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 698 | RECORD(EXPR_VA_ARG); |
| 699 | RECORD(EXPR_ADDR_LABEL); |
| 700 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 701 | RECORD(EXPR_CHOOSE); |
| 702 | RECORD(EXPR_GNU_NULL); |
| 703 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 704 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 705 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 706 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 707 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 708 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 709 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 710 | RECORD(EXPR_OBJC_ENCODE); |
| 711 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 712 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 713 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 714 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 715 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 716 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 717 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 718 | RECORD(STMT_OBJC_CATCH); |
| 719 | RECORD(STMT_OBJC_FINALLY); |
| 720 | RECORD(STMT_OBJC_AT_TRY); |
| 721 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 722 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 723 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 724 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 725 | RECORD(EXPR_CXX_CONSTRUCT); |
| 726 | RECORD(EXPR_CXX_STATIC_CAST); |
| 727 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 728 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 729 | RECORD(EXPR_CXX_CONST_CAST); |
| 730 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 731 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 732 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 733 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 734 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 735 | RECORD(EXPR_CXX_TYPEID_TYPE); |
| 736 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 737 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 738 | RECORD(EXPR_CXX_THIS); |
| 739 | RECORD(EXPR_CXX_THROW); |
| 740 | RECORD(EXPR_CXX_DEFAULT_ARG); |
| 741 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 742 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 743 | RECORD(EXPR_CXX_NEW); |
| 744 | RECORD(EXPR_CXX_DELETE); |
| 745 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 746 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 747 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 748 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 749 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 750 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 751 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
| 752 | RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); |
| 753 | RECORD(EXPR_CXX_NOEXCEPT); |
| 754 | RECORD(EXPR_OPAQUE_VALUE); |
| 755 | RECORD(EXPR_BINARY_TYPE_TRAIT); |
| 756 | RECORD(EXPR_PACK_EXPANSION); |
| 757 | RECORD(EXPR_SIZEOF_PACK); |
| 758 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 759 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 760 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 761 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 763 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 764 | RecordData Record; |
| 765 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 767 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 768 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 770 | // Control Block. |
| 771 | BLOCK(CONTROL_BLOCK); |
| 772 | RECORD(METADATA); |
| 773 | RECORD(IMPORTS); |
| 774 | RECORD(LANGUAGE_OPTIONS); |
| 775 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 776 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 777 | RECORD(ORIGINAL_PCH_DIR); |
| 778 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame^] | 779 | BLOCK(INPUT_FILES_BLOCK); |
| 780 | RECORD(INPUT_FILE); |
| 781 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 782 | // AST Top-Level Block. |
| 783 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 784 | RECORD(TYPE_OFFSET); |
| 785 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 786 | RECORD(IDENTIFIER_OFFSET); |
| 787 | RECORD(IDENTIFIER_TABLE); |
| 788 | RECORD(EXTERNAL_DEFINITIONS); |
| 789 | RECORD(SPECIAL_TYPES); |
| 790 | RECORD(STATISTICS); |
| 791 | RECORD(TENTATIVE_DEFINITIONS); |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 792 | RECORD(UNUSED_FILESCOPED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 793 | RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); |
| 794 | RECORD(SELECTOR_OFFSETS); |
| 795 | RECORD(METHOD_POOL); |
| 796 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 797 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 798 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 799 | RECORD(STAT_CACHE); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 800 | RECORD(EXT_VECTOR_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 801 | RECORD(PPD_ENTITIES_OFFSETS); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 802 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 803 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 804 | RECORD(LOCAL_REDECLARATIONS_MAP); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 805 | RECORD(SEMA_DECL_REFS); |
| 806 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 807 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 808 | RECORD(DECL_REPLACEMENTS); |
| 809 | RECORD(UPDATE_VISIBLE); |
| 810 | RECORD(DECL_UPDATE_OFFSETS); |
| 811 | RECORD(DECL_UPDATES); |
| 812 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 813 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 814 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 815 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 816 | RECORD(FP_PRAGMA_OPTIONS); |
| 817 | RECORD(OPENCL_EXTENSIONS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 818 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 819 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 820 | RECORD(MODULE_OFFSET_MAP); |
| 821 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 822 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 823 | RECORD(FILE_SORTED_DECLS); |
| 824 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 825 | RECORD(MERGED_DECLARATIONS); |
| 826 | RECORD(LOCAL_REDECLARATIONS); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 827 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 828 | RECORD(MACRO_OFFSET); |
| 829 | RECORD(MACRO_UPDATES); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 830 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 831 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 832 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 833 | RECORD(SM_SLOC_FILE_ENTRY); |
| 834 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 835 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 836 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 838 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 839 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 840 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 841 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 842 | RECORD(PP_TOKEN); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 843 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 844 | // Decls and Types block. |
| 845 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 846 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 847 | RECORD(TYPE_COMPLEX); |
| 848 | RECORD(TYPE_POINTER); |
| 849 | RECORD(TYPE_BLOCK_POINTER); |
| 850 | RECORD(TYPE_LVALUE_REFERENCE); |
| 851 | RECORD(TYPE_RVALUE_REFERENCE); |
| 852 | RECORD(TYPE_MEMBER_POINTER); |
| 853 | RECORD(TYPE_CONSTANT_ARRAY); |
| 854 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 855 | RECORD(TYPE_VARIABLE_ARRAY); |
| 856 | RECORD(TYPE_VECTOR); |
| 857 | RECORD(TYPE_EXT_VECTOR); |
| 858 | RECORD(TYPE_FUNCTION_PROTO); |
| 859 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 860 | RECORD(TYPE_TYPEDEF); |
| 861 | RECORD(TYPE_TYPEOF_EXPR); |
| 862 | RECORD(TYPE_TYPEOF); |
| 863 | RECORD(TYPE_RECORD); |
| 864 | RECORD(TYPE_ENUM); |
| 865 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | 94f619a | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 866 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 867 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 868 | RECORD(TYPE_DECLTYPE); |
| 869 | RECORD(TYPE_ELABORATED); |
| 870 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 871 | RECORD(TYPE_UNRESOLVED_USING); |
| 872 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 873 | RECORD(TYPE_OBJC_OBJECT); |
| 874 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 875 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 876 | RECORD(TYPE_DEPENDENT_NAME); |
| 877 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 878 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 879 | RECORD(TYPE_PAREN); |
| 880 | RECORD(TYPE_PACK_EXPANSION); |
| 881 | RECORD(TYPE_ATTRIBUTED); |
| 882 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 883 | RECORD(TYPE_ATOMIC); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 884 | RECORD(DECL_TYPEDEF); |
| 885 | RECORD(DECL_ENUM); |
| 886 | RECORD(DECL_RECORD); |
| 887 | RECORD(DECL_ENUM_CONSTANT); |
| 888 | RECORD(DECL_FUNCTION); |
| 889 | RECORD(DECL_OBJC_METHOD); |
| 890 | RECORD(DECL_OBJC_INTERFACE); |
| 891 | RECORD(DECL_OBJC_PROTOCOL); |
| 892 | RECORD(DECL_OBJC_IVAR); |
| 893 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 894 | RECORD(DECL_OBJC_CATEGORY); |
| 895 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 896 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 897 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 898 | RECORD(DECL_OBJC_PROPERTY); |
| 899 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 900 | RECORD(DECL_FIELD); |
| 901 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 902 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 903 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 904 | RECORD(DECL_FILE_SCOPE_ASM); |
| 905 | RECORD(DECL_BLOCK); |
| 906 | RECORD(DECL_CONTEXT_LEXICAL); |
| 907 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 908 | RECORD(DECL_NAMESPACE); |
| 909 | RECORD(DECL_NAMESPACE_ALIAS); |
| 910 | RECORD(DECL_USING); |
| 911 | RECORD(DECL_USING_SHADOW); |
| 912 | RECORD(DECL_USING_DIRECTIVE); |
| 913 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 914 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 915 | RECORD(DECL_LINKAGE_SPEC); |
| 916 | RECORD(DECL_CXX_RECORD); |
| 917 | RECORD(DECL_CXX_METHOD); |
| 918 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 919 | RECORD(DECL_CXX_DESTRUCTOR); |
| 920 | RECORD(DECL_CXX_CONVERSION); |
| 921 | RECORD(DECL_ACCESS_SPEC); |
| 922 | RECORD(DECL_FRIEND); |
| 923 | RECORD(DECL_FRIEND_TEMPLATE); |
| 924 | RECORD(DECL_CLASS_TEMPLATE); |
| 925 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 926 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
| 927 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 928 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 929 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 930 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 931 | RECORD(DECL_STATIC_ASSERT); |
| 932 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 933 | RECORD(DECL_INDIRECTFIELD); |
| 934 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 935 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 936 | // Statements and Exprs can occur in the Decls and Types block. |
| 937 | AddStmtsExprs(Stream, Record); |
| 938 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 939 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 940 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 941 | RECORD(PPD_MACRO_DEFINITION); |
| 942 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 943 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 944 | #undef RECORD |
| 945 | #undef BLOCK |
| 946 | Stream.ExitBlock(); |
| 947 | } |
| 948 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 949 | /// \brief Adjusts the given filename to only write out the portion of the |
| 950 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 952 | /// \param Filename the file name to adjust. |
| 953 | /// |
| 954 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 955 | /// the returned filename will be adjusted by this system root. |
| 956 | /// |
| 957 | /// \returns either the original filename (if it needs no adjustment) or the |
| 958 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 959 | static const char * |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 960 | adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 961 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 962 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 963 | if (isysroot.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 964 | return Filename; |
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 | // Verify that the filename and the system root have the same prefix. |
| 967 | unsigned Pos = 0; |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 968 | for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 969 | if (Filename[Pos] != isysroot[Pos]) |
| 970 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 972 | // We hit the end of the filename before we hit the end of the system root. |
| 973 | if (!Filename[Pos]) |
| 974 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 976 | // If the file name has a '/' at the current position, skip over the '/'. |
| 977 | // We distinguish sysroot-based includes from absolute includes by the |
| 978 | // absence of '/' at the beginning of sysroot-based includes. |
| 979 | if (Filename[Pos] == '/') |
| 980 | ++Pos; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 982 | return Filename + Pos; |
| 983 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 984 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 985 | /// \brief Write the control block. |
| 986 | void ASTWriter::WriteControlBlock(ASTContext &Context, StringRef isysroot, |
| 987 | const std::string &OutputFile) { |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 988 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 989 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
| 990 | RecordData Record; |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 992 | // Metadata |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 993 | BitCodeAbbrev *MetadataAbbrev = new BitCodeAbbrev(); |
| 994 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 995 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 996 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 997 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 998 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 999 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
| 1000 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1001 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1002 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
| 1003 | Record.push_back(METADATA); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1004 | Record.push_back(VERSION_MAJOR); |
| 1005 | Record.push_back(VERSION_MINOR); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1006 | Record.push_back(CLANG_VERSION_MAJOR); |
| 1007 | Record.push_back(CLANG_VERSION_MINOR); |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1008 | Record.push_back(!isysroot.empty()); |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 1009 | Record.push_back(ASTHasCompilerErrors); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1010 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1011 | getClangFullRepositoryVersion()); |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1012 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1013 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1014 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1015 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
| 1016 | llvm::SmallVector<char, 128> ModulePaths; |
| 1017 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1018 | |
| 1019 | for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end(); |
| 1020 | M != MEnd; ++M) { |
| 1021 | // Skip modules that weren't directly imported. |
| 1022 | if (!(*M)->isDirectlyImported()) |
| 1023 | continue; |
| 1024 | |
| 1025 | Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding |
| 1026 | // FIXME: Write import location, once it matters. |
| 1027 | // FIXME: This writes the absolute path for AST files we depend on. |
| 1028 | const std::string &FileName = (*M)->FileName; |
| 1029 | Record.push_back(FileName.size()); |
| 1030 | Record.append(FileName.begin(), FileName.end()); |
| 1031 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1032 | Stream.EmitRecord(IMPORTS, Record); |
| 1033 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1034 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1035 | // Language options. |
| 1036 | Record.clear(); |
| 1037 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1038 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1039 | Record.push_back(LangOpts.Name); |
| 1040 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1041 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
| 1042 | #include "clang/Basic/LangOptions.def" |
| 1043 | |
| 1044 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1045 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
| 1046 | |
| 1047 | Record.push_back(LangOpts.CurrentModule.size()); |
| 1048 | Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end()); |
| 1049 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1050 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1051 | // Target options. |
| 1052 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1053 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1054 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1055 | AddString(TargetOpts.Triple, Record); |
| 1056 | AddString(TargetOpts.CPU, Record); |
| 1057 | AddString(TargetOpts.ABI, Record); |
| 1058 | AddString(TargetOpts.CXXABI, Record); |
| 1059 | AddString(TargetOpts.LinkerVersion, Record); |
| 1060 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1061 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1062 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1063 | } |
| 1064 | Record.push_back(TargetOpts.Features.size()); |
| 1065 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1066 | AddString(TargetOpts.Features[I], Record); |
| 1067 | } |
| 1068 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1069 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1070 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1071 | SourceManager &SM = Context.getSourceManager(); |
| 1072 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 1073 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1074 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1075 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1076 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1077 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1078 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1079 | SmallString<128> MainFilePath(MainFile->getName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1081 | llvm::sys::fs::make_absolute(MainFilePath); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1082 | |
Kovarththanan Rajaratnam | d16d38c | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1083 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1085 | isysroot); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1086 | RecordData Record; |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1087 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1088 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1089 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
| 1090 | Record.clear(); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1091 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1092 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1093 | // Original PCH directory |
| 1094 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1095 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1096 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1097 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1098 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1099 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1100 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1101 | |
| 1102 | llvm::sys::fs::make_absolute(OutputPath); |
| 1103 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1104 | |
| 1105 | RecordData Record; |
| 1106 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1107 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1108 | } |
| 1109 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1110 | WriteInputFiles(Context.SourceMgr, isysroot); |
| 1111 | Stream.ExitBlock(); |
| 1112 | } |
| 1113 | |
| 1114 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, StringRef isysroot) { |
| 1115 | using namespace llvm; |
| 1116 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
| 1117 | RecordData Record; |
| 1118 | |
| 1119 | // Create input-file abbreviation. |
| 1120 | BitCodeAbbrev *IFAbbrev = new BitCodeAbbrev(); |
| 1121 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
| 1122 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1123 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
| 1124 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1125 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1126 | |
| 1127 | // Write out all of the input files. |
| 1128 | std::vector<uint32_t> InputFileOffsets; |
| 1129 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1130 | // Get this source location entry. |
| 1131 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
| 1132 | FileID FID = FileID::get(I); |
| 1133 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
| 1134 | |
| 1135 | // We only care about file entries that were not overridden. |
| 1136 | if (!SLoc->isFile()) |
| 1137 | continue; |
| 1138 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1139 | if (!Cache->OrigEntry || Cache->BufferOverridden) |
| 1140 | continue; |
| 1141 | |
| 1142 | Record.clear(); |
| 1143 | Record.push_back(INPUT_FILE); |
| 1144 | |
| 1145 | // Emit size/modification time for this file. |
| 1146 | Record.push_back(Cache->OrigEntry->getSize()); |
| 1147 | Record.push_back(Cache->OrigEntry->getModificationTime()); |
| 1148 | |
| 1149 | // Turn the file name into an absolute path, if it isn't already. |
| 1150 | const char *Filename = Cache->OrigEntry->getName(); |
| 1151 | SmallString<128> FilePath(Filename); |
| 1152 | |
| 1153 | // Ask the file manager to fixup the relative path for us. This will |
| 1154 | // honor the working directory. |
| 1155 | SourceMgr.getFileManager().FixupRelativePath(FilePath); |
| 1156 | |
| 1157 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1158 | // call to FixupRelativePath should always return an absolute path. |
| 1159 | llvm::sys::fs::make_absolute(FilePath); |
| 1160 | Filename = FilePath.c_str(); |
| 1161 | |
| 1162 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1163 | |
| 1164 | Stream.EmitRecordWithBlob(IFAbbrevCode, Record, Filename); |
| 1165 | } |
| 1166 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1167 | Stream.ExitBlock(); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1170 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1171 | // stat cache Serialization |
| 1172 | //===----------------------------------------------------------------------===// |
| 1173 | |
| 1174 | namespace { |
| 1175 | // Trait used for the on-disk hash table of stat cache results. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1176 | class ASTStatCacheTrait { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1177 | public: |
| 1178 | typedef const char * key_type; |
| 1179 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1181 | typedef struct stat data_type; |
| 1182 | typedef const data_type &data_type_ref; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1183 | |
| 1184 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1185 | return llvm::HashString(path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1186 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | |
| 1188 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1189 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1190 | data_type_ref Data) { |
| 1191 | unsigned StrLen = strlen(path); |
| 1192 | clang::io::Emit16(Out, StrLen); |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1193 | unsigned DataLen = 4 + 4 + 2 + 8 + 8; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1194 | clang::io::Emit8(Out, DataLen); |
| 1195 | return std::make_pair(StrLen + 1, DataLen); |
| 1196 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1198 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1199 | Out.write(path, KeyLen); |
| 1200 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1201 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1202 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1203 | data_type_ref Data, unsigned DataLen) { |
| 1204 | using namespace clang::io; |
| 1205 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1206 | |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1207 | Emit32(Out, (uint32_t) Data.st_ino); |
| 1208 | Emit32(Out, (uint32_t) Data.st_dev); |
| 1209 | Emit16(Out, (uint16_t) Data.st_mode); |
| 1210 | Emit64(Out, (uint64_t) Data.st_mtime); |
| 1211 | Emit64(Out, (uint64_t) Data.st_size); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1212 | |
| 1213 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1214 | } |
| 1215 | }; |
| 1216 | } // end anonymous namespace |
| 1217 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1218 | /// \brief Write the stat() system call cache to the AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1219 | void ASTWriter::WriteStatCache(MemorizeStatCalls &StatCalls) { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1220 | // Build the on-disk hash table containing information about every |
| 1221 | // stat() call. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1222 | OnDiskChainedHashTableGenerator<ASTStatCacheTrait> Generator; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1223 | unsigned NumStatEntries = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1225 | StatEnd = StatCalls.end(); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1226 | Stat != StatEnd; ++Stat, ++NumStatEntries) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1227 | StringRef Filename = Stat->first(); |
Chris Lattner | d386df4 | 2011-07-14 18:24:21 +0000 | [diff] [blame] | 1228 | Generator.insert(Filename.data(), Stat->second); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1230 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1231 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1232 | SmallString<4096> StatCacheData; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1233 | uint32_t BucketOffset; |
| 1234 | { |
| 1235 | llvm::raw_svector_ostream Out(StatCacheData); |
| 1236 | // Make sure that no bucket is at offset 0 |
| 1237 | clang::io::Emit32(Out, 0); |
| 1238 | BucketOffset = Generator.Emit(Out); |
| 1239 | } |
| 1240 | |
| 1241 | // Create a blob abbreviation |
| 1242 | using namespace llvm; |
| 1243 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1244 | Abbrev->Add(BitCodeAbbrevOp(STAT_CACHE)); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1245 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1246 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1247 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1248 | unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1249 | |
| 1250 | // Write the stat cache |
| 1251 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1252 | Record.push_back(STAT_CACHE); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1253 | Record.push_back(BucketOffset); |
| 1254 | Record.push_back(NumStatEntries); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1255 | Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1259 | // Source Manager Serialization |
| 1260 | //===----------------------------------------------------------------------===// |
| 1261 | |
| 1262 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1263 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1264 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1265 | using namespace llvm; |
| 1266 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1267 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1268 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1269 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1270 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1271 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1272 | // FileEntry fields. |
| 1273 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1274 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1275 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // BufferOverridden |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1276 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1277 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1278 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1279 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1280 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1284 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1285 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1286 | using namespace llvm; |
| 1287 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1288 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1289 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1290 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1291 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1292 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1293 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1294 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1298 | /// buffer's blob. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1299 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1300 | using namespace llvm; |
| 1301 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1302 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1303 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1304 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1307 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1308 | /// expansion. |
| 1309 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1310 | using namespace llvm; |
| 1311 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1312 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1313 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1314 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1315 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1316 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1317 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1318 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1321 | namespace { |
| 1322 | // Trait used for the on-disk hash table of header search information. |
| 1323 | class HeaderFileInfoTrait { |
| 1324 | ASTWriter &Writer; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1325 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1326 | // Keep track of the framework names we've used during serialization. |
| 1327 | SmallVector<char, 128> FrameworkStringData; |
| 1328 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1329 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1330 | public: |
Benjamin Kramer | d1d76b2 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 1331 | HeaderFileInfoTrait(ASTWriter &Writer) |
| 1332 | : Writer(Writer) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1333 | |
| 1334 | typedef const char *key_type; |
| 1335 | typedef key_type key_type_ref; |
| 1336 | |
| 1337 | typedef HeaderFileInfo data_type; |
| 1338 | typedef const data_type &data_type_ref; |
| 1339 | |
| 1340 | static unsigned ComputeHash(const char *path) { |
| 1341 | // The hash is based only on the filename portion of the key, so that the |
| 1342 | // reader can match based on filenames when symlinking or excess path |
| 1343 | // elements ("foo/../", "../") change the form of the name. However, |
| 1344 | // complete path is still the key. |
| 1345 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1346 | } |
| 1347 | |
| 1348 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1349 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1350 | data_type_ref Data) { |
| 1351 | unsigned StrLen = strlen(path); |
| 1352 | clang::io::Emit16(Out, StrLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1353 | unsigned DataLen = 1 + 2 + 4 + 4; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1354 | clang::io::Emit8(Out, DataLen); |
| 1355 | return std::make_pair(StrLen + 1, DataLen); |
| 1356 | } |
| 1357 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1358 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1359 | Out.write(path, KeyLen); |
| 1360 | } |
| 1361 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1362 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1363 | data_type_ref Data, unsigned DataLen) { |
| 1364 | using namespace clang::io; |
| 1365 | uint64_t Start = Out.tell(); (void)Start; |
| 1366 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1367 | unsigned char Flags = (Data.isImport << 5) |
| 1368 | | (Data.isPragmaOnce << 4) |
| 1369 | | (Data.DirInfo << 2) |
| 1370 | | (Data.Resolved << 1) |
| 1371 | | Data.IndexHeaderMapHeader; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1372 | Emit8(Out, (uint8_t)Flags); |
| 1373 | Emit16(Out, (uint16_t) Data.NumIncludes); |
| 1374 | |
| 1375 | if (!Data.ControllingMacro) |
| 1376 | Emit32(Out, (uint32_t)Data.ControllingMacroID); |
| 1377 | else |
| 1378 | Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1379 | |
| 1380 | unsigned Offset = 0; |
| 1381 | if (!Data.Framework.empty()) { |
| 1382 | // If this header refers into a framework, save the framework name. |
| 1383 | llvm::StringMap<unsigned>::iterator Pos |
| 1384 | = FrameworkNameOffset.find(Data.Framework); |
| 1385 | if (Pos == FrameworkNameOffset.end()) { |
| 1386 | Offset = FrameworkStringData.size() + 1; |
| 1387 | FrameworkStringData.append(Data.Framework.begin(), |
| 1388 | Data.Framework.end()); |
| 1389 | FrameworkStringData.push_back(0); |
| 1390 | |
| 1391 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1392 | } else |
| 1393 | Offset = Pos->second; |
| 1394 | } |
| 1395 | Emit32(Out, Offset); |
| 1396 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1397 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1398 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1399 | |
| 1400 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1401 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1402 | }; |
| 1403 | } // end anonymous namespace |
| 1404 | |
| 1405 | /// \brief Write the header search block for the list of files that |
| 1406 | /// |
| 1407 | /// \param HS The header search structure to save. |
Argyrios Kyrtzidis | f5ab034 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1408 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1409 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1410 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1411 | |
| 1412 | if (FilesByUID.size() > HS.header_file_size()) |
| 1413 | FilesByUID.resize(HS.header_file_size()); |
| 1414 | |
Benjamin Kramer | d1d76b2 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 1415 | HeaderFileInfoTrait GeneratorTrait(*this); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1416 | OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1417 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1418 | unsigned NumHeaderSearchEntries = 0; |
| 1419 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1420 | const FileEntry *File = FilesByUID[UID]; |
| 1421 | if (!File) |
| 1422 | continue; |
| 1423 | |
Argyrios Kyrtzidis | f5ab034 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1424 | // Use HeaderSearch's getFileInfo to make sure we get the HeaderFileInfo |
| 1425 | // from the external source if it was not provided already. |
| 1426 | const HeaderFileInfo &HFI = HS.getFileInfo(File); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1427 | if (HFI.External && Chain) |
| 1428 | continue; |
| 1429 | |
| 1430 | // Turn the file name into an absolute path, if it isn't already. |
| 1431 | const char *Filename = File->getName(); |
| 1432 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1433 | |
| 1434 | // If we performed any translation on the file name at all, we need to |
| 1435 | // save this string, since the generator will refer to it later. |
| 1436 | if (Filename != File->getName()) { |
| 1437 | Filename = strdup(Filename); |
| 1438 | SavedStrings.push_back(Filename); |
| 1439 | } |
| 1440 | |
| 1441 | Generator.insert(Filename, HFI, GeneratorTrait); |
| 1442 | ++NumHeaderSearchEntries; |
| 1443 | } |
| 1444 | |
| 1445 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1446 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1447 | uint32_t BucketOffset; |
| 1448 | { |
| 1449 | llvm::raw_svector_ostream Out(TableData); |
| 1450 | // Make sure that no bucket is at offset 0 |
| 1451 | clang::io::Emit32(Out, 0); |
| 1452 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1453 | } |
| 1454 | |
| 1455 | // Create a blob abbreviation |
| 1456 | using namespace llvm; |
| 1457 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1458 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1459 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1460 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1461 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1462 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1463 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1464 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1465 | // Write the header search table |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1466 | RecordData Record; |
| 1467 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1468 | Record.push_back(BucketOffset); |
| 1469 | Record.push_back(NumHeaderSearchEntries); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1470 | Record.push_back(TableData.size()); |
| 1471 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1472 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); |
| 1473 | |
| 1474 | // Free all of the strings we had to duplicate. |
| 1475 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
| 1476 | free((void*)SavedStrings[I]); |
| 1477 | } |
| 1478 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1479 | /// \brief Writes the block containing the serialized form of the |
| 1480 | /// source manager. |
| 1481 | /// |
| 1482 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1483 | /// blob), indexed based on the file name, so that we only create |
| 1484 | /// entries for files that we actually need. In the common case (no |
| 1485 | /// errors), we probably won't have to create file entries for any of |
| 1486 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1487 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1488 | const Preprocessor &PP, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1489 | StringRef isysroot) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1490 | RecordData Record; |
| 1491 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1492 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1493 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1494 | |
| 1495 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1496 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1497 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1498 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1499 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1500 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1501 | // Write out the source location entry table. We skip the first |
| 1502 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1503 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1504 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1505 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1506 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1507 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1508 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1509 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1510 | FileID FID = FileID::get(I); |
| 1511 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1513 | // Record the offset of this source-location entry. |
| 1514 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1515 | |
| 1516 | // Figure out which record code to use. |
| 1517 | unsigned Code; |
| 1518 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1519 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1520 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1521 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1522 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1523 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1524 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1525 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1526 | Record.clear(); |
| 1527 | Record.push_back(Code); |
| 1528 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1529 | // Starting offset of this entry within this module, so skip the dummy. |
| 1530 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1531 | if (SLoc->isFile()) { |
| 1532 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1533 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1534 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1535 | Record.push_back(File.hasLineDirectives()); |
| 1536 | |
| 1537 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1538 | if (Content->OrigEntry) { |
| 1539 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1540 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1541 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1542 | // The source location entry is a file. The blob associated |
| 1543 | // with this entry is the file name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1544 | |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1545 | // Emit size/modification time for this file. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1546 | Record.push_back(Content->OrigEntry->getSize()); |
| 1547 | Record.push_back(Content->OrigEntry->getModificationTime()); |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1548 | Record.push_back(Content->BufferOverridden); |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1549 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1550 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1551 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1552 | if (FDI != FileDeclIDs.end()) { |
| 1553 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1554 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1555 | } else { |
| 1556 | Record.push_back(0); |
| 1557 | Record.push_back(0); |
| 1558 | } |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1559 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1560 | // 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] | 1561 | const char *Filename = Content->OrigEntry->getName(); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1562 | SmallString<128> FilePath(Filename); |
Anders Carlsson | a426705 | 2011-03-08 16:04:35 +0000 | [diff] [blame] | 1563 | |
| 1564 | // Ask the file manager to fixup the relative path for us. This will |
| 1565 | // honor the working directory. |
| 1566 | SourceMgr.getFileManager().FixupRelativePath(FilePath); |
| 1567 | |
| 1568 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1569 | // call to FixupRelativePath should always return an absolute path. |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1570 | llvm::sys::fs::make_absolute(FilePath); |
Kovarththanan Rajaratnam | d16d38c | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1571 | Filename = FilePath.c_str(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1572 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1573 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1574 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1575 | |
| 1576 | if (Content->BufferOverridden) { |
| 1577 | Record.clear(); |
| 1578 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
| 1579 | const llvm::MemoryBuffer *Buffer |
| 1580 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1581 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
| 1582 | StringRef(Buffer->getBufferStart(), |
| 1583 | Buffer->getBufferSize() + 1)); |
| 1584 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1585 | } else { |
| 1586 | // The source location entry is a buffer. The blob associated |
| 1587 | // with this entry contains the contents of the buffer. |
| 1588 | |
| 1589 | // We add one to the size so that we capture the trailing NULL |
| 1590 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1591 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1592 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1593 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1594 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1595 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1596 | StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1597 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1598 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1599 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1600 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1601 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1602 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1603 | if (strcmp(Name, "<built-in>") == 0) { |
| 1604 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1605 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1606 | } |
| 1607 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1608 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1609 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 73ee5d7 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1610 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1611 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | a1d943a | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1612 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1613 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1614 | |
| 1615 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1616 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1617 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1618 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1619 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1620 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1621 | } |
| 1622 | } |
| 1623 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1624 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1625 | |
| 1626 | if (SLocEntryOffsets.empty()) |
| 1627 | return; |
| 1628 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1629 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1630 | // table is used for lazily loading source-location information. |
| 1631 | using namespace llvm; |
| 1632 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1633 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1634 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1635 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1636 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1637 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1638 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1639 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1640 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1641 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1642 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1643 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1644 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1645 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1646 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1647 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1648 | |
| 1649 | // Write the line table. It depends on remapping working, so it must come |
| 1650 | // after the source location offsets. |
| 1651 | if (SourceMgr.hasLineTable()) { |
| 1652 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1653 | |
| 1654 | Record.clear(); |
| 1655 | // Emit the file names |
| 1656 | Record.push_back(LineTable.getNumFilenames()); |
| 1657 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1658 | // Emit the file name |
| 1659 | const char *Filename = LineTable.getFilename(I); |
| 1660 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1661 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1662 | Record.push_back(FilenameLen); |
| 1663 | if (FilenameLen) |
| 1664 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1665 | } |
| 1666 | |
| 1667 | // Emit the line entries |
| 1668 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1669 | L != LEnd; ++L) { |
| 1670 | // Only emit entries for local files. |
Douglas Gregor | 02c2dbf | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1671 | if (L->first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1672 | continue; |
| 1673 | |
| 1674 | // Emit the file ID |
Douglas Gregor | 02c2dbf | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1675 | Record.push_back(L->first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1676 | |
| 1677 | // Emit the line entries |
| 1678 | Record.push_back(L->second.size()); |
| 1679 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1680 | LEEnd = L->second.end(); |
| 1681 | LE != LEEnd; ++LE) { |
| 1682 | Record.push_back(LE->FileOffset); |
| 1683 | Record.push_back(LE->LineNo); |
| 1684 | Record.push_back(LE->FilenameID); |
| 1685 | Record.push_back((unsigned)LE->FileKind); |
| 1686 | Record.push_back(LE->IncludeOffset); |
| 1687 | } |
| 1688 | } |
| 1689 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1690 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1693 | //===----------------------------------------------------------------------===// |
| 1694 | // Preprocessor Serialization |
| 1695 | //===----------------------------------------------------------------------===// |
| 1696 | |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1697 | static int compareMacroDefinitions(const void *XPtr, const void *YPtr) { |
| 1698 | const std::pair<const IdentifierInfo *, MacroInfo *> &X = |
| 1699 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; |
| 1700 | const std::pair<const IdentifierInfo *, MacroInfo *> &Y = |
| 1701 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; |
| 1702 | return X.first->getName().compare(Y.first->getName()); |
| 1703 | } |
| 1704 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1705 | /// \brief Writes the block containing the serialized form of the |
| 1706 | /// preprocessor. |
| 1707 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1708 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1709 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 1710 | if (PPRec) |
| 1711 | WritePreprocessorDetail(*PPRec); |
| 1712 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1713 | RecordData Record; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1714 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1715 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1716 | if (PP.getCounterValue() != 0) { |
| 1717 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1718 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1719 | Record.clear(); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1723 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1724 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1725 | // 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] | 1726 | // FIXME: use diagnostics subsystem for localization etc. |
| 1727 | if (PP.SawDateOrTime()) |
| 1728 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1730 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1731 | // Loop over all the macro definitions that are live at the end of the file, |
| 1732 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1733 | |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1734 | // Construct the list of macro definitions that need to be serialized. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1735 | SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1736 | MacrosToEmit; |
| 1737 | llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1738 | for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), |
Douglas Gregor | 68051a7 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1739 | E = PP.macro_end(Chain == 0); |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1740 | I != E; ++I) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1741 | if (!IsModule || I->second->isPublic()) { |
| 1742 | MacroDefinitionsSeen.insert(I->first); |
| 1743 | MacrosToEmit.push_back(std::make_pair(I->first, I->second)); |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1744 | } |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1745 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1746 | |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1747 | // Sort the set of macro definitions that need to be serialized by the |
| 1748 | // name of the macro, to provide a stable ordering. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1749 | llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1750 | &compareMacroDefinitions); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1751 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1752 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 1753 | /// the local macro ID |
| 1754 | /// |
| 1755 | /// For each identifier that is associated with a macro, this map |
| 1756 | /// provides the offset into the bitstream where that macro is |
| 1757 | /// defined. |
| 1758 | std::vector<uint32_t> MacroOffsets; |
| 1759 | |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1760 | for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { |
| 1761 | const IdentifierInfo *Name = MacrosToEmit[I].first; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 1762 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1763 | for (MacroInfo *MI = MacrosToEmit[I].second; MI; |
| 1764 | MI = MI->getPreviousDefinition()) { |
| 1765 | MacroID ID = getMacroRef(MI); |
| 1766 | if (!ID) |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1767 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1769 | // Skip macros from a AST file if we're chaining. |
| 1770 | if (Chain && MI->isFromAST() && !MI->hasChangedAfterLoad()) |
| 1771 | continue; |
| 1772 | |
| 1773 | if (ID < FirstMacroID) { |
| 1774 | // This will have been dealt with via an update record. |
| 1775 | assert(MacroUpdates.count(MI) > 0 && "Missing macro update"); |
| 1776 | continue; |
| 1777 | } |
| 1778 | |
| 1779 | // Record the local offset of this macro. |
| 1780 | unsigned Index = ID - FirstMacroID; |
| 1781 | if (Index == MacroOffsets.size()) |
| 1782 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1783 | else { |
| 1784 | if (Index > MacroOffsets.size()) |
| 1785 | MacroOffsets.resize(Index + 1); |
| 1786 | |
| 1787 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 1788 | } |
| 1789 | |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1790 | AddIdentifierRef(Name, Record); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1791 | addMacroRef(MI, Record); |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1792 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1793 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 1794 | AddSourceLocation(MI->getUndefLoc(), Record); |
| 1795 | Record.push_back(MI->isUsed()); |
| 1796 | Record.push_back(MI->isPublic()); |
| 1797 | AddSourceLocation(MI->getVisibilityLocation(), Record); |
| 1798 | unsigned Code; |
| 1799 | if (MI->isObjectLike()) { |
| 1800 | Code = PP_MACRO_OBJECT_LIKE; |
| 1801 | } else { |
| 1802 | Code = PP_MACRO_FUNCTION_LIKE; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1803 | |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1804 | Record.push_back(MI->isC99Varargs()); |
| 1805 | Record.push_back(MI->isGNUVarargs()); |
| 1806 | Record.push_back(MI->getNumArgs()); |
| 1807 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1808 | I != E; ++I) |
| 1809 | AddIdentifierRef(*I, Record); |
| 1810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1811 | |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1812 | // If we have a detailed preprocessing record, record the macro definition |
| 1813 | // ID that corresponds to this macro. |
| 1814 | if (PPRec) |
| 1815 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 1816 | |
| 1817 | Stream.EmitRecord(Code, Record); |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1818 | Record.clear(); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1819 | |
| 1820 | // Emit the tokens array. |
| 1821 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1822 | // Note that we know that the preprocessor does not have any annotation |
| 1823 | // tokens in it because they are created by the parser, and thus can't |
| 1824 | // be in a macro definition. |
| 1825 | const Token &Tok = MI->getReplacementToken(TokNo); |
| 1826 | |
| 1827 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1828 | Record.push_back(Tok.getLength()); |
| 1829 | |
| 1830 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 1831 | // if it is needed. |
| 1832 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 1833 | // FIXME: Should translate token kind to a stable encoding. |
| 1834 | Record.push_back(Tok.getKind()); |
| 1835 | // FIXME: Should translate token flags to a stable encoding. |
| 1836 | Record.push_back(Tok.getFlags()); |
| 1837 | |
| 1838 | Stream.EmitRecord(PP_TOKEN, Record); |
| 1839 | Record.clear(); |
| 1840 | } |
| 1841 | ++NumMacros; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1842 | } |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1843 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1844 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1845 | |
| 1846 | // Write the offsets table for macro IDs. |
| 1847 | using namespace llvm; |
| 1848 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1849 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 1850 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 1851 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 1852 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1853 | |
| 1854 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1855 | Record.clear(); |
| 1856 | Record.push_back(MACRO_OFFSET); |
| 1857 | Record.push_back(MacroOffsets.size()); |
| 1858 | Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS); |
| 1859 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, |
| 1860 | data(MacroOffsets)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 1864 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1865 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1866 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1867 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1869 | // Enter the preprocessor block. |
| 1870 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1872 | // If the preprocessor has a preprocessing record, emit it. |
| 1873 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1874 | using namespace llvm; |
| 1875 | |
| 1876 | // Set up the abbreviation for |
| 1877 | unsigned InclusionAbbrev = 0; |
| 1878 | { |
| 1879 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1880 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1881 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 1882 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 1883 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 1884 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1885 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1886 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1887 | } |
| 1888 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1889 | unsigned FirstPreprocessorEntityID |
| 1890 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 1891 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 1892 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1893 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 1894 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 1895 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1896 | E != EEnd; |
| 1897 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1898 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1899 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1900 | PreprocessedEntityOffsets.push_back(PPEntityOffset((*E)->getSourceRange(), |
| 1901 | Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1902 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1903 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1904 | // Record this macro definition's ID. |
| 1905 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1906 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1907 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1908 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 1909 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1910 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1911 | |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1912 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1913 | Record.push_back(ME->isBuiltinMacro()); |
| 1914 | if (ME->isBuiltinMacro()) |
| 1915 | AddIdentifierRef(ME->getName(), Record); |
| 1916 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1917 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1918 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1919 | continue; |
| 1920 | } |
| 1921 | |
| 1922 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 1923 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1924 | Record.push_back(ID->getFileName().size()); |
| 1925 | Record.push_back(ID->wasInQuotes()); |
| 1926 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 1927 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1928 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1929 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 1930 | // Check that the FileEntry is not null because it was not resolved and |
| 1931 | // we create a PCH even with compiler errors. |
| 1932 | if (ID->getFile()) |
| 1933 | Buffer += ID->getFile()->getName(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1934 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 1935 | continue; |
| 1936 | } |
| 1937 | |
| 1938 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 1939 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1940 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1941 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1942 | // Write the offsets table for the preprocessing record. |
| 1943 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1944 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 1945 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1946 | // Write the offsets table for identifier IDs. |
| 1947 | using namespace llvm; |
| 1948 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1949 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1950 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1951 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1952 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1953 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1954 | Record.clear(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1955 | Record.push_back(PPD_ENTITIES_OFFSETS); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1956 | Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1957 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
| 1958 | data(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1959 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 1962 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 1963 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 1964 | if (Known != SubmoduleIDs.end()) |
| 1965 | return Known->second; |
| 1966 | |
| 1967 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 1968 | } |
| 1969 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1970 | /// \brief Compute the number of modules within the given tree (including the |
| 1971 | /// given module). |
| 1972 | static unsigned getNumberOfModules(Module *Mod) { |
| 1973 | unsigned ChildModules = 0; |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 1974 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 1975 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1976 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 1977 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1978 | |
| 1979 | return ChildModules + 1; |
| 1980 | } |
| 1981 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1982 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6038251 | 2011-12-05 16:35:23 +0000 | [diff] [blame] | 1983 | // Determine the dependencies of our module and each of it's submodules. |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 1984 | // FIXME: This feels like it belongs somewhere else, but there are no |
| 1985 | // other consumers of this information. |
| 1986 | SourceManager &SrcMgr = PP->getSourceManager(); |
| 1987 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
| 1988 | for (ASTContext::import_iterator I = Context->local_import_begin(), |
| 1989 | IEnd = Context->local_import_end(); |
| 1990 | I != IEnd; ++I) { |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 1991 | if (Module *ImportedFrom |
| 1992 | = ModMap.inferModuleFromLocation(FullSourceLoc(I->getLocation(), |
| 1993 | SrcMgr))) { |
| 1994 | ImportedFrom->Imports.push_back(I->getImportedModule()); |
| 1995 | } |
| 1996 | } |
| 1997 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1998 | // Enter the submodule description block. |
| 1999 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
| 2000 | |
| 2001 | // Write the abbreviations needed for the submodules block. |
| 2002 | using namespace llvm; |
| 2003 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2004 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2005 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2006 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2007 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2008 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2009 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2010 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2011 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2012 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2013 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2014 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2015 | |
| 2016 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2017 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2018 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2019 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2020 | |
| 2021 | Abbrev = new BitCodeAbbrev(); |
| 2022 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2023 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2024 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2025 | |
| 2026 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2027 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2028 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2029 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2030 | |
| 2031 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2032 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2033 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2034 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2035 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2036 | Abbrev = new BitCodeAbbrev(); |
| 2037 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
| 2038 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
| 2039 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2040 | |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2041 | Abbrev = new BitCodeAbbrev(); |
| 2042 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2043 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2044 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2045 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2046 | // Write the submodule metadata block. |
| 2047 | RecordData Record; |
| 2048 | Record.push_back(getNumberOfModules(WritingModule)); |
| 2049 | Record.push_back(FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS); |
| 2050 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2051 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2052 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2053 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2054 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2055 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2056 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2057 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2058 | unsigned ID = getSubmoduleID(Mod); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2059 | |
| 2060 | // Emit the definition of the block. |
| 2061 | Record.clear(); |
| 2062 | Record.push_back(SUBMODULE_DEFINITION); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2063 | Record.push_back(ID); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2064 | if (Mod->Parent) { |
| 2065 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
| 2066 | Record.push_back(SubmoduleIDs[Mod->Parent]); |
| 2067 | } else { |
| 2068 | Record.push_back(0); |
| 2069 | } |
| 2070 | Record.push_back(Mod->IsFramework); |
| 2071 | Record.push_back(Mod->IsExplicit); |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2072 | Record.push_back(Mod->IsSystem); |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2073 | Record.push_back(Mod->InferSubmodules); |
| 2074 | Record.push_back(Mod->InferExplicitSubmodules); |
| 2075 | Record.push_back(Mod->InferExportWildcard); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2076 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2077 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2078 | // Emit the requirements. |
| 2079 | for (unsigned I = 0, N = Mod->Requires.size(); I != N; ++I) { |
| 2080 | Record.clear(); |
| 2081 | Record.push_back(SUBMODULE_REQUIRES); |
| 2082 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, |
| 2083 | Mod->Requires[I].data(), |
| 2084 | Mod->Requires[I].size()); |
| 2085 | } |
| 2086 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2087 | // Emit the umbrella header, if there is one. |
Douglas Gregor | 73141fa | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 2088 | if (const FileEntry *UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2089 | Record.clear(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2090 | Record.push_back(SUBMODULE_UMBRELLA_HEADER); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2091 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
Douglas Gregor | 73141fa | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 2092 | UmbrellaHeader->getName()); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2093 | } else if (const DirectoryEntry *UmbrellaDir = Mod->getUmbrellaDir()) { |
| 2094 | Record.clear(); |
| 2095 | Record.push_back(SUBMODULE_UMBRELLA_DIR); |
| 2096 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
| 2097 | UmbrellaDir->getName()); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | // Emit the headers. |
| 2101 | for (unsigned I = 0, N = Mod->Headers.size(); I != N; ++I) { |
| 2102 | Record.clear(); |
| 2103 | Record.push_back(SUBMODULE_HEADER); |
| 2104 | Stream.EmitRecordWithBlob(HeaderAbbrev, Record, |
| 2105 | Mod->Headers[I]->getName()); |
| 2106 | } |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2107 | // Emit the excluded headers. |
| 2108 | for (unsigned I = 0, N = Mod->ExcludedHeaders.size(); I != N; ++I) { |
| 2109 | Record.clear(); |
| 2110 | Record.push_back(SUBMODULE_EXCLUDED_HEADER); |
| 2111 | Stream.EmitRecordWithBlob(ExcludedHeaderAbbrev, Record, |
| 2112 | Mod->ExcludedHeaders[I]->getName()); |
| 2113 | } |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2114 | for (unsigned I = 0, N = Mod->TopHeaders.size(); I != N; ++I) { |
| 2115 | Record.clear(); |
| 2116 | Record.push_back(SUBMODULE_TOPHEADER); |
| 2117 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, |
| 2118 | Mod->TopHeaders[I]->getName()); |
| 2119 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2120 | |
| 2121 | // Emit the imports. |
| 2122 | if (!Mod->Imports.empty()) { |
| 2123 | Record.clear(); |
| 2124 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
Douglas Gregor | 18b5864 | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2125 | unsigned ImportedID = getSubmoduleID(Mod->Imports[I]); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2126 | assert(ImportedID && "Unknown submodule!"); |
| 2127 | Record.push_back(ImportedID); |
| 2128 | } |
| 2129 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2130 | } |
| 2131 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2132 | // Emit the exports. |
| 2133 | if (!Mod->Exports.empty()) { |
| 2134 | Record.clear(); |
| 2135 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
Douglas Gregor | 18b5864 | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2136 | if (Module *Exported = Mod->Exports[I].getPointer()) { |
| 2137 | unsigned ExportedID = SubmoduleIDs[Exported]; |
| 2138 | assert(ExportedID > 0 && "Unknown submodule ID?"); |
| 2139 | Record.push_back(ExportedID); |
| 2140 | } else { |
| 2141 | Record.push_back(0); |
| 2142 | } |
| 2143 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2144 | Record.push_back(Mod->Exports[I].getInt()); |
| 2145 | } |
| 2146 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2147 | } |
| 2148 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2149 | // Queue up the submodules of this module. |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2150 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2151 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2152 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2153 | Q.push(*Sub); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | Stream.ExitBlock(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2157 | |
| 2158 | assert((NextSubmoduleID - FirstSubmoduleID |
| 2159 | == getNumberOfModules(WritingModule)) && "Wrong # of submodules"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2162 | serialization::SubmoduleID |
| 2163 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2164 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2165 | return 0; // No submodule |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2166 | |
| 2167 | // Find the module that owns this location. |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2168 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2169 | Module *OwningMod |
| 2170 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2171 | if (!OwningMod) |
| 2172 | return 0; |
| 2173 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2174 | // Check whether this submodule is part of our own module. |
| 2175 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2176 | return 0; |
| 2177 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2178 | return getSubmoduleID(OwningMod); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2181 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) { |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2182 | RecordData Record; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2183 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2184 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2185 | I != E; ++I) { |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2186 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2187 | if (point.Loc.isInvalid()) |
| 2188 | continue; |
| 2189 | |
| 2190 | Record.push_back(point.Loc.getRawEncoding()); |
Daniel Dunbar | e8c12a2 | 2011-09-29 01:42:25 +0000 | [diff] [blame] | 2191 | for (DiagnosticsEngine::DiagState::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2192 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
Daniel Dunbar | a3637e6 | 2011-09-29 01:30:00 +0000 | [diff] [blame] | 2193 | if (I->second.isPragma()) { |
| 2194 | Record.push_back(I->first); |
| 2195 | Record.push_back(I->second.getMapping()); |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2196 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2197 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2198 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2199 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2202 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2203 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2206 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2207 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2208 | return; |
| 2209 | |
| 2210 | RecordData Record; |
| 2211 | |
| 2212 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2213 | using namespace llvm; |
| 2214 | |
| 2215 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2216 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2217 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2218 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2219 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2220 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2221 | // Write the base specifier offsets table. |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2222 | Record.clear(); |
| 2223 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 2224 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 2225 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2226 | data(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2229 | //===----------------------------------------------------------------------===// |
| 2230 | // Type Serialization |
| 2231 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2232 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2233 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2234 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | a7fbbb0 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2235 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2236 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2237 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2238 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2239 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2240 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2241 | // Record the offset for this type. |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2242 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2243 | if (TypeOffsets.size() == Index) |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2244 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2245 | else if (TypeOffsets.size() < Index) { |
| 2246 | TypeOffsets.resize(Index + 1); |
| 2247 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2251 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2252 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2253 | ASTTypeWriter W(*this, Record); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2254 | |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2255 | if (T.hasLocalNonFastQualifiers()) { |
| 2256 | Qualifiers Qs = T.getLocalQualifiers(); |
| 2257 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2258 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2259 | W.Code = TYPE_EXT_QUAL; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2260 | } else { |
| 2261 | switch (T->getTypeClass()) { |
| 2262 | // For all of the concrete, non-dependent types, call the |
| 2263 | // appropriate visitor function. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2264 | #define TYPE(Class, Base) \ |
Mike Stump | 281d6d7 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 2265 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2266 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2267 | #include "clang/AST/TypeNodes.def" |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2268 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | // Emit the serialized record. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2272 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2273 | |
| 2274 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2275 | FlushStmts(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2278 | //===----------------------------------------------------------------------===// |
| 2279 | // Declaration Serialization |
| 2280 | //===----------------------------------------------------------------------===// |
| 2281 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2282 | /// \brief Write the block containing all of the declaration IDs |
| 2283 | /// lexically declared within the given DeclContext. |
| 2284 | /// |
| 2285 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2286 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2287 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2288 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2289 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2290 | return 0; |
| 2291 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2292 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2293 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2294 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2295 | SmallVector<KindDeclIDPair, 64> Decls; |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2296 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 2297 | D != DEnd; ++D) |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2298 | Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2299 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2300 | ++NumLexicalDeclContexts; |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2301 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2302 | return Offset; |
| 2303 | } |
| 2304 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2305 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2306 | using namespace llvm; |
| 2307 | RecordData Record; |
| 2308 | |
| 2309 | // Write the type offsets array |
| 2310 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2311 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2312 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2313 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2314 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2315 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2316 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2317 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2318 | Record.push_back(TypeOffsets.size()); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2319 | Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2320 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2321 | |
| 2322 | // Write the declaration offsets array |
| 2323 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2324 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2325 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2326 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2327 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2328 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2329 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2330 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2331 | Record.push_back(DeclOffsets.size()); |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2332 | Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2333 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2336 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2337 | using namespace llvm; |
| 2338 | RecordData Record; |
| 2339 | |
| 2340 | // Join the vectors of DeclIDs from all files. |
| 2341 | SmallVector<DeclID, 256> FileSortedIDs; |
| 2342 | for (FileDeclIDsTy::iterator |
| 2343 | FI = FileDeclIDs.begin(), FE = FileDeclIDs.end(); FI != FE; ++FI) { |
| 2344 | DeclIDInFileInfo &Info = *FI->second; |
| 2345 | Info.FirstDeclIndex = FileSortedIDs.size(); |
| 2346 | for (LocDeclIDsTy::iterator |
| 2347 | DI = Info.DeclIDs.begin(), DE = Info.DeclIDs.end(); DI != DE; ++DI) |
| 2348 | FileSortedIDs.push_back(DI->second); |
| 2349 | } |
| 2350 | |
| 2351 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2352 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2353 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2354 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2355 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 2356 | Record.push_back(FILE_SORTED_DECLS); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2357 | Record.push_back(FileSortedIDs.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2358 | Stream.EmitRecordWithBlob(AbbrevCode, Record, data(FileSortedIDs)); |
| 2359 | } |
| 2360 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2361 | void ASTWriter::WriteComments() { |
| 2362 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2363 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2364 | RecordData Record; |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2365 | for (ArrayRef<RawComment *>::iterator I = RawComments.begin(), |
| 2366 | E = RawComments.end(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2367 | I != E; ++I) { |
| 2368 | Record.clear(); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2369 | AddSourceRange((*I)->getSourceRange(), Record); |
| 2370 | Record.push_back((*I)->getKind()); |
| 2371 | Record.push_back((*I)->isTrailingComment()); |
| 2372 | Record.push_back((*I)->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2373 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2374 | } |
| 2375 | Stream.ExitBlock(); |
| 2376 | } |
| 2377 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2378 | //===----------------------------------------------------------------------===// |
| 2379 | // Global Method Pool and Selector Serialization |
| 2380 | //===----------------------------------------------------------------------===// |
| 2381 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2382 | namespace { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2383 | // 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] | 2384 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2385 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2386 | |
| 2387 | public: |
| 2388 | typedef Selector key_type; |
| 2389 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2390 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2391 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2392 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2393 | ObjCMethodList Instance, Factory; |
| 2394 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2395 | typedef const data_type& data_type_ref; |
| 2396 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2397 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2398 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2399 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2400 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2402 | |
| 2403 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2404 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2405 | data_type_ref Methods) { |
| 2406 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 2407 | clang::io::Emit16(Out, KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2408 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2409 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2410 | Method = Method->Next) |
| 2411 | if (Method->Method) |
| 2412 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2413 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2414 | Method = Method->Next) |
| 2415 | if (Method->Method) |
| 2416 | DataLen += 4; |
| 2417 | clang::io::Emit16(Out, DataLen); |
| 2418 | return std::make_pair(KeyLen, DataLen); |
| 2419 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2420 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2421 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2422 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2423 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2424 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2425 | unsigned N = Sel.getNumArgs(); |
| 2426 | clang::io::Emit16(Out, N); |
| 2427 | if (N == 0) |
| 2428 | N = 1; |
| 2429 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2430 | clang::io::Emit32(Out, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2431 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 2432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2433 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2434 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2435 | data_type_ref Methods, unsigned DataLen) { |
| 2436 | uint64_t Start = Out.tell(); (void)Start; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2437 | clang::io::Emit32(Out, Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2438 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2439 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2440 | Method = Method->Next) |
| 2441 | if (Method->Method) |
| 2442 | ++NumInstanceMethods; |
| 2443 | |
| 2444 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2445 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2446 | Method = Method->Next) |
| 2447 | if (Method->Method) |
| 2448 | ++NumFactoryMethods; |
| 2449 | |
| 2450 | clang::io::Emit16(Out, NumInstanceMethods); |
| 2451 | clang::io::Emit16(Out, NumFactoryMethods); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2452 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2453 | Method = Method->Next) |
| 2454 | if (Method->Method) |
| 2455 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2456 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2457 | Method = Method->Next) |
| 2458 | if (Method->Method) |
| 2459 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2460 | |
| 2461 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2462 | } |
| 2463 | }; |
| 2464 | } // end anonymous namespace |
| 2465 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2466 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2467 | /// |
| 2468 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2469 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2470 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2471 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2472 | using namespace llvm; |
| 2473 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2474 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2475 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2476 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2477 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2478 | // 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] | 2479 | { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2480 | OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2481 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2482 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2483 | // Create the on-disk hash table representation. We walk through every |
| 2484 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2485 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2486 | for (llvm::DenseMap<Selector, SelectorID>::iterator |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2487 | I = SelectorIDs.begin(), E = SelectorIDs.end(); |
| 2488 | I != E; ++I) { |
| 2489 | Selector S = I->first; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2490 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2491 | ASTMethodPoolTrait::data_type Data = { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2492 | I->second, |
| 2493 | ObjCMethodList(), |
| 2494 | ObjCMethodList() |
| 2495 | }; |
| 2496 | if (F != SemaRef.MethodPool.end()) { |
| 2497 | Data.Instance = F->second.first; |
| 2498 | Data.Factory = F->second.second; |
| 2499 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2500 | // 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] | 2501 | // changed. |
| 2502 | if (Chain && I->second < FirstSelectorID) { |
| 2503 | // Selector already exists. Did it change? |
| 2504 | bool changed = false; |
| 2505 | for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; |
| 2506 | M = M->Next) { |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2507 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2508 | changed = true; |
| 2509 | } |
| 2510 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; |
| 2511 | M = M->Next) { |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2512 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2513 | changed = true; |
| 2514 | } |
| 2515 | if (!changed) |
| 2516 | continue; |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2517 | } else if (Data.Instance.Method || Data.Factory.Method) { |
| 2518 | // A new method pool entry. |
| 2519 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2520 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2521 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2524 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2525 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2526 | uint32_t BucketOffset; |
| 2527 | { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2528 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2529 | llvm::raw_svector_ostream Out(MethodPool); |
| 2530 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2531 | clang::io::Emit32(Out, 0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2532 | BucketOffset = Generator.Emit(Out, Trait); |
| 2533 | } |
| 2534 | |
| 2535 | // Create a blob abbreviation |
| 2536 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2537 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2538 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2539 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2540 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2541 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2542 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2543 | // Write the method pool |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2544 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2545 | Record.push_back(METHOD_POOL); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2546 | Record.push_back(BucketOffset); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2547 | Record.push_back(NumTableEntries); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2548 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2549 | |
| 2550 | // Create a blob abbreviation for the selector table offsets. |
| 2551 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2552 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2553 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2554 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2555 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2556 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2557 | |
| 2558 | // Write the selector offsets table. |
| 2559 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2560 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2561 | Record.push_back(SelectorOffsets.size()); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2562 | Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2563 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2564 | data(SelectorOffsets)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2565 | } |
| 2566 | } |
| 2567 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2568 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2569 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2570 | using namespace llvm; |
| 2571 | if (SemaRef.ReferencedSelectors.empty()) |
| 2572 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2573 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2574 | RecordData Record; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2575 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2576 | // 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] | 2577 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 2578 | // headers, probably not worth it. It's not a correctness issue. |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2579 | for (DenseMap<Selector, SourceLocation>::iterator S = |
| 2580 | SemaRef.ReferencedSelectors.begin(), |
| 2581 | E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { |
| 2582 | Selector Sel = (*S).first; |
| 2583 | SourceLocation Loc = (*S).second; |
| 2584 | AddSelectorRef(Sel, Record); |
| 2585 | AddSourceLocation(Loc, Record); |
| 2586 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2587 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2590 | //===----------------------------------------------------------------------===// |
| 2591 | // Identifier Table Serialization |
| 2592 | //===----------------------------------------------------------------------===// |
| 2593 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2594 | namespace { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2595 | class ASTIdentifierTableTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2596 | ASTWriter &Writer; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2597 | Preprocessor &PP; |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2598 | IdentifierResolver &IdResolver; |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2599 | bool IsModule; |
| 2600 | |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2601 | /// \brief Determines whether this is an "interesting" identifier |
| 2602 | /// that needs a full IdentifierInfo structure written into the hash |
| 2603 | /// table. |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2604 | bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) { |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2605 | if (II->isPoisoned() || |
| 2606 | II->isExtensionToken() || |
| 2607 | II->getObjCOrBuiltinID() || |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2608 | II->hasRevertedTokenIDToIdentifier() || |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2609 | II->getFETokenInfo<void>()) |
| 2610 | return true; |
| 2611 | |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2612 | return hadMacroDefinition(II, Macro); |
Douglas Gregor | d7910e9 | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2613 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2614 | |
| 2615 | bool hadMacroDefinition(IdentifierInfo *II, MacroInfo *&Macro) { |
| 2616 | if (!II->hadMacroDefinition()) |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2617 | return false; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2618 | |
| 2619 | if (Macro || (Macro = PP.getMacroInfoHistory(II))) |
Douglas Gregor | ebf0049 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 2620 | return !Macro->isBuiltinMacro() && (!IsModule || Macro->isPublic()); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2621 | |
| 2622 | return false; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2625 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2626 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2627 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2628 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2629 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2630 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2631 | |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2632 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
| 2633 | IdentifierResolver &IdResolver, bool IsModule) |
| 2634 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule) { } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2635 | |
| 2636 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 2637 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2638 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2639 | |
| 2640 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2641 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2642 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2643 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Douglas Gregor | d7910e9 | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2644 | MacroInfo *Macro = 0; |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2645 | if (isInterestingIdentifier(II, Macro)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2646 | DataLen += 2; // 2 bytes for builtin ID |
| 2647 | DataLen += 2; // 2 bytes for flags |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2648 | if (hadMacroDefinition(II, Macro)) { |
| 2649 | for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { |
| 2650 | if (Writer.getMacroRef(M) != 0) |
| 2651 | DataLen += 4; |
| 2652 | } |
| 2653 | |
| 2654 | DataLen += 4; |
| 2655 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2656 | |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2657 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 2658 | DEnd = IdResolver.end(); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2659 | D != DEnd; ++D) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2660 | DataLen += sizeof(DeclID); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2661 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2662 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 2663 | // We emit the key length after the data length so that every |
| 2664 | // string is preceded by a 16-bit length. This matches the PTH |
| 2665 | // format for storing identifiers. |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2666 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2667 | return std::make_pair(KeyLen, DataLen); |
| 2668 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2669 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2670 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2671 | unsigned KeyLen) { |
| 2672 | // Record the location of the key data. This is used when generating |
| 2673 | // the mapping from persistent IDs to strings. |
| 2674 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2675 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2676 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2677 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2678 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2679 | IdentID ID, unsigned) { |
Douglas Gregor | d7910e9 | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2680 | MacroInfo *Macro = 0; |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2681 | if (!isInterestingIdentifier(II, Macro)) { |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2682 | clang::io::Emit32(Out, ID << 1); |
| 2683 | return; |
| 2684 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2685 | |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2686 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2687 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 2688 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
| 2689 | clang::io::Emit16(Out, Bits); |
| 2690 | Bits = 0; |
| 2691 | bool HadMacroDefinition = hadMacroDefinition(II, Macro); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2692 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2693 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 2694 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 2695 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2696 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2697 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2698 | |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2699 | if (HadMacroDefinition) { |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2700 | // Write all of the macro IDs associated with this identifier. |
| 2701 | for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { |
| 2702 | if (MacroID ID = Writer.getMacroRef(M)) |
| 2703 | clang::io::Emit32(Out, ID); |
| 2704 | } |
| 2705 | |
| 2706 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 7b8e4bc | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2707 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2708 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2709 | // Emit the declaration IDs in reverse order, because the |
| 2710 | // IdentifierResolver provides the declarations as they would be |
| 2711 | // visible (e.g., the function "stat" would come before the struct |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2712 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 2713 | // (so we need to see the struct "status" before the function "status"). |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2714 | // Only emit declarations that aren't from a chained PCH, though. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2715 | SmallVector<Decl *, 16> Decls(IdResolver.begin(II), |
| 2716 | IdResolver.end()); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2717 | for (SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2718 | DEnd = Decls.rend(); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2719 | D != DEnd; ++D) |
Sebastian Redl | 78f5177 | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 2720 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2721 | } |
| 2722 | }; |
| 2723 | } // end anonymous namespace |
| 2724 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2725 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2726 | /// |
| 2727 | /// The identifier table consists of a blob containing string data |
| 2728 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 2729 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2730 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 2731 | IdentifierResolver &IdResolver, |
| 2732 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2733 | using namespace llvm; |
| 2734 | |
| 2735 | // Create and write out the blob that contains the identifier |
| 2736 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2737 | { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2738 | OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2739 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2740 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2741 | // Look for any identifiers that were named while processing the |
| 2742 | // headers, but are otherwise not needed. We add these to the hash |
| 2743 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2744 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2745 | // file. |
| 2746 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 2747 | IDEnd = PP.getIdentifierTable().end(); |
| 2748 | ID != IDEnd; ++ID) |
| 2749 | getIdentifierRef(ID->second); |
| 2750 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2751 | // Create the on-disk hash table representation. We only store offsets |
| 2752 | // for identifiers that appear here for the first time. |
| 2753 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2754 | for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2755 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 2756 | ID != IDEnd; ++ID) { |
| 2757 | assert(ID->first && "NULL identifier in identifier table"); |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2758 | if (!Chain || !ID->first->isFromAST() || |
| 2759 | ID->first->hasChangedSinceDeserialization()) |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2760 | Generator.insert(const_cast<IdentifierInfo *>(ID->first), ID->second, |
| 2761 | Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2762 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2763 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2764 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2765 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2766 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2767 | { |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2768 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2769 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2770 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2771 | clang::io::Emit32(Out, 0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2772 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | // Create a blob abbreviation |
| 2776 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2777 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2778 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2779 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2780 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2781 | |
| 2782 | // Write the identifier table |
| 2783 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2784 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2785 | Record.push_back(BucketOffset); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2786 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2790 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2791 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2792 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2793 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2794 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2795 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2796 | |
| 2797 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2798 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2799 | Record.push_back(IdentifierOffsets.size()); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2800 | Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2801 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2802 | data(IdentifierOffsets)); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2805 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2806 | // DeclContext's Name Lookup Table Serialization |
| 2807 | //===----------------------------------------------------------------------===// |
| 2808 | |
| 2809 | namespace { |
| 2810 | // Trait used for the on-disk hash table used in the method pool. |
| 2811 | class ASTDeclContextNameLookupTrait { |
| 2812 | ASTWriter &Writer; |
| 2813 | |
| 2814 | public: |
| 2815 | typedef DeclarationName key_type; |
| 2816 | typedef key_type key_type_ref; |
| 2817 | |
| 2818 | typedef DeclContext::lookup_result data_type; |
| 2819 | typedef const data_type& data_type_ref; |
| 2820 | |
| 2821 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 2822 | |
| 2823 | unsigned ComputeHash(DeclarationName Name) { |
| 2824 | llvm::FoldingSetNodeID ID; |
| 2825 | ID.AddInteger(Name.getNameKind()); |
| 2826 | |
| 2827 | switch (Name.getNameKind()) { |
| 2828 | case DeclarationName::Identifier: |
| 2829 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 2830 | break; |
| 2831 | case DeclarationName::ObjCZeroArgSelector: |
| 2832 | case DeclarationName::ObjCOneArgSelector: |
| 2833 | case DeclarationName::ObjCMultiArgSelector: |
| 2834 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 2835 | break; |
| 2836 | case DeclarationName::CXXConstructorName: |
| 2837 | case DeclarationName::CXXDestructorName: |
| 2838 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2839 | break; |
| 2840 | case DeclarationName::CXXOperatorName: |
| 2841 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 2842 | break; |
| 2843 | case DeclarationName::CXXLiteralOperatorName: |
| 2844 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 2845 | case DeclarationName::CXXUsingDirective: |
| 2846 | break; |
| 2847 | } |
| 2848 | |
| 2849 | return ID.ComputeHash(); |
| 2850 | } |
| 2851 | |
| 2852 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2853 | EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2854 | data_type_ref Lookup) { |
| 2855 | unsigned KeyLen = 1; |
| 2856 | switch (Name.getNameKind()) { |
| 2857 | case DeclarationName::Identifier: |
| 2858 | case DeclarationName::ObjCZeroArgSelector: |
| 2859 | case DeclarationName::ObjCOneArgSelector: |
| 2860 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2861 | case DeclarationName::CXXLiteralOperatorName: |
| 2862 | KeyLen += 4; |
| 2863 | break; |
| 2864 | case DeclarationName::CXXOperatorName: |
| 2865 | KeyLen += 1; |
| 2866 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2867 | case DeclarationName::CXXConstructorName: |
| 2868 | case DeclarationName::CXXDestructorName: |
| 2869 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2870 | case DeclarationName::CXXUsingDirective: |
| 2871 | break; |
| 2872 | } |
| 2873 | clang::io::Emit16(Out, KeyLen); |
| 2874 | |
| 2875 | // 2 bytes for num of decls and 4 for each DeclID. |
| 2876 | unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); |
| 2877 | clang::io::Emit16(Out, DataLen); |
| 2878 | |
| 2879 | return std::make_pair(KeyLen, DataLen); |
| 2880 | } |
| 2881 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2882 | void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2883 | using namespace clang::io; |
| 2884 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2885 | Emit8(Out, Name.getNameKind()); |
| 2886 | switch (Name.getNameKind()) { |
| 2887 | case DeclarationName::Identifier: |
| 2888 | Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2889 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2890 | case DeclarationName::ObjCZeroArgSelector: |
| 2891 | case DeclarationName::ObjCOneArgSelector: |
| 2892 | case DeclarationName::ObjCMultiArgSelector: |
| 2893 | Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2894 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2895 | case DeclarationName::CXXOperatorName: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2896 | assert(Name.getCXXOverloadedOperator() < NUM_OVERLOADED_OPERATORS && |
| 2897 | "Invalid operator?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2898 | Emit8(Out, Name.getCXXOverloadedOperator()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2899 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2900 | case DeclarationName::CXXLiteralOperatorName: |
| 2901 | Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2902 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2903 | case DeclarationName::CXXConstructorName: |
| 2904 | case DeclarationName::CXXDestructorName: |
| 2905 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2906 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2907 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2908 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2909 | |
| 2910 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2913 | void EmitData(raw_ostream& Out, key_type_ref, |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2914 | data_type Lookup, unsigned DataLen) { |
| 2915 | uint64_t Start = Out.tell(); (void)Start; |
| 2916 | clang::io::Emit16(Out, Lookup.second - Lookup.first); |
| 2917 | for (; Lookup.first != Lookup.second; ++Lookup.first) |
| 2918 | clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); |
| 2919 | |
| 2920 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 2921 | } |
| 2922 | }; |
| 2923 | } // end anonymous namespace |
| 2924 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2925 | /// \brief Write the block containing all of the declaration IDs |
| 2926 | /// visible from the given DeclContext. |
| 2927 | /// |
| 2928 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2929 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2930 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 2931 | DeclContext *DC) { |
| 2932 | if (DC->getPrimaryContext() != DC) |
| 2933 | return 0; |
| 2934 | |
| 2935 | // Since there is no name lookup into functions or methods, don't bother to |
| 2936 | // build a visible-declarations table for these entities. |
| 2937 | if (DC->isFunctionOrMethod()) |
| 2938 | return 0; |
| 2939 | |
| 2940 | // If not in C++, we perform name lookup for the translation unit via the |
| 2941 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 2942 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 2943 | // friend declarations, is there a way to do this without writing the table ? |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2944 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2945 | return 0; |
| 2946 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2947 | // Serialize the contents of the mapping used for lookup. Note that, |
| 2948 | // although we have two very different code paths, the serialized |
| 2949 | // representation is the same for both cases: a declaration name, |
| 2950 | // followed by a size, followed by references to the visible |
| 2951 | // declarations that have that name. |
| 2952 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 2953 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2954 | if (!Map || Map->empty()) |
| 2955 | return 0; |
| 2956 | |
| 2957 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2958 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2959 | |
| 2960 | // Create the on-disk hash table representation. |
Douglas Gregor | 05ef931 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2961 | DeclarationName ConversionName; |
| 2962 | llvm::SmallVector<NamedDecl *, 4> ConversionDecls; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2963 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2964 | D != DEnd; ++D) { |
| 2965 | DeclarationName Name = D->first; |
| 2966 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Douglas Gregor | 05ef931 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2967 | if (Result.first != Result.second) { |
| 2968 | if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 2969 | // Hash all conversion function names to the same name. The actual |
| 2970 | // type information in conversion function name is not used in the |
| 2971 | // key (since such type information is not stable across different |
| 2972 | // modules), so the intended effect is to coalesce all of the conversion |
| 2973 | // functions under a single key. |
| 2974 | if (!ConversionName) |
| 2975 | ConversionName = Name; |
| 2976 | ConversionDecls.append(Result.first, Result.second); |
| 2977 | continue; |
| 2978 | } |
| 2979 | |
Argyrios Kyrtzidis | d3497db | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 2980 | Generator.insert(Name, Result, Trait); |
Douglas Gregor | 05ef931 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2981 | } |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2982 | } |
| 2983 | |
Douglas Gregor | 05ef931 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2984 | // Add the conversion functions |
| 2985 | if (!ConversionDecls.empty()) { |
| 2986 | Generator.insert(ConversionName, |
| 2987 | DeclContext::lookup_result(ConversionDecls.begin(), |
| 2988 | ConversionDecls.end()), |
| 2989 | Trait); |
| 2990 | } |
| 2991 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2992 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2993 | SmallString<4096> LookupTable; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2994 | uint32_t BucketOffset; |
| 2995 | { |
| 2996 | llvm::raw_svector_ostream Out(LookupTable); |
| 2997 | // Make sure that no bucket is at offset 0 |
| 2998 | clang::io::Emit32(Out, 0); |
| 2999 | BucketOffset = Generator.Emit(Out, Trait); |
| 3000 | } |
| 3001 | |
| 3002 | // Write the lookup table |
| 3003 | RecordData Record; |
| 3004 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 3005 | Record.push_back(BucketOffset); |
| 3006 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
| 3007 | LookupTable.str()); |
| 3008 | |
| 3009 | Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); |
| 3010 | ++NumVisibleDeclContexts; |
| 3011 | return Offset; |
| 3012 | } |
| 3013 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3014 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3015 | /// |
| 3016 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3017 | /// DeclContext in a dependent AST file. As such, they only exist for the TU |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3018 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3019 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3020 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3021 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 3022 | if (!Map || Map->empty()) |
| 3023 | return; |
| 3024 | |
| 3025 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 3026 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3027 | |
| 3028 | // Create the hash table. |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3029 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 3030 | D != DEnd; ++D) { |
| 3031 | DeclarationName Name = D->first; |
| 3032 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Sebastian Redl | 9617e7e | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3033 | // For any name that appears in this table, the results are complete, i.e. |
| 3034 | // they overwrite results from previous PCHs. Merging is always a mess. |
Argyrios Kyrtzidis | d3497db | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 3035 | if (Result.first != Result.second) |
| 3036 | Generator.insert(Name, Result, Trait); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3040 | SmallString<4096> LookupTable; |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3041 | uint32_t BucketOffset; |
| 3042 | { |
| 3043 | llvm::raw_svector_ostream Out(LookupTable); |
| 3044 | // Make sure that no bucket is at offset 0 |
| 3045 | clang::io::Emit32(Out, 0); |
| 3046 | BucketOffset = Generator.Emit(Out, Trait); |
| 3047 | } |
| 3048 | |
| 3049 | // Write the lookup table |
| 3050 | RecordData Record; |
| 3051 | Record.push_back(UPDATE_VISIBLE); |
| 3052 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 3053 | Record.push_back(BucketOffset); |
| 3054 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); |
| 3055 | } |
| 3056 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3057 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3058 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 3059 | RecordData Record; |
| 3060 | Record.push_back(Opts.fp_contract); |
| 3061 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3062 | } |
| 3063 | |
| 3064 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3065 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3066 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3067 | return; |
| 3068 | |
| 3069 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3070 | RecordData Record; |
| 3071 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3072 | #include "clang/Basic/OpenCLExtensions.def" |
| 3073 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3074 | } |
| 3075 | |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3076 | void ASTWriter::WriteRedeclarations() { |
| 3077 | RecordData LocalRedeclChains; |
| 3078 | SmallVector<serialization::LocalRedeclarationsInfo, 2> LocalRedeclsMap; |
| 3079 | |
| 3080 | for (unsigned I = 0, N = Redeclarations.size(); I != N; ++I) { |
| 3081 | Decl *First = Redeclarations[I]; |
| 3082 | assert(First->getPreviousDecl() == 0 && "Not the first declaration?"); |
| 3083 | |
| 3084 | Decl *MostRecent = First->getMostRecentDecl(); |
| 3085 | |
| 3086 | // If we only have a single declaration, there is no point in storing |
| 3087 | // a redeclaration chain. |
| 3088 | if (First == MostRecent) |
| 3089 | continue; |
| 3090 | |
| 3091 | unsigned Offset = LocalRedeclChains.size(); |
| 3092 | unsigned Size = 0; |
| 3093 | LocalRedeclChains.push_back(0); // Placeholder for the size. |
| 3094 | |
| 3095 | // Collect the set of local redeclarations of this declaration. |
| 3096 | for (Decl *Prev = MostRecent; Prev != First; |
| 3097 | Prev = Prev->getPreviousDecl()) { |
| 3098 | if (!Prev->isFromASTFile()) { |
| 3099 | AddDeclRef(Prev, LocalRedeclChains); |
| 3100 | ++Size; |
| 3101 | } |
| 3102 | } |
| 3103 | LocalRedeclChains[Offset] = Size; |
| 3104 | |
| 3105 | // Reverse the set of local redeclarations, so that we store them in |
| 3106 | // order (since we found them in reverse order). |
| 3107 | std::reverse(LocalRedeclChains.end() - Size, LocalRedeclChains.end()); |
| 3108 | |
| 3109 | // Add the mapping from the first ID to the set of local declarations. |
| 3110 | LocalRedeclarationsInfo Info = { getDeclID(First), Offset }; |
| 3111 | LocalRedeclsMap.push_back(Info); |
| 3112 | |
| 3113 | assert(N == Redeclarations.size() && |
| 3114 | "Deserialized a declaration we shouldn't have"); |
| 3115 | } |
| 3116 | |
| 3117 | if (LocalRedeclChains.empty()) |
| 3118 | return; |
| 3119 | |
| 3120 | // Sort the local redeclarations map by the first declaration ID, |
| 3121 | // since the reader will be performing binary searches on this information. |
| 3122 | llvm::array_pod_sort(LocalRedeclsMap.begin(), LocalRedeclsMap.end()); |
| 3123 | |
| 3124 | // Emit the local redeclarations map. |
| 3125 | using namespace llvm; |
| 3126 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3127 | Abbrev->Add(BitCodeAbbrevOp(LOCAL_REDECLARATIONS_MAP)); |
| 3128 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3129 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3130 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3131 | |
| 3132 | RecordData Record; |
| 3133 | Record.push_back(LOCAL_REDECLARATIONS_MAP); |
| 3134 | Record.push_back(LocalRedeclsMap.size()); |
| 3135 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3136 | reinterpret_cast<char*>(LocalRedeclsMap.data()), |
| 3137 | LocalRedeclsMap.size() * sizeof(LocalRedeclarationsInfo)); |
| 3138 | |
| 3139 | // Emit the redeclaration chains. |
| 3140 | Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedeclChains); |
| 3141 | } |
| 3142 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3143 | void ASTWriter::WriteObjCCategories() { |
| 3144 | llvm::SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
| 3145 | RecordData Categories; |
| 3146 | |
| 3147 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3148 | unsigned Size = 0; |
| 3149 | unsigned StartIndex = Categories.size(); |
| 3150 | |
| 3151 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3152 | |
| 3153 | // Allocate space for the size. |
| 3154 | Categories.push_back(0); |
| 3155 | |
| 3156 | // Add the categories. |
| 3157 | for (ObjCCategoryDecl *Cat = Class->getCategoryList(); |
| 3158 | Cat; Cat = Cat->getNextClassCategory(), ++Size) { |
| 3159 | assert(getDeclID(Cat) != 0 && "Bogus category"); |
| 3160 | AddDeclRef(Cat, Categories); |
| 3161 | } |
| 3162 | |
| 3163 | // Update the size. |
| 3164 | Categories[StartIndex] = Size; |
| 3165 | |
| 3166 | // Record this interface -> category map. |
| 3167 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3168 | CategoriesMap.push_back(CatInfo); |
| 3169 | } |
| 3170 | |
| 3171 | // Sort the categories map by the definition ID, since the reader will be |
| 3172 | // performing binary searches on this information. |
| 3173 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3174 | |
| 3175 | // Emit the categories map. |
| 3176 | using namespace llvm; |
| 3177 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3178 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3179 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3180 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3181 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3182 | |
| 3183 | RecordData Record; |
| 3184 | Record.push_back(OBJC_CATEGORIES_MAP); |
| 3185 | Record.push_back(CategoriesMap.size()); |
| 3186 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3187 | reinterpret_cast<char*>(CategoriesMap.data()), |
| 3188 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
| 3189 | |
| 3190 | // Emit the category lists. |
| 3191 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3192 | } |
| 3193 | |
Douglas Gregor | 464b0ca | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3194 | void ASTWriter::WriteMergedDecls() { |
| 3195 | if (!Chain || Chain->MergedDecls.empty()) |
| 3196 | return; |
| 3197 | |
| 3198 | RecordData Record; |
| 3199 | for (ASTReader::MergedDeclsMap::iterator I = Chain->MergedDecls.begin(), |
| 3200 | IEnd = Chain->MergedDecls.end(); |
| 3201 | I != IEnd; ++I) { |
Douglas Gregor | 64af53c | 2012-01-05 22:27:05 +0000 | [diff] [blame] | 3202 | DeclID CanonID = I->first->isFromASTFile()? I->first->getGlobalID() |
Douglas Gregor | 464b0ca | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3203 | : getDeclID(I->first); |
| 3204 | assert(CanonID && "Merged declaration not known?"); |
| 3205 | |
| 3206 | Record.push_back(CanonID); |
| 3207 | Record.push_back(I->second.size()); |
| 3208 | Record.append(I->second.begin(), I->second.end()); |
| 3209 | } |
| 3210 | Stream.EmitRecord(MERGED_DECLARATIONS, Record); |
| 3211 | } |
| 3212 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3213 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3214 | // General Serialization Routines |
| 3215 | //===----------------------------------------------------------------------===// |
| 3216 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3217 | /// \brief Write a record containing the given attributes. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3218 | void ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, |
| 3219 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3220 | Record.push_back(Attrs.size()); |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3221 | for (ArrayRef<const Attr *>::iterator i = Attrs.begin(), |
| 3222 | e = Attrs.end(); i != e; ++i){ |
| 3223 | const Attr *A = *i; |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3224 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 309b4c4 | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 3225 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3226 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3227 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3228 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3229 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3230 | } |
| 3231 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3232 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3233 | Record.push_back(Str.size()); |
| 3234 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 3235 | } |
| 3236 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3237 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 3238 | RecordDataImpl &Record) { |
| 3239 | Record.push_back(Version.getMajor()); |
| 3240 | if (llvm::Optional<unsigned> Minor = Version.getMinor()) |
| 3241 | Record.push_back(*Minor + 1); |
| 3242 | else |
| 3243 | Record.push_back(0); |
| 3244 | if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) |
| 3245 | Record.push_back(*Subminor + 1); |
| 3246 | else |
| 3247 | Record.push_back(0); |
| 3248 | } |
| 3249 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3250 | /// \brief Note that the identifier II occurs at the given offset |
| 3251 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3252 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3253 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3254 | // 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] | 3255 | // up earlier in the chain and thus don't need an offset. |
| 3256 | if (ID >= FirstIdentID) |
| 3257 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3260 | /// \brief Note that the selector Sel occurs at the given offset |
| 3261 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3262 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3263 | unsigned ID = SelectorIDs[Sel]; |
| 3264 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3265 | // Don't record offsets for selectors that are also available in a different |
| 3266 | // file. |
| 3267 | if (ID < FirstSelectorID) |
| 3268 | return; |
| 3269 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3272 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3273 | : Stream(Stream), Context(0), PP(0), Chain(0), WritingModule(0), |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3274 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 3275 | ASTHasCompilerErrors(false), |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3276 | FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3277 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3278 | FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), |
| 3279 | FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID), |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3280 | FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
| 3281 | NextSubmoduleID(FirstSubmoduleID), |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3282 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3283 | CollectedStmts(&StmtsToEmit), |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3284 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3285 | NumVisibleDeclContexts(0), |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3286 | NextCXXBaseSpecifiersID(1), |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3287 | DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3288 | DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), |
| 3289 | DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), |
| 3290 | DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3291 | DeclTypedefAbbrev(0), |
| 3292 | DeclVarAbbrev(0), DeclFieldAbbrev(0), |
| 3293 | DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3294 | { |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3295 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3296 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3297 | ASTWriter::~ASTWriter() { |
| 3298 | for (FileDeclIDsTy::iterator |
| 3299 | I = FileDeclIDs.begin(), E = FileDeclIDs.end(); I != E; ++I) |
| 3300 | delete I->second; |
| 3301 | } |
| 3302 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3303 | void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 3304 | const std::string &OutputFile, |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3305 | Module *WritingModule, StringRef isysroot, |
| 3306 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3307 | WritingAST = true; |
| 3308 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3309 | ASTHasCompilerErrors = hasErrors; |
| 3310 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3311 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3312 | Stream.Emit((unsigned)'C', 8); |
| 3313 | Stream.Emit((unsigned)'P', 8); |
| 3314 | Stream.Emit((unsigned)'C', 8); |
| 3315 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 3317 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3318 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3319 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3320 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3321 | this->WritingModule = WritingModule; |
Douglas Gregor | f7a700fd | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3322 | WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile, WritingModule); |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3323 | Context = 0; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3324 | PP = 0; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3325 | this->WritingModule = 0; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3326 | |
| 3327 | WritingAST = false; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3330 | template<typename Vector> |
| 3331 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 3332 | ASTWriter::RecordData &Record) { |
| 3333 | for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end(); |
| 3334 | I != E; ++I) { |
| 3335 | Writer.AddDeclRef(*I, Record); |
| 3336 | } |
| 3337 | } |
| 3338 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3339 | void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3340 | StringRef isysroot, |
Douglas Gregor | f7a700fd | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3341 | const std::string &OutputFile, |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3342 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3343 | using namespace llvm; |
| 3344 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3345 | // Make sure that the AST reader knows to finalize itself. |
| 3346 | if (Chain) |
| 3347 | Chain->finalizeForWriting(); |
| 3348 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3349 | ASTContext &Context = SemaRef.Context; |
| 3350 | Preprocessor &PP = SemaRef.PP; |
| 3351 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3352 | // Set up predefined declaration IDs. |
| 3353 | DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; |
Douglas Gregor | 3ea7269 | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 3354 | if (Context.ObjCIdDecl) |
| 3355 | DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID; |
Douglas Gregor | 52e0280 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 3356 | if (Context.ObjCSelDecl) |
| 3357 | DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 3358 | if (Context.ObjCClassDecl) |
| 3359 | DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; |
Douglas Gregor | d53ae83 | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 3360 | if (Context.ObjCProtocolClassDecl) |
| 3361 | DeclIDs[Context.ObjCProtocolClassDecl] = PREDEF_DECL_OBJC_PROTOCOL_ID; |
Douglas Gregor | 801c99d | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 3362 | if (Context.Int128Decl) |
| 3363 | DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; |
| 3364 | if (Context.UInt128Decl) |
| 3365 | DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; |
Douglas Gregor | bab8a96 | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 3366 | if (Context.ObjCInstanceTypeDecl) |
| 3367 | DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID; |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 3368 | if (Context.BuiltinVaListDecl) |
| 3369 | DeclIDs[Context.getBuiltinVaListDecl()] = PREDEF_DECL_BUILTIN_VA_LIST_ID; |
| 3370 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3371 | if (!Chain) { |
| 3372 | // Make sure that we emit IdentifierInfos (and any attached |
| 3373 | // declarations) for builtins. We don't need to do this when we're |
| 3374 | // emitting chained PCH files, because all of the builtins will be |
| 3375 | // in the original PCH file. |
| 3376 | // FIXME: Modules won't like this at all. |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3377 | IdentifierTable &Table = PP.getIdentifierTable(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3378 | SmallVector<const char *, 32> BuiltinNames; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3379 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3380 | Context.getLangOpts().NoBuiltin); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3381 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 3382 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 3383 | } |
| 3384 | |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3385 | // If there are any out-of-date identifiers, bring them up to date. |
| 3386 | if (ExternalPreprocessorSource *ExtSource = PP.getExternalSource()) { |
| 3387 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 3388 | IDEnd = PP.getIdentifierTable().end(); |
| 3389 | ID != IDEnd; ++ID) |
| 3390 | if (ID->second->isOutOfDate()) |
| 3391 | ExtSource->updateOutOfDateIdentifier(*ID->second); |
| 3392 | } |
| 3393 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3394 | // 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] | 3395 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3396 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3397 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3398 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 3399 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3400 | // Build a record containing all of the file scoped decls in this file. |
| 3401 | RecordData UnusedFileScopedDecls; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3402 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 3403 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3404 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3405 | // Build a record containing all of the delegating constructors we still need |
| 3406 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3407 | RecordData DelegatingCtorDecls; |
Douglas Gregor | bae3120 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 3408 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3410 | // Write the set of weak, undeclared identifiers. We always write the |
| 3411 | // entire table, since later PCH files in a PCH chain are only interested in |
| 3412 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3413 | RecordData WeakUndeclaredIdentifiers; |
| 3414 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 3415 | for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3416 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 3417 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 3418 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 3419 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 3420 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 3421 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 3422 | } |
| 3423 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3424 | |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3425 | // Build a record containing all of the locally-scoped external |
| 3426 | // declarations in this header file. Generally, this record will be |
| 3427 | // empty. |
| 3428 | RecordData LocallyScopedExternalDecls; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3429 | // 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] | 3430 | // nondeterminstic! |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3431 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3432 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 3433 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3434 | TD != TDEnd; ++TD) { |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3435 | if (!TD->second->isFromASTFile()) |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3436 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 3437 | } |
| 3438 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3439 | // Build a record containing all of the ext_vector declarations. |
| 3440 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 3441 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3442 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3443 | // Build a record containing all of the VTable uses information. |
| 3444 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3445 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3446 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 3447 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 3448 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 3449 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 3450 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | // Build a record containing all of dynamic classes declarations. |
| 3454 | RecordData DynamicClasses; |
Douglas Gregor | 3200219 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 3455 | AddLazyVectorDecls(*this, SemaRef.DynamicClasses, DynamicClasses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3456 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3457 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3458 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3459 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3460 | I = SemaRef.PendingInstantiations.begin(), |
| 3461 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 3462 | AddDeclRef(I->first, PendingInstantiations); |
| 3463 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3464 | } |
| 3465 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 3466 | "There are local ones at end of translation unit!"); |
| 3467 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3468 | // Build a record containing some declaration references. |
| 3469 | RecordData SemaDeclRefs; |
| 3470 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 3471 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 3472 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 3473 | } |
| 3474 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3475 | RecordData CUDASpecialDeclRefs; |
| 3476 | if (Context.getcudaConfigureCallDecl()) { |
| 3477 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 3478 | } |
| 3479 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3480 | // Build a record containing all of the known namespaces. |
| 3481 | RecordData KnownNamespaces; |
| 3482 | for (llvm::DenseMap<NamespaceDecl*, bool>::iterator |
| 3483 | I = SemaRef.KnownNamespaces.begin(), |
| 3484 | IEnd = SemaRef.KnownNamespaces.end(); |
| 3485 | I != IEnd; ++I) { |
| 3486 | if (!I->second) |
| 3487 | AddDeclRef(I->first, KnownNamespaces); |
| 3488 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3489 | |
| 3490 | // Write the control block |
| 3491 | WriteControlBlock(Context, isysroot, OutputFile); |
| 3492 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3493 | // Write the remaining AST contents. |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3494 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3495 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3496 | if (StatCalls && isysroot.empty()) |
Douglas Gregor | 11cfd94 | 2010-07-12 23:48:14 +0000 | [diff] [blame] | 3497 | WriteStatCache(*StatCalls); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3498 | |
| 3499 | // Create a lexical update block containing all of the declarations in the |
| 3500 | // translation unit that do not come from other AST files. |
| 3501 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
| 3502 | SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
| 3503 | for (DeclContext::decl_iterator I = TU->noload_decls_begin(), |
| 3504 | E = TU->noload_decls_end(); |
| 3505 | I != E; ++I) { |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3506 | if (!(*I)->isFromASTFile()) |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3507 | NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 3511 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 3512 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3513 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 3514 | Record.clear(); |
| 3515 | Record.push_back(TU_UPDATE_LEXICAL); |
| 3516 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 3517 | data(NewGlobalDecls)); |
| 3518 | |
| 3519 | // And a visible updates block for the translation unit. |
| 3520 | Abv = new llvm::BitCodeAbbrev(); |
| 3521 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 3522 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3523 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 3524 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3525 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 3526 | WriteDeclContextVisibleUpdate(TU); |
| 3527 | |
| 3528 | // If the translation unit has an anonymous namespace, and we don't already |
| 3529 | // have an update block for it, write it as an update block. |
| 3530 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 3531 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
| 3532 | if (Record.empty()) { |
| 3533 | Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3534 | Record.push_back(reinterpret_cast<uint64_t>(NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3535 | } |
| 3536 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3537 | |
| 3538 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 3539 | // an AST file, are registered for serialization. |
| 3540 | for (SmallVector<const Decl *, 16>::iterator |
| 3541 | I = UpdatingVisibleDecls.begin(), |
| 3542 | E = UpdatingVisibleDecls.end(); I != E; ++I) { |
| 3543 | GetDeclRef(*I); |
| 3544 | } |
| 3545 | |
Argyrios Kyrtzidis | 09c1b3d | 2011-11-14 04:52:24 +0000 | [diff] [blame] | 3546 | // Resolve any declaration pointers within the declaration updates block. |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3547 | ResolveDeclUpdatesBlocks(); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3548 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3549 | // Form the record of special types. |
| 3550 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3551 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3552 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 3553 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 3554 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 3555 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 3556 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3557 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 3558 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3559 | |
Douglas Gregor | 1970d88 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3560 | // Keep writing types and declarations until all types and |
| 3561 | // declarations have been written. |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3562 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3563 | WriteDeclsBlockAbbrevs(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3564 | for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), |
| 3565 | E = DeclsToRewrite.end(); |
| 3566 | I != E; ++I) |
| 3567 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3568 | while (!DeclTypesToEmit.empty()) { |
| 3569 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 3570 | DeclTypesToEmit.pop(); |
| 3571 | if (DOT.isType()) |
| 3572 | WriteType(DOT.getType()); |
| 3573 | else |
| 3574 | WriteDecl(Context, DOT.getDecl()); |
| 3575 | } |
| 3576 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3577 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3578 | DoneWritingDeclsAndTypes = true; |
| 3579 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3580 | WriteFileDeclIDsMap(); |
| 3581 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3582 | WriteComments(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3583 | |
| 3584 | if (Chain) { |
| 3585 | // Write the mapping information describing our module dependencies and how |
| 3586 | // each of those modules were mapped into our own offset/ID space, so that |
| 3587 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 3588 | // The map consists solely of a blob with the following format: |
| 3589 | // *(module-name-len:i16 module-name:len*i8 |
| 3590 | // source-location-offset:i32 |
| 3591 | // identifier-id:i32 |
| 3592 | // preprocessed-entity-id:i32 |
| 3593 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3594 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3595 | // selector-id:i32 |
| 3596 | // declaration-id:i32 |
| 3597 | // c++-base-specifiers-id:i32 |
| 3598 | // type-id:i32) |
| 3599 | // |
| 3600 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3601 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 3602 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3603 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3604 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3605 | { |
| 3606 | llvm::raw_svector_ostream Out(Buffer); |
| 3607 | for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3608 | MEnd = Chain->ModuleMgr.end(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3609 | M != MEnd; ++M) { |
| 3610 | StringRef FileName = (*M)->FileName; |
| 3611 | io::Emit16(Out, FileName.size()); |
| 3612 | Out.write(FileName.data(), FileName.size()); |
| 3613 | io::Emit32(Out, (*M)->SLocEntryBaseOffset); |
| 3614 | io::Emit32(Out, (*M)->BaseIdentifierID); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3615 | io::Emit32(Out, (*M)->BaseMacroID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3616 | io::Emit32(Out, (*M)->BasePreprocessedEntityID); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3617 | io::Emit32(Out, (*M)->BaseSubmoduleID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3618 | io::Emit32(Out, (*M)->BaseSelectorID); |
| 3619 | io::Emit32(Out, (*M)->BaseDeclID); |
| 3620 | io::Emit32(Out, (*M)->BaseTypeIndex); |
| 3621 | } |
| 3622 | } |
| 3623 | Record.clear(); |
| 3624 | Record.push_back(MODULE_OFFSET_MAP); |
| 3625 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 3626 | Buffer.data(), Buffer.size()); |
| 3627 | } |
Douglas Gregor | f7a700fd | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3628 | WritePreprocessor(PP, WritingModule != 0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3629 | WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3630 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3631 | WriteReferencedSelectorsPool(SemaRef); |
Douglas Gregor | f7a700fd | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3632 | WriteIdentifierTable(PP, SemaRef.IdResolver, WritingModule != 0); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3633 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 3634 | WriteOpenCLExtensions(SemaRef); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3635 | |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3636 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3637 | WritePragmaDiagnosticMappings(Context.getDiagnostics()); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3638 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 3639 | WriteCXXBaseSpecifiersOffsets(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3640 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3641 | // If we're emitting a module, write out the submodule information. |
| 3642 | if (WritingModule) |
| 3643 | WriteSubmodules(WritingModule); |
| 3644 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3645 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 3646 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3647 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3648 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3649 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3650 | |
| 3651 | // Write the record containing tentative definitions. |
| 3652 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3653 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3654 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3655 | // Write the record containing unused file scoped decls. |
| 3656 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3657 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3658 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3659 | // Write the record containing weak undeclared identifiers. |
| 3660 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3661 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3662 | WeakUndeclaredIdentifiers); |
| 3663 | |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3664 | // Write the record containing locally-scoped external definitions. |
| 3665 | if (!LocallyScopedExternalDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3666 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3667 | LocallyScopedExternalDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3668 | |
| 3669 | // Write the record containing ext_vector type names. |
| 3670 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3671 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3673 | // Write the record containing VTable uses information. |
| 3674 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3675 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3676 | |
| 3677 | // Write the record containing dynamic classes declarations. |
| 3678 | if (!DynamicClasses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3679 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3680 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3681 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3682 | if (!PendingInstantiations.empty()) |
| 3683 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3684 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3685 | // Write the record containing declaration references of Sema. |
| 3686 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3687 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3688 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3689 | // Write the record containing CUDA-specific declaration references. |
| 3690 | if (!CUDASpecialDeclRefs.empty()) |
| 3691 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3692 | |
| 3693 | // Write the delegating constructors. |
| 3694 | if (!DelegatingCtorDecls.empty()) |
| 3695 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3696 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3697 | // Write the known namespaces. |
| 3698 | if (!KnownNamespaces.empty()) |
| 3699 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
| 3700 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3701 | // Write the visible updates to DeclContexts. |
| 3702 | for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |
| 3703 | I = UpdatedDeclContexts.begin(), |
| 3704 | E = UpdatedDeclContexts.end(); |
| 3705 | I != E; ++I) |
| 3706 | WriteDeclContextVisibleUpdate(*I); |
| 3707 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 3708 | if (!WritingModule) { |
| 3709 | // Write the submodules that were imported, if any. |
| 3710 | RecordData ImportedModules; |
| 3711 | for (ASTContext::import_iterator I = Context.local_import_begin(), |
| 3712 | IEnd = Context.local_import_end(); |
| 3713 | I != IEnd; ++I) { |
| 3714 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
| 3715 | ImportedModules.push_back(SubmoduleIDs[I->getImportedModule()]); |
| 3716 | } |
| 3717 | if (!ImportedModules.empty()) { |
| 3718 | // Sort module IDs. |
| 3719 | llvm::array_pod_sort(ImportedModules.begin(), ImportedModules.end()); |
| 3720 | |
| 3721 | // Unique module IDs. |
| 3722 | ImportedModules.erase(std::unique(ImportedModules.begin(), |
| 3723 | ImportedModules.end()), |
| 3724 | ImportedModules.end()); |
| 3725 | |
| 3726 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 3727 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 3728 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3729 | |
| 3730 | WriteMacroUpdates(); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3731 | WriteDeclUpdatesBlocks(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3732 | WriteDeclReplacementsBlock(); |
Douglas Gregor | 464b0ca | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3733 | WriteMergedDecls(); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3734 | WriteRedeclarations(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3735 | WriteObjCCategories(); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3736 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3737 | // Some simple statistics |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3738 | Record.clear(); |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3739 | Record.push_back(NumStatements); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 3740 | Record.push_back(NumMacros); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3741 | Record.push_back(NumLexicalDeclContexts); |
| 3742 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3743 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3744 | Stream.ExitBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3745 | } |
| 3746 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3747 | void ASTWriter::WriteMacroUpdates() { |
| 3748 | if (MacroUpdates.empty()) |
| 3749 | return; |
| 3750 | |
| 3751 | RecordData Record; |
| 3752 | for (MacroUpdatesMap::iterator I = MacroUpdates.begin(), |
| 3753 | E = MacroUpdates.end(); |
| 3754 | I != E; ++I) { |
| 3755 | addMacroRef(I->first, Record); |
| 3756 | AddSourceLocation(I->second.UndefLoc, Record); |
Douglas Gregor | cfa46a8 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 3757 | Record.push_back(inferSubmoduleIDFromLocation(I->second.UndefLoc)); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3758 | } |
| 3759 | Stream.EmitRecord(MACRO_UPDATES, Record); |
| 3760 | } |
| 3761 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3762 | /// \brief Go through the declaration update blocks and resolve declaration |
| 3763 | /// pointers into declaration IDs. |
| 3764 | void ASTWriter::ResolveDeclUpdatesBlocks() { |
| 3765 | for (DeclUpdateMap::iterator |
| 3766 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3767 | const Decl *D = I->first; |
| 3768 | UpdateRecord &URec = I->second; |
| 3769 | |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3770 | if (isRewritten(D)) |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3771 | continue; // The decl will be written completely |
| 3772 | |
| 3773 | unsigned Idx = 0, N = URec.size(); |
| 3774 | while (Idx < N) { |
| 3775 | switch ((DeclUpdateKind)URec[Idx++]) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3776 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 3777 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 3778 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
| 3779 | URec[Idx] = GetDeclRef(reinterpret_cast<Decl *>(URec[Idx])); |
| 3780 | ++Idx; |
| 3781 | break; |
| 3782 | |
| 3783 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
| 3784 | ++Idx; |
| 3785 | break; |
| 3786 | } |
| 3787 | } |
| 3788 | } |
| 3789 | } |
| 3790 | |
Argyrios Kyrtzidis | 97bfda9 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3791 | void ASTWriter::WriteDeclUpdatesBlocks() { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3792 | if (DeclUpdates.empty()) |
| 3793 | return; |
| 3794 | |
| 3795 | RecordData OffsetsRecord; |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3796 | Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3797 | for (DeclUpdateMap::iterator |
| 3798 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3799 | const Decl *D = I->first; |
| 3800 | UpdateRecord &URec = I->second; |
| 3801 | |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3802 | if (isRewritten(D)) |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 3803 | continue; // The decl will be written completely,no need to store updates. |
| 3804 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3805 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 3806 | Stream.EmitRecord(DECL_UPDATES, URec); |
| 3807 | |
| 3808 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 3809 | OffsetsRecord.push_back(Offset); |
| 3810 | } |
| 3811 | Stream.ExitBlock(); |
| 3812 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); |
| 3813 | } |
| 3814 | |
Argyrios Kyrtzidis | 97bfda9 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3815 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3816 | if (ReplacedDecls.empty()) |
| 3817 | return; |
| 3818 | |
| 3819 | RecordData Record; |
Argyrios Kyrtzidis | 6fb6003 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 3820 | for (SmallVector<ReplacedDeclInfo, 16>::iterator |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3821 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
Argyrios Kyrtzidis | 6fb6003 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 3822 | Record.push_back(I->ID); |
| 3823 | Record.push_back(I->Offset); |
| 3824 | Record.push_back(I->Loc); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3825 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3826 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3827 | } |
| 3828 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3829 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3830 | Record.push_back(Loc.getRawEncoding()); |
| 3831 | } |
| 3832 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3833 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3834 | AddSourceLocation(Range.getBegin(), Record); |
| 3835 | AddSourceLocation(Range.getEnd(), Record); |
| 3836 | } |
| 3837 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3838 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3839 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3840 | const uint64_t *Words = Value.getRawData(); |
| 3841 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3844 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3845 | Record.push_back(Value.isUnsigned()); |
| 3846 | AddAPInt(Value, Record); |
| 3847 | } |
| 3848 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3849 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 3850 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 3851 | } |
| 3852 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3853 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3854 | Record.push_back(getIdentifierRef(II)); |
| 3855 | } |
| 3856 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3857 | void ASTWriter::addMacroRef(MacroInfo *MI, RecordDataImpl &Record) { |
| 3858 | Record.push_back(getMacroRef(MI)); |
| 3859 | } |
| 3860 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3861 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3862 | if (II == 0) |
| 3863 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3864 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3865 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3866 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3867 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3868 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3871 | MacroID ASTWriter::getMacroRef(MacroInfo *MI) { |
| 3872 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 3873 | // have been redefined by the header (in which case they are not |
| 3874 | // isBuiltinMacro). |
| 3875 | if (MI == 0 || MI->isBuiltinMacro()) |
| 3876 | return 0; |
| 3877 | |
| 3878 | MacroID &ID = MacroIDs[MI]; |
| 3879 | if (ID == 0) |
| 3880 | ID = NextMacroID++; |
| 3881 | return ID; |
| 3882 | } |
| 3883 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3884 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3885 | Record.push_back(getSelectorRef(SelRef)); |
| 3886 | } |
| 3887 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3888 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3889 | if (Sel.getAsOpaquePtr() == 0) { |
| 3890 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3893 | SelectorID &SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3894 | if (SID == 0 && Chain) { |
| 3895 | // This might trigger a ReadSelector callback, which will set the ID for |
| 3896 | // this selector. |
| 3897 | Chain->LoadSelector(Sel); |
| 3898 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3899 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3900 | SID = NextSelectorID++; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3901 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3902 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3905 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 3906 | AddDeclRef(Temp->getDestructor(), Record); |
| 3907 | } |
| 3908 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3909 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
| 3910 | CXXBaseSpecifier const *BasesEnd, |
| 3911 | RecordDataImpl &Record) { |
| 3912 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 3913 | CXXBaseSpecifiersToWrite.push_back( |
| 3914 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 3915 | Bases, BasesEnd)); |
| 3916 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 3917 | } |
| 3918 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3919 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3920 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3921 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3922 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3923 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3924 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3925 | break; |
| 3926 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3927 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3928 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3929 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3930 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3931 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3932 | break; |
| 3933 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3934 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3935 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3936 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3937 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3938 | case TemplateArgument::Null: |
| 3939 | case TemplateArgument::Integral: |
| 3940 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3941 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3942 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3943 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3944 | break; |
| 3945 | } |
| 3946 | } |
| 3947 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3948 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3949 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3950 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3951 | |
| 3952 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 3953 | bool InfoHasSameExpr |
| 3954 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 3955 | Record.push_back(InfoHasSameExpr); |
| 3956 | if (InfoHasSameExpr) |
| 3957 | return; // Avoid storing the same expr twice. |
| 3958 | } |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3959 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 3960 | Record); |
| 3961 | } |
| 3962 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3963 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 3964 | RecordDataImpl &Record) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3965 | if (TInfo == 0) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3966 | AddTypeRef(QualType(), Record); |
| 3967 | return; |
| 3968 | } |
| 3969 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3970 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 3971 | } |
| 3972 | |
| 3973 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 3974 | AddTypeRef(TL.getType(), Record); |
| 3975 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3976 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3977 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3978 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3979 | } |
| 3980 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3981 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 3982 | Record.push_back(GetOrCreateTypeID(T)); |
| 3983 | } |
| 3984 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3985 | TypeID ASTWriter::GetOrCreateTypeID( QualType T) { |
| 3986 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3987 | std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); |
| 3988 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3989 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3990 | TypeID ASTWriter::getTypeID(QualType T) const { |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3991 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3992 | std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); |
Argyrios Kyrtzidis | e394f2c | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3993 | } |
| 3994 | |
| 3995 | TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { |
| 3996 | if (T.isNull()) |
| 3997 | return TypeIdx(); |
| 3998 | assert(!T.getLocalFastQualifiers()); |
| 3999 | |
Argyrios Kyrtzidis | a7fbbb0 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 4000 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4001 | if (Idx.getIndex() == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4002 | if (DoneWritingDeclsAndTypes) { |
| 4003 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 4004 | return TypeIdx(); |
| 4005 | } |
| 4006 | |
Douglas Gregor | 1970d88 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 4007 | // 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] | 4008 | // into the queue of types to emit. |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4009 | Idx = TypeIdx(NextTypeID++); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4010 | DeclTypesToEmit.push(T); |
Douglas Gregor | 1970d88 | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 4011 | } |
Argyrios Kyrtzidis | e394f2c | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 4012 | return Idx; |
| 4013 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4014 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4015 | TypeIdx ASTWriter::getTypeIdx(QualType T) const { |
Argyrios Kyrtzidis | e394f2c | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 4016 | if (T.isNull()) |
| 4017 | return TypeIdx(); |
| 4018 | assert(!T.getLocalFastQualifiers()); |
| 4019 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4020 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 4021 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 4022 | return I->second; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4023 | } |
| 4024 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4025 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4026 | Record.push_back(GetDeclRef(D)); |
| 4027 | } |
| 4028 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4029 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4030 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
| 4031 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4032 | if (D == 0) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4033 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4034 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4035 | |
| 4036 | // If D comes from an AST file, its declaration ID is already known and |
| 4037 | // fixed. |
| 4038 | if (D->isFromASTFile()) |
| 4039 | return D->getGlobalID(); |
| 4040 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4041 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4042 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4043 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4044 | if (DoneWritingDeclsAndTypes) { |
| 4045 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4049 | // We haven't seen this declaration before. Give it a new ID and |
| 4050 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4051 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4052 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4053 | } |
| 4054 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4055 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4056 | } |
| 4057 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4058 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4059 | if (D == 0) |
| 4060 | return 0; |
| 4061 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4062 | // If D comes from an AST file, its declaration ID is already known and |
| 4063 | // fixed. |
| 4064 | if (D->isFromASTFile()) |
| 4065 | return D->getGlobalID(); |
| 4066 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4067 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 4068 | return DeclIDs[D]; |
| 4069 | } |
| 4070 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4071 | static inline bool compLocDecl(std::pair<unsigned, serialization::DeclID> L, |
| 4072 | std::pair<unsigned, serialization::DeclID> R) { |
| 4073 | return L.first < R.first; |
| 4074 | } |
| 4075 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4076 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4077 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4078 | assert(D); |
| 4079 | |
| 4080 | SourceLocation Loc = D->getLocation(); |
| 4081 | if (Loc.isInvalid()) |
| 4082 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4083 | |
| 4084 | // We only keep track of the file-level declarations of each file. |
| 4085 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 4086 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 4087 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 4088 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 4089 | if (isa<ParmVarDecl>(D)) |
| 4090 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4091 | |
| 4092 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4093 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4094 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4095 | FileID FID; |
| 4096 | unsigned Offset; |
| 4097 | llvm::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4098 | if (FID.isInvalid()) |
| 4099 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4100 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4101 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4102 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4103 | if (!Info) |
| 4104 | Info = new DeclIDInFileInfo(); |
| 4105 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4106 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4107 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 4108 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4109 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4110 | Decls.push_back(LocDecl); |
| 4111 | return; |
| 4112 | } |
| 4113 | |
| 4114 | LocDeclIDsTy::iterator |
| 4115 | I = std::upper_bound(Decls.begin(), Decls.end(), LocDecl, compLocDecl); |
| 4116 | |
| 4117 | Decls.insert(I, LocDecl); |
| 4118 | } |
| 4119 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4120 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 4121 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4122 | Record.push_back(Name.getNameKind()); |
| 4123 | switch (Name.getNameKind()) { |
| 4124 | case DeclarationName::Identifier: |
| 4125 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 4126 | break; |
| 4127 | |
| 4128 | case DeclarationName::ObjCZeroArgSelector: |
| 4129 | case DeclarationName::ObjCOneArgSelector: |
| 4130 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4131 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4132 | break; |
| 4133 | |
| 4134 | case DeclarationName::CXXConstructorName: |
| 4135 | case DeclarationName::CXXDestructorName: |
| 4136 | case DeclarationName::CXXConversionFunctionName: |
| 4137 | AddTypeRef(Name.getCXXNameType(), Record); |
| 4138 | break; |
| 4139 | |
| 4140 | case DeclarationName::CXXOperatorName: |
| 4141 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 4142 | break; |
| 4143 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4144 | case DeclarationName::CXXLiteralOperatorName: |
| 4145 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 4146 | break; |
| 4147 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4148 | case DeclarationName::CXXUsingDirective: |
| 4149 | // No extra data to emit |
| 4150 | break; |
| 4151 | } |
| 4152 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4153 | |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4154 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4155 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4156 | switch (Name.getNameKind()) { |
| 4157 | case DeclarationName::CXXConstructorName: |
| 4158 | case DeclarationName::CXXDestructorName: |
| 4159 | case DeclarationName::CXXConversionFunctionName: |
| 4160 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 4161 | break; |
| 4162 | |
| 4163 | case DeclarationName::CXXOperatorName: |
| 4164 | AddSourceLocation( |
| 4165 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 4166 | Record); |
| 4167 | AddSourceLocation( |
| 4168 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 4169 | Record); |
| 4170 | break; |
| 4171 | |
| 4172 | case DeclarationName::CXXLiteralOperatorName: |
| 4173 | AddSourceLocation( |
| 4174 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 4175 | Record); |
| 4176 | break; |
| 4177 | |
| 4178 | case DeclarationName::Identifier: |
| 4179 | case DeclarationName::ObjCZeroArgSelector: |
| 4180 | case DeclarationName::ObjCOneArgSelector: |
| 4181 | case DeclarationName::ObjCMultiArgSelector: |
| 4182 | case DeclarationName::CXXUsingDirective: |
| 4183 | break; |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4188 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4189 | AddDeclarationName(NameInfo.getName(), Record); |
| 4190 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 4191 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 4192 | } |
| 4193 | |
| 4194 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4195 | RecordDataImpl &Record) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4196 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4197 | Record.push_back(Info.NumTemplParamLists); |
| 4198 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 4199 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 4200 | } |
| 4201 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4202 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4203 | RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4204 | // 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] | 4205 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4206 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4207 | |
| 4208 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 4209 | while (NNS) { |
| 4210 | NestedNames.push_back(NNS); |
| 4211 | NNS = NNS->getPrefix(); |
| 4212 | } |
| 4213 | |
| 4214 | Record.push_back(NestedNames.size()); |
| 4215 | while(!NestedNames.empty()) { |
| 4216 | NNS = NestedNames.pop_back_val(); |
| 4217 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 4218 | Record.push_back(Kind); |
| 4219 | switch (Kind) { |
| 4220 | case NestedNameSpecifier::Identifier: |
| 4221 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 4222 | break; |
| 4223 | |
| 4224 | case NestedNameSpecifier::Namespace: |
| 4225 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 4226 | break; |
| 4227 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4228 | case NestedNameSpecifier::NamespaceAlias: |
| 4229 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 4230 | break; |
| 4231 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4232 | case NestedNameSpecifier::TypeSpec: |
| 4233 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4234 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 4235 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4236 | break; |
| 4237 | |
| 4238 | case NestedNameSpecifier::Global: |
| 4239 | // Don't need to write an associated value. |
| 4240 | break; |
| 4241 | } |
| 4242 | } |
| 4243 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4244 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4245 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 4246 | RecordDataImpl &Record) { |
| 4247 | // 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] | 4248 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4249 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4250 | |
| 4251 | // Push each of the nested-name-specifiers's onto a stack for |
| 4252 | // serialization in reverse order. |
| 4253 | while (NNS) { |
| 4254 | NestedNames.push_back(NNS); |
| 4255 | NNS = NNS.getPrefix(); |
| 4256 | } |
| 4257 | |
| 4258 | Record.push_back(NestedNames.size()); |
| 4259 | while(!NestedNames.empty()) { |
| 4260 | NNS = NestedNames.pop_back_val(); |
| 4261 | NestedNameSpecifier::SpecifierKind Kind |
| 4262 | = NNS.getNestedNameSpecifier()->getKind(); |
| 4263 | Record.push_back(Kind); |
| 4264 | switch (Kind) { |
| 4265 | case NestedNameSpecifier::Identifier: |
| 4266 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 4267 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4268 | break; |
| 4269 | |
| 4270 | case NestedNameSpecifier::Namespace: |
| 4271 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 4272 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4273 | break; |
| 4274 | |
| 4275 | case NestedNameSpecifier::NamespaceAlias: |
| 4276 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 4277 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4278 | break; |
| 4279 | |
| 4280 | case NestedNameSpecifier::TypeSpec: |
| 4281 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4282 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4283 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 4284 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4285 | break; |
| 4286 | |
| 4287 | case NestedNameSpecifier::Global: |
| 4288 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4289 | break; |
| 4290 | } |
| 4291 | } |
| 4292 | } |
| 4293 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4294 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4295 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4296 | Record.push_back(Kind); |
| 4297 | switch (Kind) { |
| 4298 | case TemplateName::Template: |
| 4299 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 4300 | break; |
| 4301 | |
| 4302 | case TemplateName::OverloadedTemplate: { |
| 4303 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 4304 | Record.push_back(OvT->size()); |
| 4305 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 4306 | I != E; ++I) |
| 4307 | AddDeclRef(*I, Record); |
| 4308 | break; |
| 4309 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4310 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4311 | case TemplateName::QualifiedTemplate: { |
| 4312 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 4313 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 4314 | Record.push_back(QualT->hasTemplateKeyword()); |
| 4315 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 4316 | break; |
| 4317 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4318 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4319 | case TemplateName::DependentTemplate: { |
| 4320 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 4321 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 4322 | Record.push_back(DepT->isIdentifier()); |
| 4323 | if (DepT->isIdentifier()) |
| 4324 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 4325 | else |
| 4326 | Record.push_back(DepT->getOperator()); |
| 4327 | break; |
| 4328 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4329 | |
| 4330 | case TemplateName::SubstTemplateTemplateParm: { |
| 4331 | SubstTemplateTemplateParmStorage *subst |
| 4332 | = Name.getAsSubstTemplateTemplateParm(); |
| 4333 | AddDeclRef(subst->getParameter(), Record); |
| 4334 | AddTemplateName(subst->getReplacement(), Record); |
| 4335 | break; |
| 4336 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4337 | |
| 4338 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4339 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 4340 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 4341 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 4342 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 4343 | break; |
| 4344 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4345 | } |
| 4346 | } |
| 4347 | |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4348 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4349 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4350 | Record.push_back(Arg.getKind()); |
| 4351 | switch (Arg.getKind()) { |
| 4352 | case TemplateArgument::Null: |
| 4353 | break; |
| 4354 | case TemplateArgument::Type: |
| 4355 | AddTypeRef(Arg.getAsType(), Record); |
| 4356 | break; |
| 4357 | case TemplateArgument::Declaration: |
| 4358 | AddDeclRef(Arg.getAsDecl(), Record); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4359 | Record.push_back(Arg.isDeclForReferenceParam()); |
| 4360 | break; |
| 4361 | case TemplateArgument::NullPtr: |
| 4362 | AddTypeRef(Arg.getNullPtrType(), Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4363 | break; |
| 4364 | case TemplateArgument::Integral: |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 4365 | AddAPSInt(Arg.getAsIntegral(), Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4366 | AddTypeRef(Arg.getIntegralType(), Record); |
| 4367 | break; |
| 4368 | case TemplateArgument::Template: |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4369 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 4370 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4371 | case TemplateArgument::TemplateExpansion: |
| 4372 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4373 | if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
| 4374 | Record.push_back(*NumExpansions + 1); |
| 4375 | else |
| 4376 | Record.push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4377 | break; |
| 4378 | case TemplateArgument::Expression: |
| 4379 | AddStmt(Arg.getAsExpr()); |
| 4380 | break; |
| 4381 | case TemplateArgument::Pack: |
| 4382 | Record.push_back(Arg.pack_size()); |
| 4383 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 4384 | I != E; ++I) |
| 4385 | AddTemplateArgument(*I, Record); |
| 4386 | break; |
| 4387 | } |
| 4388 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4389 | |
| 4390 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4391 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4392 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4393 | assert(TemplateParams && "No TemplateParams!"); |
| 4394 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 4395 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 4396 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 4397 | Record.push_back(TemplateParams->size()); |
| 4398 | for (TemplateParameterList::const_iterator |
| 4399 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 4400 | P != PEnd; ++P) |
| 4401 | AddDeclRef(*P, Record); |
| 4402 | } |
| 4403 | |
| 4404 | /// \brief Emit a template argument list. |
| 4405 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4406 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4407 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4408 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4409 | Record.push_back(TemplateArgs->size()); |
| 4410 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4411 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 4412 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4413 | |
| 4414 | |
| 4415 | void |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4416 | ASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4417 | Record.push_back(Set.size()); |
| 4418 | for (UnresolvedSetImpl::const_iterator |
| 4419 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 4420 | AddDeclRef(I.getDecl(), Record); |
| 4421 | Record.push_back(I.getAccess()); |
| 4422 | } |
| 4423 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4424 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4425 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4426 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4427 | Record.push_back(Base.isVirtual()); |
| 4428 | Record.push_back(Base.isBaseOfClass()); |
| 4429 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4430 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4431 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4432 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4433 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 4434 | : SourceLocation(), |
| 4435 | Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4436 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4437 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4438 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 4439 | RecordData Record; |
| 4440 | for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { |
| 4441 | Record.clear(); |
| 4442 | |
| 4443 | // Record the offset of this base-specifier set. |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4444 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4445 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 4446 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 4447 | else { |
| 4448 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 4449 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 4450 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 4451 | } |
| 4452 | |
| 4453 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 4454 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 4455 | Record.push_back(BEnd - B); |
| 4456 | for (; B != BEnd; ++B) |
| 4457 | AddCXXBaseSpecifier(*B, Record); |
| 4458 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | d585304 | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 4459 | |
| 4460 | // Flush any expressions that were written as part of the base specifiers. |
| 4461 | FlushStmts(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | CXXBaseSpecifiersToWrite.clear(); |
| 4465 | } |
| 4466 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4467 | void ASTWriter::AddCXXCtorInitializers( |
| 4468 | const CXXCtorInitializer * const *CtorInitializers, |
| 4469 | unsigned NumCtorInitializers, |
| 4470 | RecordDataImpl &Record) { |
| 4471 | Record.push_back(NumCtorInitializers); |
| 4472 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 4473 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4474 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4475 | if (Init->isBaseInitializer()) { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4476 | Record.push_back(CTOR_INITIALIZER_BASE); |
Douglas Gregor | d73f3dd | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4477 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4478 | Record.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4479 | } else if (Init->isDelegatingInitializer()) { |
| 4480 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
Douglas Gregor | d73f3dd | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4481 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4482 | } else if (Init->isMemberInitializer()){ |
| 4483 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 4484 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4485 | } else { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4486 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 4487 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4488 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4489 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4490 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 4491 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4492 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 4493 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 4494 | Record.push_back(Init->isWritten()); |
| 4495 | if (Init->isWritten()) { |
| 4496 | Record.push_back(Init->getSourceOrder()); |
| 4497 | } else { |
| 4498 | Record.push_back(Init->getNumArrayIndices()); |
| 4499 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 4500 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 4501 | } |
| 4502 | } |
| 4503 | } |
| 4504 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4505 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
| 4506 | assert(D->DefinitionData); |
| 4507 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4508 | Record.push_back(Data.IsLambda); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4509 | Record.push_back(Data.UserDeclaredConstructor); |
| 4510 | Record.push_back(Data.UserDeclaredCopyConstructor); |
Douglas Gregor | cd0d826 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4511 | Record.push_back(Data.UserDeclaredMoveConstructor); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4512 | Record.push_back(Data.UserDeclaredCopyAssignment); |
Douglas Gregor | cd0d826 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4513 | Record.push_back(Data.UserDeclaredMoveAssignment); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4514 | Record.push_back(Data.UserDeclaredDestructor); |
| 4515 | Record.push_back(Data.Aggregate); |
| 4516 | Record.push_back(Data.PlainOldData); |
| 4517 | Record.push_back(Data.Empty); |
| 4518 | Record.push_back(Data.Polymorphic); |
| 4519 | Record.push_back(Data.Abstract); |
Chandler Carruth | 583edf8 | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 4520 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | b196374 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 4521 | Record.push_back(Data.HasNoNonEmptyBases); |
| 4522 | Record.push_back(Data.HasPrivateFields); |
| 4523 | Record.push_back(Data.HasProtectedFields); |
| 4524 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 61226d3 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 4525 | Record.push_back(Data.HasMutableFields); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4526 | Record.push_back(Data.HasOnlyCMembers); |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 4527 | Record.push_back(Data.HasInClassInitializer); |
Alexis Hunt | f479f1b | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 4528 | Record.push_back(Data.HasTrivialDefaultConstructor); |
Richard Smith | 111af8d | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 4529 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4530 | Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4531 | Record.push_back(Data.HasConstexprDefaultConstructor); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4532 | Record.push_back(Data.HasTrivialCopyConstructor); |
Chandler Carruth | ad7d404 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 4533 | Record.push_back(Data.HasTrivialMoveConstructor); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4534 | Record.push_back(Data.HasTrivialCopyAssignment); |
Chandler Carruth | ad7d404 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 4535 | Record.push_back(Data.HasTrivialMoveAssignment); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4536 | Record.push_back(Data.HasTrivialDestructor); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4537 | Record.push_back(Data.HasIrrelevantDestructor); |
Chandler Carruth | e71d062 | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 4538 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4539 | Record.push_back(Data.ComputedVisibleConversions); |
Alexis Hunt | ea6f032 | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 4540 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4541 | Record.push_back(Data.DeclaredDefaultConstructor); |
| 4542 | Record.push_back(Data.DeclaredCopyConstructor); |
Douglas Gregor | cd0d826 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4543 | Record.push_back(Data.DeclaredMoveConstructor); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4544 | Record.push_back(Data.DeclaredCopyAssignment); |
Douglas Gregor | cd0d826 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4545 | Record.push_back(Data.DeclaredMoveAssignment); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4546 | Record.push_back(Data.DeclaredDestructor); |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 4547 | Record.push_back(Data.FailedImplicitMoveConstructor); |
| 4548 | Record.push_back(Data.FailedImplicitMoveAssignment); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4549 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4550 | |
| 4551 | Record.push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4552 | if (Data.NumBases > 0) |
| 4553 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 4554 | Record); |
| 4555 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4556 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 4557 | Record.push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4558 | if (Data.NumVBases > 0) |
| 4559 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 4560 | Record); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4561 | |
| 4562 | AddUnresolvedSet(Data.Conversions, Record); |
| 4563 | AddUnresolvedSet(Data.VisibleConversions, Record); |
| 4564 | // Data.Definition is the owning decl, no need to write it. |
| 4565 | AddDeclRef(Data.FirstFriend, Record); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4566 | |
| 4567 | // Add lambda-specific data. |
| 4568 | if (Data.IsLambda) { |
| 4569 | CXXRecordDecl::LambdaDefinitionData &Lambda = D->getLambdaData(); |
Douglas Gregor | 680e9e0 | 2012-02-21 19:11:17 +0000 | [diff] [blame] | 4570 | Record.push_back(Lambda.Dependent); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4571 | Record.push_back(Lambda.NumCaptures); |
| 4572 | Record.push_back(Lambda.NumExplicitCaptures); |
Douglas Gregor | 6379854 | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 4573 | Record.push_back(Lambda.ManglingNumber); |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 4574 | AddDeclRef(Lambda.ContextDecl, Record); |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 4575 | AddTypeSourceInfo(Lambda.MethodTyInfo, Record); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4576 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
| 4577 | LambdaExpr::Capture &Capture = Lambda.Captures[I]; |
| 4578 | AddSourceLocation(Capture.getLocation(), Record); |
| 4579 | Record.push_back(Capture.isImplicit()); |
| 4580 | Record.push_back(Capture.getCaptureKind()); // FIXME: stable! |
| 4581 | VarDecl *Var = Capture.capturesVariable()? Capture.getCapturedVar() : 0; |
| 4582 | AddDeclRef(Var, Record); |
| 4583 | AddSourceLocation(Capture.isPackExpansion()? Capture.getEllipsisLoc() |
| 4584 | : SourceLocation(), |
| 4585 | Record); |
| 4586 | } |
| 4587 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4588 | } |
| 4589 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4590 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4591 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4592 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4593 | assert(FirstDeclID == NextDeclID && |
| 4594 | FirstTypeID == NextTypeID && |
| 4595 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4596 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4597 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4598 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4599 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4600 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4601 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4602 | |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4603 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 4604 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 4605 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4606 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4607 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4608 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4609 | NextDeclID = FirstDeclID; |
| 4610 | NextTypeID = FirstTypeID; |
| 4611 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4612 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4613 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4614 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4615 | } |
| 4616 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4617 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4618 | IdentifierIDs[II] = ID; |
| 4619 | } |
| 4620 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4621 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
| 4622 | MacroIDs[MI] = ID; |
| 4623 | } |
| 4624 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4625 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4626 | // Always take the highest-numbered type index. This copes with an interesting |
| 4627 | // 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] | 4628 | // 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] | 4629 | // keep the higher-numbered entry so that we can properly write it out to |
| 4630 | // the AST file. |
| 4631 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 4632 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 4633 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4634 | } |
| 4635 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4636 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4637 | SelectorIDs[S] = ID; |
| 4638 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4639 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4640 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4641 | MacroDefinition *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4642 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4643 | MacroDefinitions[MD] = ID; |
| 4644 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4645 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 4646 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 4647 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 4648 | SubmoduleIDs[Mod] = ID; |
| 4649 | } |
| 4650 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4651 | void ASTWriter::UndefinedMacro(MacroInfo *MI) { |
| 4652 | MacroUpdates[MI].UndefLoc = MI->getUndefLoc(); |
| 4653 | } |
| 4654 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4655 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4656 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4657 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4658 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 4659 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4660 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4661 | // A forward reference was mutated into a definition. Rewrite it. |
| 4662 | // FIXME: This happens during template instantiation, should we |
| 4663 | // have created a new definition decl instead ? |
Argyrios Kyrtzidis | 4729972 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 4664 | RewriteDecl(RD); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4665 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4666 | } |
| 4667 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4668 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4669 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4670 | assert(!WritingAST && "Already writing the AST!"); |
| 4671 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4672 | // TU and namespaces are handled elsewhere. |
| 4673 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 4674 | return; |
| 4675 | |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4676 | if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile())) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4677 | return; // Not a source decl added to a DeclContext from PCH. |
| 4678 | |
| 4679 | AddUpdatedDeclContext(DC); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4680 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4681 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4682 | |
| 4683 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4684 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4685 | assert(D->isImplicit()); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4686 | if (!(!D->isFromASTFile() && RD->isFromASTFile())) |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4687 | return; // Not a source member added to a class from PCH. |
| 4688 | if (!isa<CXXMethodDecl>(D)) |
| 4689 | return; // We are interested in lazily declared implicit methods. |
| 4690 | |
| 4691 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4692 | assert(RD->isCompleteDefinition()); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4693 | UpdateRecord &Record = DeclUpdates[RD]; |
| 4694 | Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4695 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4696 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4697 | |
| 4698 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 4699 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | ef80a01 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4700 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4701 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | ef80a01 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4702 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4703 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4704 | return; // Not a source specialization added to a template from PCH. |
| 4705 | |
| 4706 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4707 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4708 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4709 | } |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 4710 | |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4711 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 4712 | const FunctionDecl *D) { |
| 4713 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4714 | assert(!WritingAST && "Already writing the AST!"); |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4715 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4716 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4717 | return; // Not a source specialization added to a template from PCH. |
| 4718 | |
| 4719 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4720 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4721 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4722 | } |
| 4723 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4724 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4725 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4726 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4727 | return; // Declaration not imported from PCH. |
| 4728 | |
| 4729 | // Implicit decl from a PCH was defined. |
| 4730 | // FIXME: Should implicit definition be a separate FunctionDecl? |
| 4731 | RewriteDecl(D); |
| 4732 | } |
| 4733 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4734 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4735 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4736 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4737 | return; |
| 4738 | |
| 4739 | // Since the actual instantiation is delayed, this really means that we need |
| 4740 | // to update the instantiation location. |
| 4741 | UpdateRecord &Record = DeclUpdates[D]; |
| 4742 | Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); |
| 4743 | AddSourceLocation( |
| 4744 | D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); |
| 4745 | } |
| 4746 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4747 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 4748 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4749 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4750 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4751 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4752 | |
| 4753 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 4754 | ObjCClassesWithCategories.insert( |
| 4755 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4756 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 4757 | |
Argyrios Kyrtzidis | 0ca3a8b | 2011-11-12 21:07:52 +0000 | [diff] [blame] | 4758 | |
Argyrios Kyrtzidis | 846e61a | 2011-11-14 04:52:29 +0000 | [diff] [blame] | 4759 | void ASTWriter::AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, |
| 4760 | const ObjCPropertyDecl *OrigProp, |
| 4761 | const ObjCCategoryDecl *ClassExt) { |
| 4762 | const ObjCInterfaceDecl *D = ClassExt->getClassInterface(); |
| 4763 | if (!D) |
| 4764 | return; |
| 4765 | |
| 4766 | assert(!WritingAST && "Already writing the AST!"); |
| 4767 | if (!D->isFromASTFile()) |
| 4768 | return; // Declaration not imported from PCH. |
| 4769 | |
| 4770 | RewriteDecl(D); |
| 4771 | } |