Sebastian Redl | 4ee2ad0 | 2010-08-18 23:56:31 +0000 | [diff] [blame] | 1 | //===--- ASTWriter.cpp - AST File Writer ----------------------------------===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 10 | // This file defines the ASTWriter class, which writes AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sebastian Redl | 7faa2ec | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTWriter.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 16 | #include "clang/Sema/Sema.h" |
| 17 | #include "clang/Sema/IdentifierResolver.h" |
Douglas Gregor | 2cf2634 | 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 | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclTemplate.h" |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclFriend.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 23 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 24 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 25 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocVisitor.h" |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 27 | #include "clang/Serialization/ASTReader.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 28 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 29 | #include "clang/Lex/PreprocessingRecord.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 31 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 33 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 34 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 37 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 38 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 39 | #include "clang/Basic/VersionTuple.h" |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 40 | #include "llvm/ADT/APFloat.h" |
| 41 | #include "llvm/ADT/APInt.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include "llvm/Bitcode/BitstreamWriter.h" |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 44 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 45 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Path.h" |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 47 | #include <algorithm> |
Chris Lattner | 3c304bd | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 48 | #include <cstdio> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 49 | #include <string.h> |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 50 | #include <utility> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 51 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 52 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 53 | |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 54 | template <typename T, typename Allocator> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 55 | static StringRef data(const std::vector<T, Allocator> &v) { |
| 56 | if (v.empty()) return StringRef(); |
| 57 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 58 | sizeof(T) * v.size()); |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 59 | } |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 60 | |
| 61 | template <typename T> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 62 | static StringRef data(const SmallVectorImpl<T> &v) { |
| 63 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 64 | sizeof(T) * v.size()); |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 67 | //===----------------------------------------------------------------------===// |
| 68 | // Type serialization |
| 69 | //===----------------------------------------------------------------------===// |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 70 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 71 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 72 | class ASTTypeWriter { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 73 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 74 | ASTWriter::RecordDataImpl &Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 75 | |
| 76 | public: |
| 77 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 78 | TypeCode Code; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 79 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 80 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 81 | : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 82 | |
| 83 | void VisitArrayType(const ArrayType *T); |
| 84 | void VisitFunctionType(const FunctionType *T); |
| 85 | void VisitTagType(const TagType *T); |
| 86 | |
| 87 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 88 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 89 | #include "clang/AST/TypeNodes.def" |
| 90 | }; |
| 91 | } |
| 92 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 93 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 94 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 97 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 98 | Writer.AddTypeRef(T->getElementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 99 | Code = TYPE_COMPLEX; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 102 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 103 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 104 | Code = TYPE_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 107 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 108 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 109 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 112 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 113 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
| 114 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 115 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 118 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 119 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 120 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 123 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 125 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 126 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 129 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 130 | Writer.AddTypeRef(T->getElementType(), Record); |
| 131 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 132 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 135 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 136 | VisitArrayType(T); |
| 137 | Writer.AddAPInt(T->getSize(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 138 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 141 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 142 | VisitArrayType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 143 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 146 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 147 | VisitArrayType(T); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 148 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 149 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 150 | Writer.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 151 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 154 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 155 | Writer.AddTypeRef(T->getElementType(), Record); |
| 156 | Record.push_back(T->getNumElements()); |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 157 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 158 | Code = TYPE_VECTOR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 161 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 162 | VisitVectorType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 163 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 166 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 167 | Writer.AddTypeRef(T->getResultType(), Record); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 168 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 169 | Record.push_back(C.getNoReturn()); |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 170 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 171 | Record.push_back(C.getRegParm()); |
Douglas Gregor | ab8bbf4 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 172 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 173 | Record.push_back(C.getCC()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 174 | Record.push_back(C.getProducesResult()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 177 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 178 | VisitFunctionType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 179 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 182 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 183 | VisitFunctionType(T); |
| 184 | Record.push_back(T->getNumArgs()); |
| 185 | for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) |
| 186 | Writer.AddTypeRef(T->getArgType(I), Record); |
| 187 | Record.push_back(T->isVariadic()); |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 188 | Record.push_back(T->hasTrailingReturn()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 189 | Record.push_back(T->getTypeQuals()); |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 190 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 191 | Record.push_back(T->getExceptionSpecType()); |
| 192 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 193 | Record.push_back(T->getNumExceptions()); |
| 194 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 195 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 196 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 197 | Writer.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame^] | 198 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
| 199 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
| 200 | Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 201 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 202 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 205 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 206 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 207 | Code = TYPE_UNRESOLVED_USING; |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 208 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 209 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 210 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 211 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 212 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 213 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 214 | Code = TYPE_TYPEDEF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 217 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 218 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 219 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 222 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 223 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 224 | Code = TYPE_TYPEOF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 227 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 228 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 229 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 230 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 233 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 234 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 235 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 236 | Record.push_back(T->getUTTKind()); |
| 237 | Code = TYPE_UNARY_TRANSFORM; |
| 238 | } |
| 239 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 240 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 241 | Writer.AddTypeRef(T->getDeducedType(), Record); |
| 242 | Code = TYPE_AUTO; |
| 243 | } |
| 244 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 245 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 246 | Record.push_back(T->isDependentType()); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 247 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 | assert(!T->isBeingDefined() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 249 | "Cannot serialize in the middle of a type definition"); |
| 250 | } |
| 251 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 252 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 253 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 254 | Code = TYPE_RECORD; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 257 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 258 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 259 | Code = TYPE_ENUM; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 260 | } |
| 261 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 262 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 263 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 264 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 265 | Record.push_back(T->getAttrKind()); |
| 266 | Code = TYPE_ATTRIBUTED; |
| 267 | } |
| 268 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 269 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 270 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 271 | const SubstTemplateTypeParmType *T) { |
| 272 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 273 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 274 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 278 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 279 | const SubstTemplateTypeParmPackType *T) { |
| 280 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 281 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 282 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 283 | } |
| 284 | |
| 285 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 286 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 287 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 288 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 289 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 290 | Record.push_back(T->getNumArgs()); |
| 291 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 292 | ArgI != ArgE; ++ArgI) |
| 293 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 294 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 295 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 296 | : T->getCanonicalTypeInternal(), |
| 297 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 298 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 302 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 303 | VisitArrayType(T); |
| 304 | Writer.AddStmt(T->getSizeExpr()); |
| 305 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 306 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 310 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 311 | const DependentSizedExtVectorType *T) { |
| 312 | // FIXME: Serialize this type (C++ only) |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 313 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 317 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 318 | Record.push_back(T->getDepth()); |
| 319 | Record.push_back(T->getIndex()); |
| 320 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 321 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 322 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 326 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 327 | Record.push_back(T->getKeyword()); |
| 328 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 329 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 330 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 331 | : T->getCanonicalTypeInternal(), |
| 332 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 333 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 337 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 338 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 339 | Record.push_back(T->getKeyword()); |
| 340 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 341 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 342 | Record.push_back(T->getNumArgs()); |
| 343 | for (DependentTemplateSpecializationType::iterator |
| 344 | I = T->begin(), E = T->end(); I != E; ++I) |
| 345 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 346 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 349 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 350 | Writer.AddTypeRef(T->getPattern(), Record); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 351 | if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) |
| 352 | Record.push_back(*NumExpansions + 1); |
| 353 | else |
| 354 | Record.push_back(0); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 355 | Code = TYPE_PACK_EXPANSION; |
| 356 | } |
| 357 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 358 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 359 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 360 | Code = TYPE_PAREN; |
| 361 | } |
| 362 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 363 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 364 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 365 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 366 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 367 | Code = TYPE_ELABORATED; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 370 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Douglas Gregor | a8e0b97 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 371 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 372 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 373 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 376 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 377 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 378 | Code = TYPE_OBJC_INTERFACE; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 381 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 382 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 383 | Record.push_back(T->getNumProtocols()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 384 | for (ObjCObjectType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 446ee4e | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 385 | E = T->qual_end(); I != E; ++I) |
| 386 | Writer.AddDeclRef(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 387 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 390 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 391 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 392 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 393 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 396 | void |
| 397 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
| 398 | Writer.AddTypeRef(T->getValueType(), Record); |
| 399 | Code = TYPE_ATOMIC; |
| 400 | } |
| 401 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 402 | namespace { |
| 403 | |
| 404 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 405 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 406 | ASTWriter::RecordDataImpl &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 407 | |
| 408 | public: |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 409 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 410 | : Writer(Writer), Record(Record) { } |
| 411 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 412 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 413 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 414 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 415 | #include "clang/AST/TypeLocNodes.def" |
| 416 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 417 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 418 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | } |
| 422 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 423 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 424 | // nothing to do |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 425 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 426 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 427 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 428 | if (TL.needsExtraLocalData()) { |
| 429 | Record.push_back(TL.getWrittenTypeSpec()); |
| 430 | Record.push_back(TL.getWrittenSignSpec()); |
| 431 | Record.push_back(TL.getWrittenWidthSpec()); |
| 432 | Record.push_back(TL.hasModeAttr()); |
| 433 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 434 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 435 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 436 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 437 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 438 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 439 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 440 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 441 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 442 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 443 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 444 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 445 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 446 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 447 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 448 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 449 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 450 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 451 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 452 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 453 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 454 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 455 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 456 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 457 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 458 | if (TL.getSizeExpr()) |
| 459 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 460 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 461 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 462 | VisitArrayTypeLoc(TL); |
| 463 | } |
| 464 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 465 | VisitArrayTypeLoc(TL); |
| 466 | } |
| 467 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 468 | VisitArrayTypeLoc(TL); |
| 469 | } |
| 470 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 471 | DependentSizedArrayTypeLoc TL) { |
| 472 | VisitArrayTypeLoc(TL); |
| 473 | } |
| 474 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 475 | DependentSizedExtVectorTypeLoc TL) { |
| 476 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 477 | } |
| 478 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 479 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 480 | } |
| 481 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 482 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 483 | } |
| 484 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 485 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
| 486 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 487 | Record.push_back(TL.getTrailingReturn()); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 488 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 489 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 490 | } |
| 491 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 492 | VisitFunctionTypeLoc(TL); |
| 493 | } |
| 494 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 495 | VisitFunctionTypeLoc(TL); |
| 496 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 497 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 498 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 499 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 500 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 501 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 502 | } |
| 503 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 504 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 505 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 506 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 507 | } |
| 508 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 509 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 510 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 511 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 512 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 513 | } |
| 514 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 515 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 516 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 517 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 518 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 519 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 520 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 521 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 522 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 523 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 524 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 525 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 526 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 527 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 528 | } |
| 529 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 530 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 531 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 532 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 533 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 534 | if (TL.hasAttrOperand()) { |
| 535 | SourceRange range = TL.getAttrOperandParensRange(); |
| 536 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 537 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 538 | } |
| 539 | if (TL.hasAttrExprOperand()) { |
| 540 | Expr *operand = TL.getAttrExprOperand(); |
| 541 | Record.push_back(operand ? 1 : 0); |
| 542 | if (operand) Writer.AddStmt(operand); |
| 543 | } else if (TL.hasAttrEnumOperand()) { |
| 544 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 545 | } |
| 546 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 547 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 548 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 549 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 550 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 551 | SubstTemplateTypeParmTypeLoc TL) { |
| 552 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 553 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 554 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 555 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 556 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 557 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 558 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 559 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 560 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 561 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 562 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 563 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 564 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 565 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 566 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 567 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 568 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 569 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 570 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 571 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 572 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 573 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 574 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 575 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 576 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 577 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 578 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 579 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 580 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 581 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 582 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 583 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 584 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 585 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 586 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 587 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 588 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 589 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 590 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 591 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 592 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 593 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 594 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 595 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 596 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 597 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 598 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 599 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 600 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 601 | } |
| 602 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 603 | Record.push_back(TL.hasBaseTypeAsWritten()); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 604 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 605 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 606 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 607 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 608 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 609 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 610 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 611 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 612 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 613 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 614 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 615 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 616 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 617 | |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 618 | //===----------------------------------------------------------------------===// |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 619 | // ASTWriter Implementation |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 620 | //===----------------------------------------------------------------------===// |
| 621 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 622 | static void EmitBlockID(unsigned ID, const char *Name, |
| 623 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 624 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 625 | Record.clear(); |
| 626 | Record.push_back(ID); |
| 627 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 628 | |
| 629 | // Emit the block name if present. |
| 630 | if (Name == 0 || Name[0] == 0) return; |
| 631 | Record.clear(); |
| 632 | while (*Name) |
| 633 | Record.push_back(*Name++); |
| 634 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 635 | } |
| 636 | |
| 637 | static void EmitRecordID(unsigned ID, const char *Name, |
| 638 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 639 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 640 | Record.clear(); |
| 641 | Record.push_back(ID); |
| 642 | while (*Name) |
| 643 | Record.push_back(*Name++); |
| 644 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 648 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 649 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 650 | RECORD(STMT_STOP); |
| 651 | RECORD(STMT_NULL_PTR); |
| 652 | RECORD(STMT_NULL); |
| 653 | RECORD(STMT_COMPOUND); |
| 654 | RECORD(STMT_CASE); |
| 655 | RECORD(STMT_DEFAULT); |
| 656 | RECORD(STMT_LABEL); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 657 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 658 | RECORD(STMT_IF); |
| 659 | RECORD(STMT_SWITCH); |
| 660 | RECORD(STMT_WHILE); |
| 661 | RECORD(STMT_DO); |
| 662 | RECORD(STMT_FOR); |
| 663 | RECORD(STMT_GOTO); |
| 664 | RECORD(STMT_INDIRECT_GOTO); |
| 665 | RECORD(STMT_CONTINUE); |
| 666 | RECORD(STMT_BREAK); |
| 667 | RECORD(STMT_RETURN); |
| 668 | RECORD(STMT_DECL); |
| 669 | RECORD(STMT_ASM); |
| 670 | RECORD(EXPR_PREDEFINED); |
| 671 | RECORD(EXPR_DECL_REF); |
| 672 | RECORD(EXPR_INTEGER_LITERAL); |
| 673 | RECORD(EXPR_FLOATING_LITERAL); |
| 674 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 675 | RECORD(EXPR_STRING_LITERAL); |
| 676 | RECORD(EXPR_CHARACTER_LITERAL); |
| 677 | RECORD(EXPR_PAREN); |
| 678 | RECORD(EXPR_UNARY_OPERATOR); |
| 679 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 680 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 681 | RECORD(EXPR_CALL); |
| 682 | RECORD(EXPR_MEMBER); |
| 683 | RECORD(EXPR_BINARY_OPERATOR); |
| 684 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 685 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 686 | RECORD(EXPR_IMPLICIT_CAST); |
| 687 | RECORD(EXPR_CSTYLE_CAST); |
| 688 | RECORD(EXPR_COMPOUND_LITERAL); |
| 689 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 690 | RECORD(EXPR_INIT_LIST); |
| 691 | RECORD(EXPR_DESIGNATED_INIT); |
| 692 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 693 | RECORD(EXPR_VA_ARG); |
| 694 | RECORD(EXPR_ADDR_LABEL); |
| 695 | RECORD(EXPR_STMT); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 696 | RECORD(EXPR_CHOOSE); |
| 697 | RECORD(EXPR_GNU_NULL); |
| 698 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 699 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 700 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 701 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 702 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 703 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 704 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 705 | RECORD(EXPR_OBJC_ENCODE); |
| 706 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 707 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 708 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 709 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 710 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 711 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 712 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 713 | RECORD(STMT_OBJC_CATCH); |
| 714 | RECORD(STMT_OBJC_FINALLY); |
| 715 | RECORD(STMT_OBJC_AT_TRY); |
| 716 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 717 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 718 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 719 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 720 | RECORD(EXPR_CXX_CONSTRUCT); |
| 721 | RECORD(EXPR_CXX_STATIC_CAST); |
| 722 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 723 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 724 | RECORD(EXPR_CXX_CONST_CAST); |
| 725 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 726 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 727 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 728 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 729 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 730 | RECORD(EXPR_CXX_TYPEID_TYPE); |
| 731 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 732 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 733 | RECORD(EXPR_CXX_THIS); |
| 734 | RECORD(EXPR_CXX_THROW); |
| 735 | RECORD(EXPR_CXX_DEFAULT_ARG); |
| 736 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 737 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 738 | RECORD(EXPR_CXX_NEW); |
| 739 | RECORD(EXPR_CXX_DELETE); |
| 740 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 741 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 742 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 743 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 744 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 745 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 746 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
| 747 | RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); |
| 748 | RECORD(EXPR_CXX_NOEXCEPT); |
| 749 | RECORD(EXPR_OPAQUE_VALUE); |
| 750 | RECORD(EXPR_BINARY_TYPE_TRAIT); |
| 751 | RECORD(EXPR_PACK_EXPANSION); |
| 752 | RECORD(EXPR_SIZEOF_PACK); |
| 753 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 754 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 755 | #undef RECORD |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 758 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 759 | RecordData Record; |
| 760 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 762 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 763 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 765 | // AST Top-Level Block. |
Sebastian Redl | f29f0a2 | 2010-08-18 23:57:22 +0000 | [diff] [blame] | 766 | BLOCK(AST_BLOCK); |
Zhongxing Xu | 51e774d | 2009-06-03 09:23:28 +0000 | [diff] [blame] | 767 | RECORD(ORIGINAL_FILE_NAME); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 768 | RECORD(ORIGINAL_FILE_ID); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 769 | RECORD(TYPE_OFFSET); |
| 770 | RECORD(DECL_OFFSET); |
| 771 | RECORD(LANGUAGE_OPTIONS); |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 772 | RECORD(METADATA); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 773 | RECORD(IDENTIFIER_OFFSET); |
| 774 | RECORD(IDENTIFIER_TABLE); |
| 775 | RECORD(EXTERNAL_DEFINITIONS); |
| 776 | RECORD(SPECIAL_TYPES); |
| 777 | RECORD(STATISTICS); |
| 778 | RECORD(TENTATIVE_DEFINITIONS); |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 779 | RECORD(UNUSED_FILESCOPED_DECLS); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 780 | RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); |
| 781 | RECORD(SELECTOR_OFFSETS); |
| 782 | RECORD(METHOD_POOL); |
| 783 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 784 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 785 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 786 | RECORD(STAT_CACHE); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 787 | RECORD(EXT_VECTOR_DECLS); |
Ted Kremenek | 5b4ec63 | 2010-01-22 20:59:36 +0000 | [diff] [blame] | 788 | RECORD(VERSION_CONTROL_BRANCH_REVISION); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 789 | RECORD(PPD_ENTITIES_OFFSETS); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 790 | RECORD(IMPORTS); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 791 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 792 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 793 | RECORD(LOCAL_REDECLARATIONS_MAP); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 794 | RECORD(SEMA_DECL_REFS); |
| 795 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 796 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 797 | RECORD(DECL_REPLACEMENTS); |
| 798 | RECORD(UPDATE_VISIBLE); |
| 799 | RECORD(DECL_UPDATE_OFFSETS); |
| 800 | RECORD(DECL_UPDATES); |
| 801 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 802 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 803 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 804 | RECORD(HEADER_SEARCH_TABLE); |
Douglas Gregor | 837593f | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 805 | RECORD(ORIGINAL_PCH_DIR); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 806 | RECORD(FP_PRAGMA_OPTIONS); |
| 807 | RECORD(OPENCL_EXTENSIONS); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 808 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 809 | RECORD(FILE_SOURCE_LOCATION_OFFSETS); |
| 810 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 837593f | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 811 | RECORD(MODULE_OFFSET_MAP); |
| 812 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 813 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | a126651 | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 814 | RECORD(FILE_SORTED_DECLS); |
| 815 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 816 | RECORD(MERGED_DECLARATIONS); |
| 817 | RECORD(LOCAL_REDECLARATIONS); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 818 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 819 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 820 | // SourceManager Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 821 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 822 | RECORD(SM_SLOC_FILE_ENTRY); |
| 823 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 824 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 825 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 827 | // Preprocessor Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 828 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 829 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 830 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 831 | RECORD(PP_TOKEN); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 832 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 833 | // Decls and Types block. |
| 834 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 835 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 836 | RECORD(TYPE_COMPLEX); |
| 837 | RECORD(TYPE_POINTER); |
| 838 | RECORD(TYPE_BLOCK_POINTER); |
| 839 | RECORD(TYPE_LVALUE_REFERENCE); |
| 840 | RECORD(TYPE_RVALUE_REFERENCE); |
| 841 | RECORD(TYPE_MEMBER_POINTER); |
| 842 | RECORD(TYPE_CONSTANT_ARRAY); |
| 843 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 844 | RECORD(TYPE_VARIABLE_ARRAY); |
| 845 | RECORD(TYPE_VECTOR); |
| 846 | RECORD(TYPE_EXT_VECTOR); |
| 847 | RECORD(TYPE_FUNCTION_PROTO); |
| 848 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 849 | RECORD(TYPE_TYPEDEF); |
| 850 | RECORD(TYPE_TYPEOF_EXPR); |
| 851 | RECORD(TYPE_TYPEOF); |
| 852 | RECORD(TYPE_RECORD); |
| 853 | RECORD(TYPE_ENUM); |
| 854 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | a53d2cb | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 855 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 856 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 857 | RECORD(TYPE_DECLTYPE); |
| 858 | RECORD(TYPE_ELABORATED); |
| 859 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 860 | RECORD(TYPE_UNRESOLVED_USING); |
| 861 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 862 | RECORD(TYPE_OBJC_OBJECT); |
| 863 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 864 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 865 | RECORD(TYPE_DEPENDENT_NAME); |
| 866 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 867 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 868 | RECORD(TYPE_PAREN); |
| 869 | RECORD(TYPE_PACK_EXPANSION); |
| 870 | RECORD(TYPE_ATTRIBUTED); |
| 871 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 872 | RECORD(TYPE_ATOMIC); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 873 | RECORD(DECL_TYPEDEF); |
| 874 | RECORD(DECL_ENUM); |
| 875 | RECORD(DECL_RECORD); |
| 876 | RECORD(DECL_ENUM_CONSTANT); |
| 877 | RECORD(DECL_FUNCTION); |
| 878 | RECORD(DECL_OBJC_METHOD); |
| 879 | RECORD(DECL_OBJC_INTERFACE); |
| 880 | RECORD(DECL_OBJC_PROTOCOL); |
| 881 | RECORD(DECL_OBJC_IVAR); |
| 882 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 883 | RECORD(DECL_OBJC_CATEGORY); |
| 884 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 885 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 886 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 887 | RECORD(DECL_OBJC_PROPERTY); |
| 888 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 889 | RECORD(DECL_FIELD); |
| 890 | RECORD(DECL_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 891 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 892 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 893 | RECORD(DECL_FILE_SCOPE_ASM); |
| 894 | RECORD(DECL_BLOCK); |
| 895 | RECORD(DECL_CONTEXT_LEXICAL); |
| 896 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 897 | RECORD(DECL_NAMESPACE); |
| 898 | RECORD(DECL_NAMESPACE_ALIAS); |
| 899 | RECORD(DECL_USING); |
| 900 | RECORD(DECL_USING_SHADOW); |
| 901 | RECORD(DECL_USING_DIRECTIVE); |
| 902 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 903 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 904 | RECORD(DECL_LINKAGE_SPEC); |
| 905 | RECORD(DECL_CXX_RECORD); |
| 906 | RECORD(DECL_CXX_METHOD); |
| 907 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 908 | RECORD(DECL_CXX_DESTRUCTOR); |
| 909 | RECORD(DECL_CXX_CONVERSION); |
| 910 | RECORD(DECL_ACCESS_SPEC); |
| 911 | RECORD(DECL_FRIEND); |
| 912 | RECORD(DECL_FRIEND_TEMPLATE); |
| 913 | RECORD(DECL_CLASS_TEMPLATE); |
| 914 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 915 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
| 916 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 917 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 918 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 919 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 920 | RECORD(DECL_STATIC_ASSERT); |
| 921 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 922 | RECORD(DECL_INDIRECTFIELD); |
| 923 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 924 | |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 925 | // Statements and Exprs can occur in the Decls and Types block. |
| 926 | AddStmtsExprs(Stream, Record); |
| 927 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 928 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 929 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 930 | RECORD(PPD_MACRO_DEFINITION); |
| 931 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 932 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 933 | #undef RECORD |
| 934 | #undef BLOCK |
| 935 | Stream.ExitBlock(); |
| 936 | } |
| 937 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 938 | /// \brief Adjusts the given filename to only write out the portion of the |
| 939 | /// filename that is not part of the system root directory. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 940 | /// |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 941 | /// \param Filename the file name to adjust. |
| 942 | /// |
| 943 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 944 | /// the returned filename will be adjusted by this system root. |
| 945 | /// |
| 946 | /// \returns either the original filename (if it needs no adjustment) or the |
| 947 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | static const char * |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 949 | adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 950 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 952 | if (isysroot.empty()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 953 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 955 | // Verify that the filename and the system root have the same prefix. |
| 956 | unsigned Pos = 0; |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 957 | for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 958 | if (Filename[Pos] != isysroot[Pos]) |
| 959 | return Filename; // Prefixes don't match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 961 | // We hit the end of the filename before we hit the end of the system root. |
| 962 | if (!Filename[Pos]) |
| 963 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 964 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 965 | // If the file name has a '/' at the current position, skip over the '/'. |
| 966 | // We distinguish sysroot-based includes from absolute includes by the |
| 967 | // absence of '/' at the beginning of sysroot-based includes. |
| 968 | if (Filename[Pos] == '/') |
| 969 | ++Pos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 970 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 971 | return Filename + Pos; |
| 972 | } |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 973 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 974 | /// \brief Write the AST metadata (e.g., i686-apple-darwin9). |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 975 | void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 976 | const std::string &OutputFile) { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 977 | using namespace llvm; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 978 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 979 | // Metadata |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 980 | const TargetInfo &Target = Context.getTargetInfo(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 981 | BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 982 | MetaAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 983 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST major |
| 984 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST minor |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 985 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major |
| 986 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor |
| 987 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 988 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Has errors |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 989 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Target triple |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 990 | unsigned MetaAbbrevCode = Stream.EmitAbbrev(MetaAbbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 992 | RecordData Record; |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 993 | Record.push_back(METADATA); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 994 | Record.push_back(VERSION_MAJOR); |
| 995 | Record.push_back(VERSION_MINOR); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 996 | Record.push_back(CLANG_VERSION_MAJOR); |
| 997 | Record.push_back(CLANG_VERSION_MINOR); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 998 | Record.push_back(!isysroot.empty()); |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 999 | Record.push_back(ASTHasCompilerErrors); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1000 | const std::string &Triple = Target.getTriple().getTriple(); |
| 1001 | Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, Triple); |
| 1002 | |
| 1003 | if (Chain) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1004 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
| 1005 | llvm::SmallVector<char, 128> ModulePaths; |
| 1006 | Record.clear(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1007 | |
| 1008 | for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end(); |
| 1009 | M != MEnd; ++M) { |
| 1010 | // Skip modules that weren't directly imported. |
| 1011 | if (!(*M)->isDirectlyImported()) |
| 1012 | continue; |
| 1013 | |
| 1014 | Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding |
| 1015 | // FIXME: Write import location, once it matters. |
| 1016 | // FIXME: This writes the absolute path for AST files we depend on. |
| 1017 | const std::string &FileName = (*M)->FileName; |
| 1018 | Record.push_back(FileName.size()); |
| 1019 | Record.append(FileName.begin(), FileName.end()); |
| 1020 | } |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1021 | Stream.EmitRecord(IMPORTS, Record); |
| 1022 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1023 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1024 | // Original file name and file ID |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1025 | SourceManager &SM = Context.getSourceManager(); |
| 1026 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 1027 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1028 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE_NAME)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1029 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1030 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1031 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1032 | SmallString<128> MainFilePath(MainFile->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1033 | |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1034 | llvm::sys::fs::make_absolute(MainFilePath); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1035 | |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1036 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1037 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1038 | isysroot); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1039 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1040 | Record.push_back(ORIGINAL_FILE_NAME); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1041 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1042 | |
| 1043 | Record.clear(); |
| 1044 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1045 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1046 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1047 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1048 | // Original PCH directory |
| 1049 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1050 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1051 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1052 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1053 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1054 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1055 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1056 | |
| 1057 | llvm::sys::fs::make_absolute(OutputPath); |
| 1058 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1059 | |
| 1060 | RecordData Record; |
| 1061 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1062 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1063 | } |
| 1064 | |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1065 | // Repository branch/version information. |
| 1066 | BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1067 | RepoAbbrev->Add(BitCodeAbbrevOp(VERSION_CONTROL_BRANCH_REVISION)); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1068 | RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1069 | unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 1070 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1071 | Record.push_back(VERSION_CONTROL_BRANCH_REVISION); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1072 | Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, |
| 1073 | getClangFullRepositoryVersion()); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | /// \brief Write the LangOptions structure. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1077 | void ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1078 | RecordData Record; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 1079 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1080 | Record.push_back(LangOpts.Name); |
| 1081 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1082 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
| 1083 | #include "clang/Basic/LangOptions.def" |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 1084 | |
| 1085 | Record.push_back(LangOpts.CurrentModule.size()); |
| 1086 | Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1087 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1090 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1091 | // stat cache Serialization |
| 1092 | //===----------------------------------------------------------------------===// |
| 1093 | |
| 1094 | namespace { |
| 1095 | // Trait used for the on-disk hash table of stat cache results. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1096 | class ASTStatCacheTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1097 | public: |
| 1098 | typedef const char * key_type; |
| 1099 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1101 | typedef struct stat data_type; |
| 1102 | typedef const data_type &data_type_ref; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1103 | |
| 1104 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1105 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1106 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | |
| 1108 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1109 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1110 | data_type_ref Data) { |
| 1111 | unsigned StrLen = strlen(path); |
| 1112 | clang::io::Emit16(Out, StrLen); |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1113 | unsigned DataLen = 4 + 4 + 2 + 8 + 8; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1114 | clang::io::Emit8(Out, DataLen); |
| 1115 | return std::make_pair(StrLen + 1, DataLen); |
| 1116 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1118 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1119 | Out.write(path, KeyLen); |
| 1120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1122 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1123 | data_type_ref Data, unsigned DataLen) { |
| 1124 | using namespace clang::io; |
| 1125 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1127 | Emit32(Out, (uint32_t) Data.st_ino); |
| 1128 | Emit32(Out, (uint32_t) Data.st_dev); |
| 1129 | Emit16(Out, (uint16_t) Data.st_mode); |
| 1130 | Emit64(Out, (uint64_t) Data.st_mtime); |
| 1131 | Emit64(Out, (uint64_t) Data.st_size); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1132 | |
| 1133 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1134 | } |
| 1135 | }; |
| 1136 | } // end anonymous namespace |
| 1137 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1138 | /// \brief Write the stat() system call cache to the AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1139 | void ASTWriter::WriteStatCache(MemorizeStatCalls &StatCalls) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1140 | // Build the on-disk hash table containing information about every |
| 1141 | // stat() call. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1142 | OnDiskChainedHashTableGenerator<ASTStatCacheTrait> Generator; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1143 | unsigned NumStatEntries = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1145 | StatEnd = StatCalls.end(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1146 | Stat != StatEnd; ++Stat, ++NumStatEntries) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1147 | StringRef Filename = Stat->first(); |
Chris Lattner | 1e5f83b | 2011-07-14 18:24:21 +0000 | [diff] [blame] | 1148 | Generator.insert(Filename.data(), Stat->second); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1151 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1152 | SmallString<4096> StatCacheData; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1153 | uint32_t BucketOffset; |
| 1154 | { |
| 1155 | llvm::raw_svector_ostream Out(StatCacheData); |
| 1156 | // Make sure that no bucket is at offset 0 |
| 1157 | clang::io::Emit32(Out, 0); |
| 1158 | BucketOffset = Generator.Emit(Out); |
| 1159 | } |
| 1160 | |
| 1161 | // Create a blob abbreviation |
| 1162 | using namespace llvm; |
| 1163 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1164 | Abbrev->Add(BitCodeAbbrevOp(STAT_CACHE)); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1165 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1166 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1167 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1168 | unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1169 | |
| 1170 | // Write the stat cache |
| 1171 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1172 | Record.push_back(STAT_CACHE); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1173 | Record.push_back(BucketOffset); |
| 1174 | Record.push_back(NumStatEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1175 | Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1179 | // Source Manager Serialization |
| 1180 | //===----------------------------------------------------------------------===// |
| 1181 | |
| 1182 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1183 | /// file. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1184 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1185 | using namespace llvm; |
| 1186 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1187 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1188 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1189 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1190 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1191 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1192 | // FileEntry fields. |
| 1193 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1194 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1195 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // BufferOverridden |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1196 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1197 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1198 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1199 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1200 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1204 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1205 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1206 | using namespace llvm; |
| 1207 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1208 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1209 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1210 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1211 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1212 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1213 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1214 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1218 | /// buffer's blob. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1219 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1220 | using namespace llvm; |
| 1221 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1222 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1223 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1224 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1227 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1228 | /// expansion. |
| 1229 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1230 | using namespace llvm; |
| 1231 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1232 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1233 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1234 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1235 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1236 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1237 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1238 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1241 | namespace { |
| 1242 | // Trait used for the on-disk hash table of header search information. |
| 1243 | class HeaderFileInfoTrait { |
| 1244 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1245 | const HeaderSearch &HS; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1246 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1247 | // Keep track of the framework names we've used during serialization. |
| 1248 | SmallVector<char, 128> FrameworkStringData; |
| 1249 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1250 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1251 | public: |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1252 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1253 | : Writer(Writer), HS(HS) { } |
| 1254 | |
| 1255 | typedef const char *key_type; |
| 1256 | typedef key_type key_type_ref; |
| 1257 | |
| 1258 | typedef HeaderFileInfo data_type; |
| 1259 | typedef const data_type &data_type_ref; |
| 1260 | |
| 1261 | static unsigned ComputeHash(const char *path) { |
| 1262 | // The hash is based only on the filename portion of the key, so that the |
| 1263 | // reader can match based on filenames when symlinking or excess path |
| 1264 | // elements ("foo/../", "../") change the form of the name. However, |
| 1265 | // complete path is still the key. |
| 1266 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1267 | } |
| 1268 | |
| 1269 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1270 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1271 | data_type_ref Data) { |
| 1272 | unsigned StrLen = strlen(path); |
| 1273 | clang::io::Emit16(Out, StrLen); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1274 | unsigned DataLen = 1 + 2 + 4 + 4; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1275 | clang::io::Emit8(Out, DataLen); |
| 1276 | return std::make_pair(StrLen + 1, DataLen); |
| 1277 | } |
| 1278 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1279 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1280 | Out.write(path, KeyLen); |
| 1281 | } |
| 1282 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1283 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1284 | data_type_ref Data, unsigned DataLen) { |
| 1285 | using namespace clang::io; |
| 1286 | uint64_t Start = Out.tell(); (void)Start; |
| 1287 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1288 | unsigned char Flags = (Data.isImport << 5) |
| 1289 | | (Data.isPragmaOnce << 4) |
| 1290 | | (Data.DirInfo << 2) |
| 1291 | | (Data.Resolved << 1) |
| 1292 | | Data.IndexHeaderMapHeader; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1293 | Emit8(Out, (uint8_t)Flags); |
| 1294 | Emit16(Out, (uint16_t) Data.NumIncludes); |
| 1295 | |
| 1296 | if (!Data.ControllingMacro) |
| 1297 | Emit32(Out, (uint32_t)Data.ControllingMacroID); |
| 1298 | else |
| 1299 | Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1300 | |
| 1301 | unsigned Offset = 0; |
| 1302 | if (!Data.Framework.empty()) { |
| 1303 | // If this header refers into a framework, save the framework name. |
| 1304 | llvm::StringMap<unsigned>::iterator Pos |
| 1305 | = FrameworkNameOffset.find(Data.Framework); |
| 1306 | if (Pos == FrameworkNameOffset.end()) { |
| 1307 | Offset = FrameworkStringData.size() + 1; |
| 1308 | FrameworkStringData.append(Data.Framework.begin(), |
| 1309 | Data.Framework.end()); |
| 1310 | FrameworkStringData.push_back(0); |
| 1311 | |
| 1312 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1313 | } else |
| 1314 | Offset = Pos->second; |
| 1315 | } |
| 1316 | Emit32(Out, Offset); |
| 1317 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1318 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1319 | } |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1320 | |
| 1321 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1322 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1323 | }; |
| 1324 | } // end anonymous namespace |
| 1325 | |
| 1326 | /// \brief Write the header search block for the list of files that |
| 1327 | /// |
| 1328 | /// \param HS The header search structure to save. |
| 1329 | /// |
| 1330 | /// \param Chain Whether we're creating a chained AST file. |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1331 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1332 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1333 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1334 | |
| 1335 | if (FilesByUID.size() > HS.header_file_size()) |
| 1336 | FilesByUID.resize(HS.header_file_size()); |
| 1337 | |
| 1338 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
| 1339 | OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1340 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1341 | unsigned NumHeaderSearchEntries = 0; |
| 1342 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1343 | const FileEntry *File = FilesByUID[UID]; |
| 1344 | if (!File) |
| 1345 | continue; |
| 1346 | |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1347 | // Use HeaderSearch's getFileInfo to make sure we get the HeaderFileInfo |
| 1348 | // from the external source if it was not provided already. |
| 1349 | const HeaderFileInfo &HFI = HS.getFileInfo(File); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1350 | if (HFI.External && Chain) |
| 1351 | continue; |
| 1352 | |
| 1353 | // Turn the file name into an absolute path, if it isn't already. |
| 1354 | const char *Filename = File->getName(); |
| 1355 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1356 | |
| 1357 | // If we performed any translation on the file name at all, we need to |
| 1358 | // save this string, since the generator will refer to it later. |
| 1359 | if (Filename != File->getName()) { |
| 1360 | Filename = strdup(Filename); |
| 1361 | SavedStrings.push_back(Filename); |
| 1362 | } |
| 1363 | |
| 1364 | Generator.insert(Filename, HFI, GeneratorTrait); |
| 1365 | ++NumHeaderSearchEntries; |
| 1366 | } |
| 1367 | |
| 1368 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1369 | SmallString<4096> TableData; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1370 | uint32_t BucketOffset; |
| 1371 | { |
| 1372 | llvm::raw_svector_ostream Out(TableData); |
| 1373 | // Make sure that no bucket is at offset 0 |
| 1374 | clang::io::Emit32(Out, 0); |
| 1375 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1376 | } |
| 1377 | |
| 1378 | // Create a blob abbreviation |
| 1379 | using namespace llvm; |
| 1380 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1381 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1382 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1383 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1384 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1385 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1386 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1387 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1388 | // Write the header search table |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1389 | RecordData Record; |
| 1390 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1391 | Record.push_back(BucketOffset); |
| 1392 | Record.push_back(NumHeaderSearchEntries); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1393 | Record.push_back(TableData.size()); |
| 1394 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1395 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); |
| 1396 | |
| 1397 | // Free all of the strings we had to duplicate. |
| 1398 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
| 1399 | free((void*)SavedStrings[I]); |
| 1400 | } |
| 1401 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1402 | /// \brief Writes the block containing the serialized form of the |
| 1403 | /// source manager. |
| 1404 | /// |
| 1405 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1406 | /// blob), indexed based on the file name, so that we only create |
| 1407 | /// entries for files that we actually need. In the common case (no |
| 1408 | /// errors), we probably won't have to create file entries for any of |
| 1409 | /// the files in the AST. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1410 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1411 | const Preprocessor &PP, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1412 | StringRef isysroot) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1413 | RecordData Record; |
| 1414 | |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1415 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1416 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1417 | |
| 1418 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | 828e18c | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1419 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1420 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1421 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1422 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1423 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1424 | // Write out the source location entry table. We skip the first |
| 1425 | // entry, which is always the same dummy entry. |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1426 | std::vector<uint32_t> SLocEntryOffsets; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1427 | // Write out the offsets of only source location file entries. |
| 1428 | // We will go through them in ASTReader::validateFileEntries(). |
| 1429 | std::vector<uint32_t> SLocFileEntryOffsets; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1430 | RecordData PreloadSLocs; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1431 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1432 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1433 | I != N; ++I) { |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1434 | // Get this source location entry. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1435 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1436 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1437 | // Record the offset of this source-location entry. |
| 1438 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1439 | |
| 1440 | // Figure out which record code to use. |
| 1441 | unsigned Code; |
| 1442 | if (SLoc->isFile()) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1443 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1444 | if (Cache->OrigEntry) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1445 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1446 | SLocFileEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1447 | } else |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1448 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1449 | } else |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1450 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1451 | Record.clear(); |
| 1452 | Record.push_back(Code); |
| 1453 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1454 | // Starting offset of this entry within this module, so skip the dummy. |
| 1455 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1456 | if (SLoc->isFile()) { |
| 1457 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1458 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1459 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1460 | Record.push_back(File.hasLineDirectives()); |
| 1461 | |
| 1462 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1463 | if (Content->OrigEntry) { |
| 1464 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1465 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1466 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1467 | // The source location entry is a file. The blob associated |
| 1468 | // with this entry is the file name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1469 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1470 | // Emit size/modification time for this file. |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1471 | Record.push_back(Content->OrigEntry->getSize()); |
| 1472 | Record.push_back(Content->OrigEntry->getModificationTime()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1473 | Record.push_back(Content->BufferOverridden); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1474 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1475 | |
| 1476 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(SLoc); |
| 1477 | if (FDI != FileDeclIDs.end()) { |
| 1478 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1479 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1480 | } else { |
| 1481 | Record.push_back(0); |
| 1482 | Record.push_back(0); |
| 1483 | } |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1484 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1485 | // Turn the file name into an absolute path, if it isn't already. |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1486 | const char *Filename = Content->OrigEntry->getName(); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1487 | SmallString<128> FilePath(Filename); |
Anders Carlsson | 2c10c80 | 2011-03-08 16:04:35 +0000 | [diff] [blame] | 1488 | |
| 1489 | // Ask the file manager to fixup the relative path for us. This will |
| 1490 | // honor the working directory. |
| 1491 | SourceMgr.getFileManager().FixupRelativePath(FilePath); |
| 1492 | |
| 1493 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1494 | // call to FixupRelativePath should always return an absolute path. |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1495 | llvm::sys::fs::make_absolute(FilePath); |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1496 | Filename = FilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1497 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1498 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1499 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1500 | |
| 1501 | if (Content->BufferOverridden) { |
| 1502 | Record.clear(); |
| 1503 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
| 1504 | const llvm::MemoryBuffer *Buffer |
| 1505 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1506 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
| 1507 | StringRef(Buffer->getBufferStart(), |
| 1508 | Buffer->getBufferSize() + 1)); |
| 1509 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1510 | } else { |
| 1511 | // The source location entry is a buffer. The blob associated |
| 1512 | // with this entry contains the contents of the buffer. |
| 1513 | |
| 1514 | // We add one to the size so that we capture the trailing NULL |
| 1515 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1516 | // the reader side). |
Douglas Gregor | 36c35ba | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1517 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1518 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1519 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1520 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1521 | StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1522 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1523 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1524 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1525 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1526 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1527 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1528 | if (strcmp(Name, "<built-in>") == 0) { |
| 1529 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1530 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1531 | } |
| 1532 | } else { |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1533 | // The source location entry is a macro expansion. |
Chandler Carruth | 1728762 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1534 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 78df836 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1535 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1536 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | d21683c | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1537 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1538 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1539 | |
| 1540 | // Compute the token length for this macro expansion. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1541 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1542 | if (I + 1 != N) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1543 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1544 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1545 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1546 | } |
| 1547 | } |
| 1548 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1549 | Stream.ExitBlock(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1550 | |
| 1551 | if (SLocEntryOffsets.empty()) |
| 1552 | return; |
| 1553 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1554 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1555 | // table is used for lazily loading source-location information. |
| 1556 | using namespace llvm; |
| 1557 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1558 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1559 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1560 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1561 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1562 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1564 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1565 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1566 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1567 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1568 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1569 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1570 | Abbrev = new BitCodeAbbrev(); |
| 1571 | Abbrev->Add(BitCodeAbbrevOp(FILE_SOURCE_LOCATION_OFFSETS)); |
| 1572 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
| 1573 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1574 | unsigned SLocFileOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1575 | |
| 1576 | Record.clear(); |
| 1577 | Record.push_back(FILE_SOURCE_LOCATION_OFFSETS); |
| 1578 | Record.push_back(SLocFileEntryOffsets.size()); |
| 1579 | Stream.EmitRecordWithBlob(SLocFileOffsetsAbbrev, Record, |
| 1580 | data(SLocFileEntryOffsets)); |
| 1581 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1582 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1583 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1584 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1585 | |
| 1586 | // Write the line table. It depends on remapping working, so it must come |
| 1587 | // after the source location offsets. |
| 1588 | if (SourceMgr.hasLineTable()) { |
| 1589 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1590 | |
| 1591 | Record.clear(); |
| 1592 | // Emit the file names |
| 1593 | Record.push_back(LineTable.getNumFilenames()); |
| 1594 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1595 | // Emit the file name |
| 1596 | const char *Filename = LineTable.getFilename(I); |
| 1597 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1598 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1599 | Record.push_back(FilenameLen); |
| 1600 | if (FilenameLen) |
| 1601 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1602 | } |
| 1603 | |
| 1604 | // Emit the line entries |
| 1605 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1606 | L != LEnd; ++L) { |
| 1607 | // Only emit entries for local files. |
| 1608 | if (L->first < 0) |
| 1609 | continue; |
| 1610 | |
| 1611 | // Emit the file ID |
| 1612 | Record.push_back(L->first); |
| 1613 | |
| 1614 | // Emit the line entries |
| 1615 | Record.push_back(L->second.size()); |
| 1616 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1617 | LEEnd = L->second.end(); |
| 1618 | LE != LEEnd; ++LE) { |
| 1619 | Record.push_back(LE->FileOffset); |
| 1620 | Record.push_back(LE->LineNo); |
| 1621 | Record.push_back(LE->FilenameID); |
| 1622 | Record.push_back((unsigned)LE->FileKind); |
| 1623 | Record.push_back(LE->IncludeOffset); |
| 1624 | } |
| 1625 | } |
| 1626 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1627 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1630 | //===----------------------------------------------------------------------===// |
| 1631 | // Preprocessor Serialization |
| 1632 | //===----------------------------------------------------------------------===// |
| 1633 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1634 | static int compareMacroDefinitions(const void *XPtr, const void *YPtr) { |
| 1635 | const std::pair<const IdentifierInfo *, MacroInfo *> &X = |
| 1636 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; |
| 1637 | const std::pair<const IdentifierInfo *, MacroInfo *> &Y = |
| 1638 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; |
| 1639 | return X.first->getName().compare(Y.first->getName()); |
| 1640 | } |
| 1641 | |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1642 | /// \brief Writes the block containing the serialized form of the |
| 1643 | /// preprocessor. |
| 1644 | /// |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1645 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1646 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 1647 | if (PPRec) |
| 1648 | WritePreprocessorDetail(*PPRec); |
| 1649 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1650 | RecordData Record; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1651 | |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1652 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1653 | if (PP.getCounterValue() != 0) { |
| 1654 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1655 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1656 | Record.clear(); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | // Enter the preprocessor block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1660 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1661 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1662 | // If the AST file contains __DATE__ or __TIME__ emit a warning about this. |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1663 | // FIXME: use diagnostics subsystem for localization etc. |
| 1664 | if (PP.SawDateOrTime()) |
| 1665 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1667 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1668 | // Loop over all the macro definitions that are live at the end of the file, |
| 1669 | // emitting each to the PP section. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1670 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1671 | // Construct the list of macro definitions that need to be serialized. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1672 | SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1673 | MacrosToEmit; |
| 1674 | llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1675 | for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), |
| 1676 | E = PP.macro_end(Chain == 0); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1677 | I != E; ++I) { |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 1678 | const IdentifierInfo *Name = I->first; |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1679 | if (!IsModule || I->second->isPublic()) { |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 1680 | MacroDefinitionsSeen.insert(Name); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1681 | MacrosToEmit.push_back(std::make_pair(I->first, I->second)); |
| 1682 | } |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | // Sort the set of macro definitions that need to be serialized by the |
| 1686 | // name of the macro, to provide a stable ordering. |
| 1687 | llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), |
| 1688 | &compareMacroDefinitions); |
| 1689 | |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1690 | // Resolve any identifiers that defined macros at the time they were |
| 1691 | // deserialized, adding them to the list of macros to emit (if appropriate). |
| 1692 | for (unsigned I = 0, N = DeserializedMacroNames.size(); I != N; ++I) { |
| 1693 | IdentifierInfo *Name |
| 1694 | = const_cast<IdentifierInfo *>(DeserializedMacroNames[I]); |
| 1695 | if (Name->hasMacroDefinition() && MacroDefinitionsSeen.insert(Name)) |
| 1696 | MacrosToEmit.push_back(std::make_pair(Name, PP.getMacroInfo(Name))); |
| 1697 | } |
| 1698 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1699 | for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { |
| 1700 | const IdentifierInfo *Name = MacrosToEmit[I].first; |
| 1701 | MacroInfo *MI = MacrosToEmit[I].second; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1702 | if (!MI) |
| 1703 | continue; |
| 1704 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1705 | // Don't emit builtin macros like __LINE__ to the AST file unless they have |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1706 | // been redefined by the header (in which case they are not isBuiltinMacro). |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1707 | // Also skip macros from a AST file if we're chaining. |
Douglas Gregor | ee9b0ba | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 1708 | |
| 1709 | // FIXME: There is a (probably minor) optimization we could do here, if |
| 1710 | // the macro comes from the original PCH but the identifier comes from a |
| 1711 | // chained PCH, by storing the offset into the original PCH rather than |
| 1712 | // writing the macro definition a second time. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1713 | if (MI->isBuiltinMacro() || |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1714 | (Chain && |
| 1715 | Name->isFromAST() && !Name->hasChangedSinceDeserialization() && |
| 1716 | MI->isFromAST() && !MI->hasChangedAfterLoad())) |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1717 | continue; |
| 1718 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1719 | AddIdentifierRef(Name, Record); |
| 1720 | MacroOffsets[Name] = Stream.GetCurrentBitNo(); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1721 | Record.push_back(MI->getDefinitionLoc().getRawEncoding()); |
| 1722 | Record.push_back(MI->isUsed()); |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1723 | Record.push_back(MI->isPublic()); |
| 1724 | AddSourceLocation(MI->getVisibilityLocation(), Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1725 | unsigned Code; |
| 1726 | if (MI->isObjectLike()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1727 | Code = PP_MACRO_OBJECT_LIKE; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1728 | } else { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1729 | Code = PP_MACRO_FUNCTION_LIKE; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1730 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1731 | Record.push_back(MI->isC99Varargs()); |
| 1732 | Record.push_back(MI->isGNUVarargs()); |
| 1733 | Record.push_back(MI->getNumArgs()); |
| 1734 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1735 | I != E; ++I) |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1736 | AddIdentifierRef(*I, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1737 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1738 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1739 | // If we have a detailed preprocessing record, record the macro definition |
| 1740 | // ID that corresponds to this macro. |
| 1741 | if (PPRec) |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1742 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1743 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1744 | Stream.EmitRecord(Code, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1745 | Record.clear(); |
| 1746 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1747 | // Emit the tokens array. |
| 1748 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1749 | // Note that we know that the preprocessor does not have any annotation |
| 1750 | // tokens in it because they are created by the parser, and thus can't be |
| 1751 | // in a macro definition. |
| 1752 | const Token &Tok = MI->getReplacementToken(TokNo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1753 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1754 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1755 | Record.push_back(Tok.getLength()); |
| 1756 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1757 | // FIXME: When reading literal tokens, reconstruct the literal pointer if |
| 1758 | // it is needed. |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1759 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1760 | // FIXME: Should translate token kind to a stable encoding. |
| 1761 | Record.push_back(Tok.getKind()); |
| 1762 | // FIXME: Should translate token flags to a stable encoding. |
| 1763 | Record.push_back(Tok.getFlags()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1764 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1765 | Stream.EmitRecord(PP_TOKEN, Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1766 | Record.clear(); |
| 1767 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1768 | ++NumMacros; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1769 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1770 | Stream.ExitBlock(); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | b6441ef | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 1774 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1775 | return; |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1776 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1777 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1778 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1779 | // Enter the preprocessor block. |
| 1780 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1781 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1782 | // If the preprocessor has a preprocessing record, emit it. |
| 1783 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1784 | using namespace llvm; |
| 1785 | |
| 1786 | // Set up the abbreviation for |
| 1787 | unsigned InclusionAbbrev = 0; |
| 1788 | { |
| 1789 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1790 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1791 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 1792 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 1793 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
| 1794 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1795 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1796 | } |
| 1797 | |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1798 | unsigned FirstPreprocessorEntityID |
| 1799 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 1800 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 1801 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1802 | RecordData Record; |
Argyrios Kyrtzidis | b6441ef | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 1803 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 1804 | EEnd = PPRec.local_end(); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1805 | E != EEnd; |
| 1806 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1807 | Record.clear(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1808 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1809 | PreprocessedEntityOffsets.push_back(PPEntityOffset((*E)->getSourceRange(), |
| 1810 | Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1811 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1812 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1813 | // Record this macro definition's ID. |
| 1814 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1815 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1816 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1817 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 1818 | continue; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1819 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1820 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1821 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 8f7c540 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1822 | Record.push_back(ME->isBuiltinMacro()); |
| 1823 | if (ME->isBuiltinMacro()) |
| 1824 | AddIdentifierRef(ME->getName(), Record); |
| 1825 | else |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1826 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1827 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1828 | continue; |
| 1829 | } |
| 1830 | |
| 1831 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 1832 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1833 | Record.push_back(ID->getFileName().size()); |
| 1834 | Record.push_back(ID->wasInQuotes()); |
| 1835 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1836 | SmallString<64> Buffer; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1837 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 1838 | // Check that the FileEntry is not null because it was not resolved and |
| 1839 | // we create a PCH even with compiler errors. |
| 1840 | if (ID->getFile()) |
| 1841 | Buffer += ID->getFile()->getName(); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1842 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 1843 | continue; |
| 1844 | } |
| 1845 | |
| 1846 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 1847 | } |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1848 | Stream.ExitBlock(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1850 | // Write the offsets table for the preprocessing record. |
| 1851 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1852 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 1853 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1854 | // Write the offsets table for identifier IDs. |
| 1855 | using namespace llvm; |
| 1856 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1857 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1858 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1859 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1860 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1861 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1862 | Record.clear(); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1863 | Record.push_back(PPD_ENTITIES_OFFSETS); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1864 | Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1865 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
| 1866 | data(PreprocessedEntityOffsets)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1867 | } |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 1870 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 1871 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 1872 | if (Known != SubmoduleIDs.end()) |
| 1873 | return Known->second; |
| 1874 | |
| 1875 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 1876 | } |
| 1877 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1878 | /// \brief Compute the number of modules within the given tree (including the |
| 1879 | /// given module). |
| 1880 | static unsigned getNumberOfModules(Module *Mod) { |
| 1881 | unsigned ChildModules = 0; |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 1882 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 1883 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1884 | Sub != SubEnd; ++Sub) |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 1885 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1886 | |
| 1887 | return ChildModules + 1; |
| 1888 | } |
| 1889 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1890 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 4bc8738d | 2011-12-05 16:35:23 +0000 | [diff] [blame] | 1891 | // Determine the dependencies of our module and each of it's submodules. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 1892 | // FIXME: This feels like it belongs somewhere else, but there are no |
| 1893 | // other consumers of this information. |
| 1894 | SourceManager &SrcMgr = PP->getSourceManager(); |
| 1895 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
| 1896 | for (ASTContext::import_iterator I = Context->local_import_begin(), |
| 1897 | IEnd = Context->local_import_end(); |
| 1898 | I != IEnd; ++I) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 1899 | if (Module *ImportedFrom |
| 1900 | = ModMap.inferModuleFromLocation(FullSourceLoc(I->getLocation(), |
| 1901 | SrcMgr))) { |
| 1902 | ImportedFrom->Imports.push_back(I->getImportedModule()); |
| 1903 | } |
| 1904 | } |
| 1905 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1906 | // Enter the submodule description block. |
| 1907 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
| 1908 | |
| 1909 | // Write the abbreviations needed for the submodules block. |
| 1910 | using namespace llvm; |
| 1911 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1912 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 1913 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1914 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 1915 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 1916 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 1917 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 1918 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 1919 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 1920 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1921 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1922 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1923 | |
| 1924 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 1925 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1926 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1927 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1928 | |
| 1929 | Abbrev = new BitCodeAbbrev(); |
| 1930 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 1931 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1932 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 1933 | |
| 1934 | Abbrev = new BitCodeAbbrev(); |
| 1935 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 1936 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1937 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1938 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 1939 | Abbrev = new BitCodeAbbrev(); |
| 1940 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
| 1941 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
| 1942 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1943 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1944 | // Write the submodule metadata block. |
| 1945 | RecordData Record; |
| 1946 | Record.push_back(getNumberOfModules(WritingModule)); |
| 1947 | Record.push_back(FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS); |
| 1948 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 1949 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1950 | // Write all of the submodules. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1951 | std::queue<Module *> Q; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1952 | Q.push(WritingModule); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1953 | while (!Q.empty()) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1954 | Module *Mod = Q.front(); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1955 | Q.pop(); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 1956 | unsigned ID = getSubmoduleID(Mod); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1957 | |
| 1958 | // Emit the definition of the block. |
| 1959 | Record.clear(); |
| 1960 | Record.push_back(SUBMODULE_DEFINITION); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 1961 | Record.push_back(ID); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1962 | if (Mod->Parent) { |
| 1963 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
| 1964 | Record.push_back(SubmoduleIDs[Mod->Parent]); |
| 1965 | } else { |
| 1966 | Record.push_back(0); |
| 1967 | } |
| 1968 | Record.push_back(Mod->IsFramework); |
| 1969 | Record.push_back(Mod->IsExplicit); |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 1970 | Record.push_back(Mod->IsSystem); |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 1971 | Record.push_back(Mod->InferSubmodules); |
| 1972 | Record.push_back(Mod->InferExplicitSubmodules); |
| 1973 | Record.push_back(Mod->InferExportWildcard); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1974 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 1975 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 1976 | // Emit the requirements. |
| 1977 | for (unsigned I = 0, N = Mod->Requires.size(); I != N; ++I) { |
| 1978 | Record.clear(); |
| 1979 | Record.push_back(SUBMODULE_REQUIRES); |
| 1980 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, |
| 1981 | Mod->Requires[I].data(), |
| 1982 | Mod->Requires[I].size()); |
| 1983 | } |
| 1984 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1985 | // Emit the umbrella header, if there is one. |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 1986 | if (const FileEntry *UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1987 | Record.clear(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 1988 | Record.push_back(SUBMODULE_UMBRELLA_HEADER); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1989 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 1990 | UmbrellaHeader->getName()); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 1991 | } else if (const DirectoryEntry *UmbrellaDir = Mod->getUmbrellaDir()) { |
| 1992 | Record.clear(); |
| 1993 | Record.push_back(SUBMODULE_UMBRELLA_DIR); |
| 1994 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
| 1995 | UmbrellaDir->getName()); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | // Emit the headers. |
| 1999 | for (unsigned I = 0, N = Mod->Headers.size(); I != N; ++I) { |
| 2000 | Record.clear(); |
| 2001 | Record.push_back(SUBMODULE_HEADER); |
| 2002 | Stream.EmitRecordWithBlob(HeaderAbbrev, Record, |
| 2003 | Mod->Headers[I]->getName()); |
| 2004 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2005 | |
| 2006 | // Emit the imports. |
| 2007 | if (!Mod->Imports.empty()) { |
| 2008 | Record.clear(); |
| 2009 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
Douglas Gregor | bab9f4a | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2010 | unsigned ImportedID = getSubmoduleID(Mod->Imports[I]); |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2011 | assert(ImportedID && "Unknown submodule!"); |
| 2012 | Record.push_back(ImportedID); |
| 2013 | } |
| 2014 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2015 | } |
| 2016 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2017 | // Emit the exports. |
| 2018 | if (!Mod->Exports.empty()) { |
| 2019 | Record.clear(); |
| 2020 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
Douglas Gregor | bab9f4a | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2021 | if (Module *Exported = Mod->Exports[I].getPointer()) { |
| 2022 | unsigned ExportedID = SubmoduleIDs[Exported]; |
| 2023 | assert(ExportedID > 0 && "Unknown submodule ID?"); |
| 2024 | Record.push_back(ExportedID); |
| 2025 | } else { |
| 2026 | Record.push_back(0); |
| 2027 | } |
| 2028 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2029 | Record.push_back(Mod->Exports[I].getInt()); |
| 2030 | } |
| 2031 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2032 | } |
| 2033 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2034 | // Queue up the submodules of this module. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2035 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2036 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2037 | Sub != SubEnd; ++Sub) |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2038 | Q.push(*Sub); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | Stream.ExitBlock(); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2042 | |
| 2043 | assert((NextSubmoduleID - FirstSubmoduleID |
| 2044 | == getNumberOfModules(WritingModule)) && "Wrong # of submodules"); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2047 | serialization::SubmoduleID |
| 2048 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2049 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2050 | return 0; // No submodule |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2051 | |
| 2052 | // Find the module that owns this location. |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2053 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2054 | Module *OwningMod |
| 2055 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2056 | if (!OwningMod) |
| 2057 | return 0; |
| 2058 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2059 | // Check whether this submodule is part of our own module. |
| 2060 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2061 | return 0; |
| 2062 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2063 | return getSubmoduleID(OwningMod); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2066 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2067 | RecordData Record; |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2068 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2069 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2070 | I != E; ++I) { |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2071 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2072 | if (point.Loc.isInvalid()) |
| 2073 | continue; |
| 2074 | |
| 2075 | Record.push_back(point.Loc.getRawEncoding()); |
Daniel Dunbar | ba494c6 | 2011-09-29 01:42:25 +0000 | [diff] [blame] | 2076 | for (DiagnosticsEngine::DiagState::const_iterator |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2077 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
Daniel Dunbar | b1c99c6 | 2011-09-29 01:30:00 +0000 | [diff] [blame] | 2078 | if (I->second.isPragma()) { |
| 2079 | Record.push_back(I->first); |
| 2080 | Record.push_back(I->second.getMapping()); |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2081 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2082 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2083 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2084 | // location. |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
Argyrios Kyrtzidis | 60f7684 | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2087 | if (!Record.empty()) |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2088 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2091 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2092 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2093 | return; |
| 2094 | |
| 2095 | RecordData Record; |
| 2096 | |
| 2097 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2098 | using namespace llvm; |
| 2099 | |
| 2100 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2101 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2102 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2103 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2104 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2105 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2106 | // Write the base specifier offsets table. |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2107 | Record.clear(); |
| 2108 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 2109 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 2110 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2111 | data(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2112 | } |
| 2113 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2114 | //===----------------------------------------------------------------------===// |
| 2115 | // Type Serialization |
| 2116 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2117 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2118 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2119 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2120 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2121 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2122 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2123 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2124 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | 55f48de | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2125 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2126 | // Record the offset for this type. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2127 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2128 | if (TypeOffsets.size() == Index) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2129 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2130 | else if (TypeOffsets.size() < Index) { |
| 2131 | TypeOffsets.resize(Index + 1); |
| 2132 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | RecordData Record; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2136 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2137 | // Emit the type's representation. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2138 | ASTTypeWriter W(*this, Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2139 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2140 | if (T.hasLocalNonFastQualifiers()) { |
| 2141 | Qualifiers Qs = T.getLocalQualifiers(); |
| 2142 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2143 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2144 | W.Code = TYPE_EXT_QUAL; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2145 | } else { |
| 2146 | switch (T->getTypeClass()) { |
| 2147 | // For all of the concrete, non-dependent types, call the |
| 2148 | // appropriate visitor function. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2149 | #define TYPE(Class, Base) \ |
Mike Stump | b716633 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 2150 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2151 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2152 | #include "clang/AST/TypeNodes.def" |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2153 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | // Emit the serialized record. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2157 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2158 | |
| 2159 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2160 | FlushStmts(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2163 | //===----------------------------------------------------------------------===// |
| 2164 | // Declaration Serialization |
| 2165 | //===----------------------------------------------------------------------===// |
| 2166 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2167 | /// \brief Write the block containing all of the declaration IDs |
| 2168 | /// lexically declared within the given DeclContext. |
| 2169 | /// |
| 2170 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2171 | /// bistream, or 0 if no block was written. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2172 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2173 | DeclContext *DC) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2174 | if (DC->decls_empty()) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2175 | return 0; |
| 2176 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2177 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2178 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2179 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2180 | SmallVector<KindDeclIDPair, 64> Decls; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2181 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 2182 | D != DEnd; ++D) |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2183 | Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2184 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2185 | ++NumLexicalDeclContexts; |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2186 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2187 | return Offset; |
| 2188 | } |
| 2189 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2190 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2191 | using namespace llvm; |
| 2192 | RecordData Record; |
| 2193 | |
| 2194 | // Write the type offsets array |
| 2195 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2196 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2197 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2198 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2199 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2200 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2201 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2202 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2203 | Record.push_back(TypeOffsets.size()); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2204 | Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2205 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2206 | |
| 2207 | // Write the declaration offsets array |
| 2208 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2209 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2210 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2211 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2212 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2213 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2214 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2215 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2216 | Record.push_back(DeclOffsets.size()); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2217 | Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2218 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2221 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2222 | using namespace llvm; |
| 2223 | RecordData Record; |
| 2224 | |
| 2225 | // Join the vectors of DeclIDs from all files. |
| 2226 | SmallVector<DeclID, 256> FileSortedIDs; |
| 2227 | for (FileDeclIDsTy::iterator |
| 2228 | FI = FileDeclIDs.begin(), FE = FileDeclIDs.end(); FI != FE; ++FI) { |
| 2229 | DeclIDInFileInfo &Info = *FI->second; |
| 2230 | Info.FirstDeclIndex = FileSortedIDs.size(); |
| 2231 | for (LocDeclIDsTy::iterator |
| 2232 | DI = Info.DeclIDs.begin(), DE = Info.DeclIDs.end(); DI != DE; ++DI) |
| 2233 | FileSortedIDs.push_back(DI->second); |
| 2234 | } |
| 2235 | |
| 2236 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2237 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
| 2238 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2239 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 2240 | Record.push_back(FILE_SORTED_DECLS); |
| 2241 | Stream.EmitRecordWithBlob(AbbrevCode, Record, data(FileSortedIDs)); |
| 2242 | } |
| 2243 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2244 | //===----------------------------------------------------------------------===// |
| 2245 | // Global Method Pool and Selector Serialization |
| 2246 | //===----------------------------------------------------------------------===// |
| 2247 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2248 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2249 | // Trait used for the on-disk hash table used in the method pool. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2250 | class ASTMethodPoolTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2251 | ASTWriter &Writer; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2252 | |
| 2253 | public: |
| 2254 | typedef Selector key_type; |
| 2255 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2256 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2257 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2258 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2259 | ObjCMethodList Instance, Factory; |
| 2260 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2261 | typedef const data_type& data_type_ref; |
| 2262 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2263 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2264 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2265 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2266 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2267 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2268 | |
| 2269 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2270 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2271 | data_type_ref Methods) { |
| 2272 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 2273 | clang::io::Emit16(Out, KeyLen); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2274 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2275 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2276 | Method = Method->Next) |
| 2277 | if (Method->Method) |
| 2278 | DataLen += 4; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2279 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2280 | Method = Method->Next) |
| 2281 | if (Method->Method) |
| 2282 | DataLen += 4; |
| 2283 | clang::io::Emit16(Out, DataLen); |
| 2284 | return std::make_pair(KeyLen, DataLen); |
| 2285 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2286 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2287 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2288 | uint64_t Start = Out.tell(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2289 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2290 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2291 | unsigned N = Sel.getNumArgs(); |
| 2292 | clang::io::Emit16(Out, N); |
| 2293 | if (N == 0) |
| 2294 | N = 1; |
| 2295 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2296 | clang::io::Emit32(Out, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2297 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 2298 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2299 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2300 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2301 | data_type_ref Methods, unsigned DataLen) { |
| 2302 | uint64_t Start = Out.tell(); (void)Start; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2303 | clang::io::Emit32(Out, Methods.ID); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2304 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2305 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2306 | Method = Method->Next) |
| 2307 | if (Method->Method) |
| 2308 | ++NumInstanceMethods; |
| 2309 | |
| 2310 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2311 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2312 | Method = Method->Next) |
| 2313 | if (Method->Method) |
| 2314 | ++NumFactoryMethods; |
| 2315 | |
| 2316 | clang::io::Emit16(Out, NumInstanceMethods); |
| 2317 | clang::io::Emit16(Out, NumFactoryMethods); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2318 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2319 | Method = Method->Next) |
| 2320 | if (Method->Method) |
| 2321 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2322 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2323 | Method = Method->Next) |
| 2324 | if (Method->Method) |
| 2325 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2326 | |
| 2327 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2328 | } |
| 2329 | }; |
| 2330 | } // end anonymous namespace |
| 2331 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2332 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2333 | /// |
| 2334 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2335 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2336 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2337 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2338 | using namespace llvm; |
| 2339 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2340 | // Do we have to do anything at all? |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2341 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2342 | return; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2343 | unsigned NumTableEntries = 0; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2344 | // Create and write out the blob that contains selectors and the method pool. |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2345 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2346 | OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2347 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2348 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2349 | // Create the on-disk hash table representation. We walk through every |
| 2350 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2351 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2352 | for (llvm::DenseMap<Selector, SelectorID>::iterator |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2353 | I = SelectorIDs.begin(), E = SelectorIDs.end(); |
| 2354 | I != E; ++I) { |
| 2355 | Selector S = I->first; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2356 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2357 | ASTMethodPoolTrait::data_type Data = { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2358 | I->second, |
| 2359 | ObjCMethodList(), |
| 2360 | ObjCMethodList() |
| 2361 | }; |
| 2362 | if (F != SemaRef.MethodPool.end()) { |
| 2363 | Data.Instance = F->second.first; |
| 2364 | Data.Factory = F->second.second; |
| 2365 | } |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2366 | // Only write this selector if it's not in an existing AST or something |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2367 | // changed. |
| 2368 | if (Chain && I->second < FirstSelectorID) { |
| 2369 | // Selector already exists. Did it change? |
| 2370 | bool changed = false; |
| 2371 | for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; |
| 2372 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2373 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2374 | changed = true; |
| 2375 | } |
| 2376 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; |
| 2377 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2378 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2379 | changed = true; |
| 2380 | } |
| 2381 | if (!changed) |
| 2382 | continue; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2383 | } else if (Data.Instance.Method || Data.Factory.Method) { |
| 2384 | // A new method pool entry. |
| 2385 | ++NumTableEntries; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2386 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2387 | Generator.insert(S, Data, Trait); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2390 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2391 | SmallString<4096> MethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2392 | uint32_t BucketOffset; |
| 2393 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2394 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2395 | llvm::raw_svector_ostream Out(MethodPool); |
| 2396 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2397 | clang::io::Emit32(Out, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2398 | BucketOffset = Generator.Emit(Out, Trait); |
| 2399 | } |
| 2400 | |
| 2401 | // Create a blob abbreviation |
| 2402 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2403 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2404 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2405 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2406 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2407 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2408 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2409 | // Write the method pool |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2410 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2411 | Record.push_back(METHOD_POOL); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2412 | Record.push_back(BucketOffset); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2413 | Record.push_back(NumTableEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2414 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2415 | |
| 2416 | // Create a blob abbreviation for the selector table offsets. |
| 2417 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2418 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2419 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2420 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2421 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2422 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2423 | |
| 2424 | // Write the selector offsets table. |
| 2425 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2426 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2427 | Record.push_back(SelectorOffsets.size()); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2428 | Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2429 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2430 | data(SelectorOffsets)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2434 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2435 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2436 | using namespace llvm; |
| 2437 | if (SemaRef.ReferencedSelectors.empty()) |
| 2438 | return; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2439 | |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2440 | RecordData Record; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2441 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2442 | // Note: this writes out all references even for a dependent AST. But it is |
Sebastian Redl | a68340f | 2010-08-04 22:21:29 +0000 | [diff] [blame] | 2443 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 2444 | // headers, probably not worth it. It's not a correctness issue. |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2445 | for (DenseMap<Selector, SourceLocation>::iterator S = |
| 2446 | SemaRef.ReferencedSelectors.begin(), |
| 2447 | E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { |
| 2448 | Selector Sel = (*S).first; |
| 2449 | SourceLocation Loc = (*S).second; |
| 2450 | AddSelectorRef(Sel, Record); |
| 2451 | AddSourceLocation(Loc, Record); |
| 2452 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2453 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2454 | } |
| 2455 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2456 | //===----------------------------------------------------------------------===// |
| 2457 | // Identifier Table Serialization |
| 2458 | //===----------------------------------------------------------------------===// |
| 2459 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2460 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2461 | class ASTIdentifierTableTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2462 | ASTWriter &Writer; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2463 | Preprocessor &PP; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2464 | IdentifierResolver &IdResolver; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2465 | bool IsModule; |
| 2466 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2467 | /// \brief Determines whether this is an "interesting" identifier |
| 2468 | /// that needs a full IdentifierInfo structure written into the hash |
| 2469 | /// table. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2470 | bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) { |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2471 | if (II->isPoisoned() || |
| 2472 | II->isExtensionToken() || |
| 2473 | II->getObjCOrBuiltinID() || |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2474 | II->hasRevertedTokenIDToIdentifier() || |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2475 | II->getFETokenInfo<void>()) |
| 2476 | return true; |
| 2477 | |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2478 | return hasMacroDefinition(II, Macro); |
| 2479 | } |
| 2480 | |
| 2481 | bool hasMacroDefinition(IdentifierInfo *II, MacroInfo *&Macro) { |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2482 | if (!II->hasMacroDefinition()) |
| 2483 | return false; |
| 2484 | |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2485 | if (Macro || (Macro = PP.getMacroInfo(II))) |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 2486 | return !Macro->isBuiltinMacro() && (!IsModule || Macro->isPublic()); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2487 | |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2488 | return false; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2491 | public: |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2492 | typedef IdentifierInfo* key_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2493 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2494 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2495 | typedef IdentID data_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2496 | typedef data_type data_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2497 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2498 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
| 2499 | IdentifierResolver &IdResolver, bool IsModule) |
| 2500 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule) { } |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2501 | |
| 2502 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 2503 | return llvm::HashString(II->getName()); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2505 | |
| 2506 | std::pair<unsigned,unsigned> |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2507 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2508 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2509 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2510 | MacroInfo *Macro = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2511 | if (isInterestingIdentifier(II, Macro)) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2512 | DataLen += 2; // 2 bytes for builtin ID, flags |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2513 | if (hasMacroDefinition(II, Macro)) |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2514 | DataLen += 8; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2515 | |
| 2516 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 2517 | DEnd = IdResolver.end(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2518 | D != DEnd; ++D) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2519 | DataLen += sizeof(DeclID); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2520 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2521 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 2522 | // We emit the key length after the data length so that every |
| 2523 | // string is preceded by a 16-bit length. This matches the PTH |
| 2524 | // format for storing identifiers. |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2525 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2526 | return std::make_pair(KeyLen, DataLen); |
| 2527 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2528 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2529 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2530 | unsigned KeyLen) { |
| 2531 | // Record the location of the key data. This is used when generating |
| 2532 | // the mapping from persistent IDs to strings. |
| 2533 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2534 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2536 | |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2537 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2538 | IdentID ID, unsigned) { |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2539 | MacroInfo *Macro = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2540 | if (!isInterestingIdentifier(II, Macro)) { |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2541 | clang::io::Emit32(Out, ID << 1); |
| 2542 | return; |
| 2543 | } |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2544 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2545 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2546 | uint32_t Bits = 0; |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2547 | bool HasMacroDefinition = hasMacroDefinition(II, Macro); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2548 | Bits = (uint32_t)II->getObjCOrBuiltinID(); |
Craig Topper | 925be54 | 2011-12-19 05:04:33 +0000 | [diff] [blame] | 2549 | assert((Bits & 0x7ff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2550 | Bits = (Bits << 1) | unsigned(HasMacroDefinition); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2551 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 2552 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 2553 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2554 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2555 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2556 | |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2557 | if (HasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2558 | clang::io::Emit32(Out, Writer.getMacroOffset(II)); |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2559 | clang::io::Emit32(Out, |
| 2560 | Writer.inferSubmoduleIDFromLocation(Macro->getDefinitionLoc())); |
| 2561 | } |
| 2562 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2563 | // Emit the declaration IDs in reverse order, because the |
| 2564 | // IdentifierResolver provides the declarations as they would be |
| 2565 | // visible (e.g., the function "stat" would come before the struct |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2566 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 2567 | // (so we need to see the struct "status" before the function "status"). |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2568 | // Only emit declarations that aren't from a chained PCH, though. |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2569 | SmallVector<Decl *, 16> Decls(IdResolver.begin(II), |
| 2570 | IdResolver.end()); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2571 | for (SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2572 | DEnd = Decls.rend(); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2573 | D != DEnd; ++D) |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 2574 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2575 | } |
| 2576 | }; |
| 2577 | } // end anonymous namespace |
| 2578 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2579 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2580 | /// |
| 2581 | /// The identifier table consists of a blob containing string data |
| 2582 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 2583 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2584 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 2585 | IdentifierResolver &IdResolver, |
| 2586 | bool IsModule) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2587 | using namespace llvm; |
| 2588 | |
| 2589 | // Create and write out the blob that contains the identifier |
| 2590 | // strings. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2591 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2592 | OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2593 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2594 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2595 | // Look for any identifiers that were named while processing the |
| 2596 | // headers, but are otherwise not needed. We add these to the hash |
| 2597 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2598 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2599 | // file. |
| 2600 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 2601 | IDEnd = PP.getIdentifierTable().end(); |
| 2602 | ID != IDEnd; ++ID) |
| 2603 | getIdentifierRef(ID->second); |
| 2604 | |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2605 | // Create the on-disk hash table representation. We only store offsets |
| 2606 | // for identifiers that appear here for the first time. |
| 2607 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2608 | for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2609 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 2610 | ID != IDEnd; ++ID) { |
| 2611 | assert(ID->first && "NULL identifier in identifier table"); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2612 | if (!Chain || !ID->first->isFromAST() || |
| 2613 | ID->first->hasChangedSinceDeserialization()) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2614 | Generator.insert(const_cast<IdentifierInfo *>(ID->first), ID->second, |
| 2615 | Trait); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2616 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2617 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2618 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2619 | SmallString<4096> IdentifierTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2620 | uint32_t BucketOffset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2621 | { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2622 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2623 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2624 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2625 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2626 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | // Create a blob abbreviation |
| 2630 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2631 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2632 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2633 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2634 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2635 | |
| 2636 | // Write the identifier table |
| 2637 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2638 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2639 | Record.push_back(BucketOffset); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2640 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2644 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2645 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2646 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2647 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2648 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2649 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2650 | |
| 2651 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2652 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2653 | Record.push_back(IdentifierOffsets.size()); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2654 | Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2655 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2656 | data(IdentifierOffsets)); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2657 | } |
| 2658 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2659 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2660 | // DeclContext's Name Lookup Table Serialization |
| 2661 | //===----------------------------------------------------------------------===// |
| 2662 | |
| 2663 | namespace { |
| 2664 | // Trait used for the on-disk hash table used in the method pool. |
| 2665 | class ASTDeclContextNameLookupTrait { |
| 2666 | ASTWriter &Writer; |
| 2667 | |
| 2668 | public: |
| 2669 | typedef DeclarationName key_type; |
| 2670 | typedef key_type key_type_ref; |
| 2671 | |
| 2672 | typedef DeclContext::lookup_result data_type; |
| 2673 | typedef const data_type& data_type_ref; |
| 2674 | |
| 2675 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 2676 | |
| 2677 | unsigned ComputeHash(DeclarationName Name) { |
| 2678 | llvm::FoldingSetNodeID ID; |
| 2679 | ID.AddInteger(Name.getNameKind()); |
| 2680 | |
| 2681 | switch (Name.getNameKind()) { |
| 2682 | case DeclarationName::Identifier: |
| 2683 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 2684 | break; |
| 2685 | case DeclarationName::ObjCZeroArgSelector: |
| 2686 | case DeclarationName::ObjCOneArgSelector: |
| 2687 | case DeclarationName::ObjCMultiArgSelector: |
| 2688 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 2689 | break; |
| 2690 | case DeclarationName::CXXConstructorName: |
| 2691 | case DeclarationName::CXXDestructorName: |
| 2692 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2693 | break; |
| 2694 | case DeclarationName::CXXOperatorName: |
| 2695 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 2696 | break; |
| 2697 | case DeclarationName::CXXLiteralOperatorName: |
| 2698 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 2699 | case DeclarationName::CXXUsingDirective: |
| 2700 | break; |
| 2701 | } |
| 2702 | |
| 2703 | return ID.ComputeHash(); |
| 2704 | } |
| 2705 | |
| 2706 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2707 | EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2708 | data_type_ref Lookup) { |
| 2709 | unsigned KeyLen = 1; |
| 2710 | switch (Name.getNameKind()) { |
| 2711 | case DeclarationName::Identifier: |
| 2712 | case DeclarationName::ObjCZeroArgSelector: |
| 2713 | case DeclarationName::ObjCOneArgSelector: |
| 2714 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2715 | case DeclarationName::CXXLiteralOperatorName: |
| 2716 | KeyLen += 4; |
| 2717 | break; |
| 2718 | case DeclarationName::CXXOperatorName: |
| 2719 | KeyLen += 1; |
| 2720 | break; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2721 | case DeclarationName::CXXConstructorName: |
| 2722 | case DeclarationName::CXXDestructorName: |
| 2723 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2724 | case DeclarationName::CXXUsingDirective: |
| 2725 | break; |
| 2726 | } |
| 2727 | clang::io::Emit16(Out, KeyLen); |
| 2728 | |
| 2729 | // 2 bytes for num of decls and 4 for each DeclID. |
| 2730 | unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); |
| 2731 | clang::io::Emit16(Out, DataLen); |
| 2732 | |
| 2733 | return std::make_pair(KeyLen, DataLen); |
| 2734 | } |
| 2735 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2736 | void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2737 | using namespace clang::io; |
| 2738 | |
| 2739 | assert(Name.getNameKind() < 0x100 && "Invalid name kind ?"); |
| 2740 | Emit8(Out, Name.getNameKind()); |
| 2741 | switch (Name.getNameKind()) { |
| 2742 | case DeclarationName::Identifier: |
| 2743 | Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
| 2744 | break; |
| 2745 | case DeclarationName::ObjCZeroArgSelector: |
| 2746 | case DeclarationName::ObjCOneArgSelector: |
| 2747 | case DeclarationName::ObjCMultiArgSelector: |
| 2748 | Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); |
| 2749 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2750 | case DeclarationName::CXXOperatorName: |
| 2751 | assert(Name.getCXXOverloadedOperator() < 0x100 && "Invalid operator ?"); |
| 2752 | Emit8(Out, Name.getCXXOverloadedOperator()); |
| 2753 | break; |
| 2754 | case DeclarationName::CXXLiteralOperatorName: |
| 2755 | Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
| 2756 | break; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2757 | case DeclarationName::CXXConstructorName: |
| 2758 | case DeclarationName::CXXDestructorName: |
| 2759 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2760 | case DeclarationName::CXXUsingDirective: |
| 2761 | break; |
| 2762 | } |
| 2763 | } |
| 2764 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2765 | void EmitData(raw_ostream& Out, key_type_ref, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2766 | data_type Lookup, unsigned DataLen) { |
| 2767 | uint64_t Start = Out.tell(); (void)Start; |
| 2768 | clang::io::Emit16(Out, Lookup.second - Lookup.first); |
| 2769 | for (; Lookup.first != Lookup.second; ++Lookup.first) |
| 2770 | clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); |
| 2771 | |
| 2772 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 2773 | } |
| 2774 | }; |
| 2775 | } // end anonymous namespace |
| 2776 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2777 | /// \brief Write the block containing all of the declaration IDs |
| 2778 | /// visible from the given DeclContext. |
| 2779 | /// |
| 2780 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2781 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2782 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 2783 | DeclContext *DC) { |
| 2784 | if (DC->getPrimaryContext() != DC) |
| 2785 | return 0; |
| 2786 | |
| 2787 | // Since there is no name lookup into functions or methods, don't bother to |
| 2788 | // build a visible-declarations table for these entities. |
| 2789 | if (DC->isFunctionOrMethod()) |
| 2790 | return 0; |
| 2791 | |
| 2792 | // If not in C++, we perform name lookup for the translation unit via the |
| 2793 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 2794 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 2795 | // friend declarations, is there a way to do this without writing the table ? |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2796 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2797 | return 0; |
| 2798 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2799 | // Serialize the contents of the mapping used for lookup. Note that, |
| 2800 | // although we have two very different code paths, the serialized |
| 2801 | // representation is the same for both cases: a declaration name, |
| 2802 | // followed by a size, followed by references to the visible |
| 2803 | // declarations that have that name. |
| 2804 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | c5d3e80 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 2805 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2806 | if (!Map || Map->empty()) |
| 2807 | return 0; |
| 2808 | |
| 2809 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2810 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2811 | |
| 2812 | // Create the on-disk hash table representation. |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2813 | DeclarationName ConversionName; |
| 2814 | llvm::SmallVector<NamedDecl *, 4> ConversionDecls; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2815 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2816 | D != DEnd; ++D) { |
| 2817 | DeclarationName Name = D->first; |
| 2818 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2819 | if (Result.first != Result.second) { |
| 2820 | if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 2821 | // Hash all conversion function names to the same name. The actual |
| 2822 | // type information in conversion function name is not used in the |
| 2823 | // key (since such type information is not stable across different |
| 2824 | // modules), so the intended effect is to coalesce all of the conversion |
| 2825 | // functions under a single key. |
| 2826 | if (!ConversionName) |
| 2827 | ConversionName = Name; |
| 2828 | ConversionDecls.append(Result.first, Result.second); |
| 2829 | continue; |
| 2830 | } |
| 2831 | |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 2832 | Generator.insert(Name, Result, Trait); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2833 | } |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2836 | // Add the conversion functions |
| 2837 | if (!ConversionDecls.empty()) { |
| 2838 | Generator.insert(ConversionName, |
| 2839 | DeclContext::lookup_result(ConversionDecls.begin(), |
| 2840 | ConversionDecls.end()), |
| 2841 | Trait); |
| 2842 | } |
| 2843 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2844 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2845 | SmallString<4096> LookupTable; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2846 | uint32_t BucketOffset; |
| 2847 | { |
| 2848 | llvm::raw_svector_ostream Out(LookupTable); |
| 2849 | // Make sure that no bucket is at offset 0 |
| 2850 | clang::io::Emit32(Out, 0); |
| 2851 | BucketOffset = Generator.Emit(Out, Trait); |
| 2852 | } |
| 2853 | |
| 2854 | // Write the lookup table |
| 2855 | RecordData Record; |
| 2856 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 2857 | Record.push_back(BucketOffset); |
| 2858 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
| 2859 | LookupTable.str()); |
| 2860 | |
| 2861 | Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); |
| 2862 | ++NumVisibleDeclContexts; |
| 2863 | return Offset; |
| 2864 | } |
| 2865 | |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2866 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 2867 | /// |
| 2868 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 2869 | /// DeclContext in a dependent AST file. As such, they only exist for the TU |
Richard Smith | c5d3e80 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 2870 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 2871 | /// enumeration members (in C++11). |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2872 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2873 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 2874 | if (!Map || Map->empty()) |
| 2875 | return; |
| 2876 | |
| 2877 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2878 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2879 | |
| 2880 | // Create the hash table. |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2881 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2882 | D != DEnd; ++D) { |
| 2883 | DeclarationName Name = D->first; |
| 2884 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 2885 | // For any name that appears in this table, the results are complete, i.e. |
| 2886 | // they overwrite results from previous PCHs. Merging is always a mess. |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 2887 | if (Result.first != Result.second) |
| 2888 | Generator.insert(Name, Result, Trait); |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2892 | SmallString<4096> LookupTable; |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2893 | uint32_t BucketOffset; |
| 2894 | { |
| 2895 | llvm::raw_svector_ostream Out(LookupTable); |
| 2896 | // Make sure that no bucket is at offset 0 |
| 2897 | clang::io::Emit32(Out, 0); |
| 2898 | BucketOffset = Generator.Emit(Out, Trait); |
| 2899 | } |
| 2900 | |
| 2901 | // Write the lookup table |
| 2902 | RecordData Record; |
| 2903 | Record.push_back(UPDATE_VISIBLE); |
| 2904 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 2905 | Record.push_back(BucketOffset); |
| 2906 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); |
| 2907 | } |
| 2908 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2909 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 2910 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 2911 | RecordData Record; |
| 2912 | Record.push_back(Opts.fp_contract); |
| 2913 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 2914 | } |
| 2915 | |
| 2916 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 2917 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2918 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2919 | return; |
| 2920 | |
| 2921 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 2922 | RecordData Record; |
| 2923 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 2924 | #include "clang/Basic/OpenCLExtensions.def" |
| 2925 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 2926 | } |
| 2927 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2928 | void ASTWriter::WriteRedeclarations() { |
| 2929 | RecordData LocalRedeclChains; |
| 2930 | SmallVector<serialization::LocalRedeclarationsInfo, 2> LocalRedeclsMap; |
| 2931 | |
| 2932 | for (unsigned I = 0, N = Redeclarations.size(); I != N; ++I) { |
| 2933 | Decl *First = Redeclarations[I]; |
| 2934 | assert(First->getPreviousDecl() == 0 && "Not the first declaration?"); |
| 2935 | |
| 2936 | Decl *MostRecent = First->getMostRecentDecl(); |
| 2937 | |
| 2938 | // If we only have a single declaration, there is no point in storing |
| 2939 | // a redeclaration chain. |
| 2940 | if (First == MostRecent) |
| 2941 | continue; |
| 2942 | |
| 2943 | unsigned Offset = LocalRedeclChains.size(); |
| 2944 | unsigned Size = 0; |
| 2945 | LocalRedeclChains.push_back(0); // Placeholder for the size. |
| 2946 | |
| 2947 | // Collect the set of local redeclarations of this declaration. |
| 2948 | for (Decl *Prev = MostRecent; Prev != First; |
| 2949 | Prev = Prev->getPreviousDecl()) { |
| 2950 | if (!Prev->isFromASTFile()) { |
| 2951 | AddDeclRef(Prev, LocalRedeclChains); |
| 2952 | ++Size; |
| 2953 | } |
| 2954 | } |
| 2955 | LocalRedeclChains[Offset] = Size; |
| 2956 | |
| 2957 | // Reverse the set of local redeclarations, so that we store them in |
| 2958 | // order (since we found them in reverse order). |
| 2959 | std::reverse(LocalRedeclChains.end() - Size, LocalRedeclChains.end()); |
| 2960 | |
| 2961 | // Add the mapping from the first ID to the set of local declarations. |
| 2962 | LocalRedeclarationsInfo Info = { getDeclID(First), Offset }; |
| 2963 | LocalRedeclsMap.push_back(Info); |
| 2964 | |
| 2965 | assert(N == Redeclarations.size() && |
| 2966 | "Deserialized a declaration we shouldn't have"); |
| 2967 | } |
| 2968 | |
| 2969 | if (LocalRedeclChains.empty()) |
| 2970 | return; |
| 2971 | |
| 2972 | // Sort the local redeclarations map by the first declaration ID, |
| 2973 | // since the reader will be performing binary searches on this information. |
| 2974 | llvm::array_pod_sort(LocalRedeclsMap.begin(), LocalRedeclsMap.end()); |
| 2975 | |
| 2976 | // Emit the local redeclarations map. |
| 2977 | using namespace llvm; |
| 2978 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2979 | Abbrev->Add(BitCodeAbbrevOp(LOCAL_REDECLARATIONS_MAP)); |
| 2980 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 2981 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2982 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 2983 | |
| 2984 | RecordData Record; |
| 2985 | Record.push_back(LOCAL_REDECLARATIONS_MAP); |
| 2986 | Record.push_back(LocalRedeclsMap.size()); |
| 2987 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 2988 | reinterpret_cast<char*>(LocalRedeclsMap.data()), |
| 2989 | LocalRedeclsMap.size() * sizeof(LocalRedeclarationsInfo)); |
| 2990 | |
| 2991 | // Emit the redeclaration chains. |
| 2992 | Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedeclChains); |
| 2993 | } |
| 2994 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2995 | void ASTWriter::WriteObjCCategories() { |
| 2996 | llvm::SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
| 2997 | RecordData Categories; |
| 2998 | |
| 2999 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3000 | unsigned Size = 0; |
| 3001 | unsigned StartIndex = Categories.size(); |
| 3002 | |
| 3003 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3004 | |
| 3005 | // Allocate space for the size. |
| 3006 | Categories.push_back(0); |
| 3007 | |
| 3008 | // Add the categories. |
| 3009 | for (ObjCCategoryDecl *Cat = Class->getCategoryList(); |
| 3010 | Cat; Cat = Cat->getNextClassCategory(), ++Size) { |
| 3011 | assert(getDeclID(Cat) != 0 && "Bogus category"); |
| 3012 | AddDeclRef(Cat, Categories); |
| 3013 | } |
| 3014 | |
| 3015 | // Update the size. |
| 3016 | Categories[StartIndex] = Size; |
| 3017 | |
| 3018 | // Record this interface -> category map. |
| 3019 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3020 | CategoriesMap.push_back(CatInfo); |
| 3021 | } |
| 3022 | |
| 3023 | // Sort the categories map by the definition ID, since the reader will be |
| 3024 | // performing binary searches on this information. |
| 3025 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3026 | |
| 3027 | // Emit the categories map. |
| 3028 | using namespace llvm; |
| 3029 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3030 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3031 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3032 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3033 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3034 | |
| 3035 | RecordData Record; |
| 3036 | Record.push_back(OBJC_CATEGORIES_MAP); |
| 3037 | Record.push_back(CategoriesMap.size()); |
| 3038 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3039 | reinterpret_cast<char*>(CategoriesMap.data()), |
| 3040 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
| 3041 | |
| 3042 | // Emit the category lists. |
| 3043 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3044 | } |
| 3045 | |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3046 | void ASTWriter::WriteMergedDecls() { |
| 3047 | if (!Chain || Chain->MergedDecls.empty()) |
| 3048 | return; |
| 3049 | |
| 3050 | RecordData Record; |
| 3051 | for (ASTReader::MergedDeclsMap::iterator I = Chain->MergedDecls.begin(), |
| 3052 | IEnd = Chain->MergedDecls.end(); |
| 3053 | I != IEnd; ++I) { |
Douglas Gregor | b6b60c1 | 2012-01-05 22:27:05 +0000 | [diff] [blame] | 3054 | DeclID CanonID = I->first->isFromASTFile()? I->first->getGlobalID() |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3055 | : getDeclID(I->first); |
| 3056 | assert(CanonID && "Merged declaration not known?"); |
| 3057 | |
| 3058 | Record.push_back(CanonID); |
| 3059 | Record.push_back(I->second.size()); |
| 3060 | Record.append(I->second.begin(), I->second.end()); |
| 3061 | } |
| 3062 | Stream.EmitRecord(MERGED_DECLARATIONS, Record); |
| 3063 | } |
| 3064 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3065 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3066 | // General Serialization Routines |
| 3067 | //===----------------------------------------------------------------------===// |
| 3068 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3069 | /// \brief Write a record containing the given attributes. |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3070 | void ASTWriter::WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4eb9fc0 | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3071 | Record.push_back(Attrs.size()); |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3072 | for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){ |
| 3073 | const Attr * A = *i; |
| 3074 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 768d6ca | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 3075 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3076 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3077 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3078 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3079 | } |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3082 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3083 | Record.push_back(Str.size()); |
| 3084 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 3085 | } |
| 3086 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3087 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 3088 | RecordDataImpl &Record) { |
| 3089 | Record.push_back(Version.getMajor()); |
| 3090 | if (llvm::Optional<unsigned> Minor = Version.getMinor()) |
| 3091 | Record.push_back(*Minor + 1); |
| 3092 | else |
| 3093 | Record.push_back(0); |
| 3094 | if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) |
| 3095 | Record.push_back(*Subminor + 1); |
| 3096 | else |
| 3097 | Record.push_back(0); |
| 3098 | } |
| 3099 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3100 | /// \brief Note that the identifier II occurs at the given offset |
| 3101 | /// within the identifier table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3102 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3103 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3104 | // Only store offsets new to this AST file. Other identifier names are looked |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3105 | // up earlier in the chain and thus don't need an offset. |
| 3106 | if (ID >= FirstIdentID) |
| 3107 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3108 | } |
| 3109 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3110 | /// \brief Note that the selector Sel occurs at the given offset |
| 3111 | /// within the method pool/selector table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3112 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3113 | unsigned ID = SelectorIDs[Sel]; |
| 3114 | assert(ID && "Unknown selector"); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3115 | // Don't record offsets for selectors that are also available in a different |
| 3116 | // file. |
| 3117 | if (ID < FirstSelectorID) |
| 3118 | return; |
| 3119 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3122 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3123 | : Stream(Stream), Context(0), PP(0), Chain(0), WritingModule(0), |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3124 | WritingAST(false), ASTHasCompilerErrors(false), |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3125 | FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3126 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3127 | FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3128 | FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
| 3129 | NextSubmoduleID(FirstSubmoduleID), |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3130 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3131 | CollectedStmts(&StmtsToEmit), |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3132 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3133 | NumVisibleDeclContexts(0), |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3134 | NextCXXBaseSpecifiersID(1), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3135 | DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3136 | DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), |
| 3137 | DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), |
| 3138 | DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3139 | DeclTypedefAbbrev(0), |
| 3140 | DeclVarAbbrev(0), DeclFieldAbbrev(0), |
| 3141 | DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3142 | { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3143 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3144 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3145 | ASTWriter::~ASTWriter() { |
| 3146 | for (FileDeclIDsTy::iterator |
| 3147 | I = FileDeclIDs.begin(), E = FileDeclIDs.end(); I != E; ++I) |
| 3148 | delete I->second; |
| 3149 | } |
| 3150 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3151 | void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 3152 | const std::string &OutputFile, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3153 | Module *WritingModule, StringRef isysroot, |
| 3154 | bool hasErrors) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3155 | WritingAST = true; |
| 3156 | |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3157 | ASTHasCompilerErrors = hasErrors; |
| 3158 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3159 | // Emit the file header. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3160 | Stream.Emit((unsigned)'C', 8); |
| 3161 | Stream.Emit((unsigned)'P', 8); |
| 3162 | Stream.Emit((unsigned)'C', 8); |
| 3163 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 3165 | WriteBlockInfoBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3166 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3167 | Context = &SemaRef.Context; |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3168 | PP = &SemaRef.PP; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3169 | this->WritingModule = WritingModule; |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3170 | WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile, WritingModule); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3171 | Context = 0; |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3172 | PP = 0; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3173 | this->WritingModule = 0; |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3174 | |
| 3175 | WritingAST = false; |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3178 | template<typename Vector> |
| 3179 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 3180 | ASTWriter::RecordData &Record) { |
| 3181 | for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end(); |
| 3182 | I != E; ++I) { |
| 3183 | Writer.AddDeclRef(*I, Record); |
| 3184 | } |
| 3185 | } |
| 3186 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3187 | void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3188 | StringRef isysroot, |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3189 | const std::string &OutputFile, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3190 | Module *WritingModule) { |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3191 | using namespace llvm; |
| 3192 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3193 | // Make sure that the AST reader knows to finalize itself. |
| 3194 | if (Chain) |
| 3195 | Chain->finalizeForWriting(); |
| 3196 | |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3197 | ASTContext &Context = SemaRef.Context; |
| 3198 | Preprocessor &PP = SemaRef.PP; |
| 3199 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3200 | // Set up predefined declaration IDs. |
| 3201 | DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 3202 | if (Context.ObjCIdDecl) |
| 3203 | DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID; |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 3204 | if (Context.ObjCSelDecl) |
| 3205 | DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 3206 | if (Context.ObjCClassDecl) |
| 3207 | DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 3208 | if (Context.ObjCProtocolClassDecl) |
| 3209 | DeclIDs[Context.ObjCProtocolClassDecl] = PREDEF_DECL_OBJC_PROTOCOL_ID; |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 3210 | if (Context.Int128Decl) |
| 3211 | DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; |
| 3212 | if (Context.UInt128Decl) |
| 3213 | DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 3214 | if (Context.ObjCInstanceTypeDecl) |
| 3215 | DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID; |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 3216 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3217 | if (!Chain) { |
| 3218 | // Make sure that we emit IdentifierInfos (and any attached |
| 3219 | // declarations) for builtins. We don't need to do this when we're |
| 3220 | // emitting chained PCH files, because all of the builtins will be |
| 3221 | // in the original PCH file. |
| 3222 | // FIXME: Modules won't like this at all. |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3223 | IdentifierTable &Table = PP.getIdentifierTable(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3224 | SmallVector<const char *, 32> BuiltinNames; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3225 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3226 | Context.getLangOpts().NoBuiltin); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3227 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 3228 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 3229 | } |
| 3230 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3231 | // If there are any out-of-date identifiers, bring them up to date. |
| 3232 | if (ExternalPreprocessorSource *ExtSource = PP.getExternalSource()) { |
| 3233 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 3234 | IDEnd = PP.getIdentifierTable().end(); |
| 3235 | ID != IDEnd; ++ID) |
| 3236 | if (ID->second->isOutOfDate()) |
| 3237 | ExtSource->updateOutOfDateIdentifier(*ID->second); |
| 3238 | } |
| 3239 | |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3240 | // Build a record containing all of the tentative definitions in this file, in |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3241 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3242 | // headers. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3243 | RecordData TentativeDefinitions; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3244 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 3245 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3246 | // Build a record containing all of the file scoped decls in this file. |
| 3247 | RecordData UnusedFileScopedDecls; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3248 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 3249 | UnusedFileScopedDecls); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3251 | // Build a record containing all of the delegating constructors we still need |
| 3252 | // to resolve. |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3253 | RecordData DelegatingCtorDecls; |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 3254 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3255 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3256 | // Write the set of weak, undeclared identifiers. We always write the |
| 3257 | // entire table, since later PCH files in a PCH chain are only interested in |
| 3258 | // the results at the end of the chain. |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3259 | RecordData WeakUndeclaredIdentifiers; |
| 3260 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 3261 | for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3262 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 3263 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 3264 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 3265 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 3266 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 3267 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 3268 | } |
| 3269 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3270 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3271 | // Build a record containing all of the locally-scoped external |
| 3272 | // declarations in this header file. Generally, this record will be |
| 3273 | // empty. |
| 3274 | RecordData LocallyScopedExternalDecls; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3275 | // FIXME: This is filling in the AST file in densemap order which is |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3276 | // nondeterminstic! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3277 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3278 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 3279 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3280 | TD != TDEnd; ++TD) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3281 | if (!TD->second->isFromASTFile()) |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3282 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 3283 | } |
| 3284 | |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3285 | // Build a record containing all of the ext_vector declarations. |
| 3286 | RecordData ExtVectorDecls; |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 3287 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3288 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3289 | // Build a record containing all of the VTable uses information. |
| 3290 | RecordData VTableUses; |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3291 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3292 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 3293 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 3294 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 3295 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 3296 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | // Build a record containing all of dynamic classes declarations. |
| 3300 | RecordData DynamicClasses; |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 3301 | AddLazyVectorDecls(*this, SemaRef.DynamicClasses, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3302 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3303 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3304 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3305 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3306 | I = SemaRef.PendingInstantiations.begin(), |
| 3307 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 3308 | AddDeclRef(I->first, PendingInstantiations); |
| 3309 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3310 | } |
| 3311 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 3312 | "There are local ones at end of translation unit!"); |
| 3313 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3314 | // Build a record containing some declaration references. |
| 3315 | RecordData SemaDeclRefs; |
| 3316 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 3317 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 3318 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 3319 | } |
| 3320 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3321 | RecordData CUDASpecialDeclRefs; |
| 3322 | if (Context.getcudaConfigureCallDecl()) { |
| 3323 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 3324 | } |
| 3325 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3326 | // Build a record containing all of the known namespaces. |
| 3327 | RecordData KnownNamespaces; |
| 3328 | for (llvm::DenseMap<NamespaceDecl*, bool>::iterator |
| 3329 | I = SemaRef.KnownNamespaces.begin(), |
| 3330 | IEnd = SemaRef.KnownNamespaces.end(); |
| 3331 | I != IEnd; ++I) { |
| 3332 | if (!I->second) |
| 3333 | AddDeclRef(I->first, KnownNamespaces); |
| 3334 | } |
| 3335 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3336 | // Write the remaining AST contents. |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3337 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3338 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 3339 | WriteMetadata(Context, isysroot, OutputFile); |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3340 | WriteLanguageOptions(Context.getLangOpts()); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3341 | if (StatCalls && isysroot.empty()) |
Douglas Gregor | dd41ed5 | 2010-07-12 23:48:14 +0000 | [diff] [blame] | 3342 | WriteStatCache(*StatCalls); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3343 | |
| 3344 | // Create a lexical update block containing all of the declarations in the |
| 3345 | // translation unit that do not come from other AST files. |
| 3346 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
| 3347 | SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
| 3348 | for (DeclContext::decl_iterator I = TU->noload_decls_begin(), |
| 3349 | E = TU->noload_decls_end(); |
| 3350 | I != E; ++I) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3351 | if (!(*I)->isFromASTFile()) |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3352 | NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 3356 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 3357 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3358 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 3359 | Record.clear(); |
| 3360 | Record.push_back(TU_UPDATE_LEXICAL); |
| 3361 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 3362 | data(NewGlobalDecls)); |
| 3363 | |
| 3364 | // And a visible updates block for the translation unit. |
| 3365 | Abv = new llvm::BitCodeAbbrev(); |
| 3366 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 3367 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3368 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 3369 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3370 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 3371 | WriteDeclContextVisibleUpdate(TU); |
| 3372 | |
| 3373 | // If the translation unit has an anonymous namespace, and we don't already |
| 3374 | // have an update block for it, write it as an update block. |
| 3375 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 3376 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
| 3377 | if (Record.empty()) { |
| 3378 | Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3379 | Record.push_back(reinterpret_cast<uint64_t>(NS)); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3380 | } |
| 3381 | } |
| 3382 | |
Argyrios Kyrtzidis | 67bc4ba | 2011-11-14 04:52:24 +0000 | [diff] [blame] | 3383 | // Resolve any declaration pointers within the declaration updates block. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3384 | ResolveDeclUpdatesBlocks(); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3385 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3386 | // Form the record of special types. |
| 3387 | RecordData SpecialTypes; |
| 3388 | AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3389 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3390 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 3391 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 3392 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 3393 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 3394 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3395 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 3396 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3397 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3398 | // Keep writing types and declarations until all types and |
| 3399 | // declarations have been written. |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3400 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3401 | WriteDeclsBlockAbbrevs(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3402 | for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), |
| 3403 | E = DeclsToRewrite.end(); |
| 3404 | I != E; ++I) |
| 3405 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3406 | while (!DeclTypesToEmit.empty()) { |
| 3407 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 3408 | DeclTypesToEmit.pop(); |
| 3409 | if (DOT.isType()) |
| 3410 | WriteType(DOT.getType()); |
| 3411 | else |
| 3412 | WriteDecl(Context, DOT.getDecl()); |
| 3413 | } |
| 3414 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3415 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3416 | WriteFileDeclIDsMap(); |
| 3417 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
| 3418 | |
| 3419 | if (Chain) { |
| 3420 | // Write the mapping information describing our module dependencies and how |
| 3421 | // each of those modules were mapped into our own offset/ID space, so that |
| 3422 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 3423 | // The map consists solely of a blob with the following format: |
| 3424 | // *(module-name-len:i16 module-name:len*i8 |
| 3425 | // source-location-offset:i32 |
| 3426 | // identifier-id:i32 |
| 3427 | // preprocessed-entity-id:i32 |
| 3428 | // macro-definition-id:i32 |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3429 | // submodule-id:i32 |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3430 | // selector-id:i32 |
| 3431 | // declaration-id:i32 |
| 3432 | // c++-base-specifiers-id:i32 |
| 3433 | // type-id:i32) |
| 3434 | // |
| 3435 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3436 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 3437 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3438 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3439 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3440 | { |
| 3441 | llvm::raw_svector_ostream Out(Buffer); |
| 3442 | for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3443 | MEnd = Chain->ModuleMgr.end(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3444 | M != MEnd; ++M) { |
| 3445 | StringRef FileName = (*M)->FileName; |
| 3446 | io::Emit16(Out, FileName.size()); |
| 3447 | Out.write(FileName.data(), FileName.size()); |
| 3448 | io::Emit32(Out, (*M)->SLocEntryBaseOffset); |
| 3449 | io::Emit32(Out, (*M)->BaseIdentifierID); |
| 3450 | io::Emit32(Out, (*M)->BasePreprocessedEntityID); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3451 | io::Emit32(Out, (*M)->BaseSubmoduleID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3452 | io::Emit32(Out, (*M)->BaseSelectorID); |
| 3453 | io::Emit32(Out, (*M)->BaseDeclID); |
| 3454 | io::Emit32(Out, (*M)->BaseTypeIndex); |
| 3455 | } |
| 3456 | } |
| 3457 | Record.clear(); |
| 3458 | Record.push_back(MODULE_OFFSET_MAP); |
| 3459 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 3460 | Buffer.data(), Buffer.size()); |
| 3461 | } |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3462 | WritePreprocessor(PP, WritingModule != 0); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3463 | WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3464 | WriteSelectors(SemaRef); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3465 | WriteReferencedSelectorsPool(SemaRef); |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3466 | WriteIdentifierTable(PP, SemaRef.IdResolver, WritingModule != 0); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3467 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 3468 | WriteOpenCLExtensions(SemaRef); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3469 | |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3470 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3471 | WritePragmaDiagnosticMappings(Context.getDiagnostics()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3472 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 3473 | WriteCXXBaseSpecifiersOffsets(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3474 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3475 | // If we're emitting a module, write out the submodule information. |
| 3476 | if (WritingModule) |
| 3477 | WriteSubmodules(WritingModule); |
| 3478 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3479 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 3480 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3481 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3482 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3483 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3484 | |
| 3485 | // Write the record containing tentative definitions. |
| 3486 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3487 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3488 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3489 | // Write the record containing unused file scoped decls. |
| 3490 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3491 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3492 | |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3493 | // Write the record containing weak undeclared identifiers. |
| 3494 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3495 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3496 | WeakUndeclaredIdentifiers); |
| 3497 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3498 | // Write the record containing locally-scoped external definitions. |
| 3499 | if (!LocallyScopedExternalDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3500 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3501 | LocallyScopedExternalDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3502 | |
| 3503 | // Write the record containing ext_vector type names. |
| 3504 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3505 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3507 | // Write the record containing VTable uses information. |
| 3508 | if (!VTableUses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3509 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3510 | |
| 3511 | // Write the record containing dynamic classes declarations. |
| 3512 | if (!DynamicClasses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3513 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3514 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3515 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3516 | if (!PendingInstantiations.empty()) |
| 3517 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3518 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3519 | // Write the record containing declaration references of Sema. |
| 3520 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3521 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3522 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3523 | // Write the record containing CUDA-specific declaration references. |
| 3524 | if (!CUDASpecialDeclRefs.empty()) |
| 3525 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3526 | |
| 3527 | // Write the delegating constructors. |
| 3528 | if (!DelegatingCtorDecls.empty()) |
| 3529 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3531 | // Write the known namespaces. |
| 3532 | if (!KnownNamespaces.empty()) |
| 3533 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
| 3534 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3535 | // Write the visible updates to DeclContexts. |
| 3536 | for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |
| 3537 | I = UpdatedDeclContexts.begin(), |
| 3538 | E = UpdatedDeclContexts.end(); |
| 3539 | I != E; ++I) |
| 3540 | WriteDeclContextVisibleUpdate(*I); |
| 3541 | |
Douglas Gregor | c5e0f9b | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 3542 | if (!WritingModule) { |
| 3543 | // Write the submodules that were imported, if any. |
| 3544 | RecordData ImportedModules; |
| 3545 | for (ASTContext::import_iterator I = Context.local_import_begin(), |
| 3546 | IEnd = Context.local_import_end(); |
| 3547 | I != IEnd; ++I) { |
| 3548 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
| 3549 | ImportedModules.push_back(SubmoduleIDs[I->getImportedModule()]); |
| 3550 | } |
| 3551 | if (!ImportedModules.empty()) { |
| 3552 | // Sort module IDs. |
| 3553 | llvm::array_pod_sort(ImportedModules.begin(), ImportedModules.end()); |
| 3554 | |
| 3555 | // Unique module IDs. |
| 3556 | ImportedModules.erase(std::unique(ImportedModules.begin(), |
| 3557 | ImportedModules.end()), |
| 3558 | ImportedModules.end()); |
| 3559 | |
| 3560 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 3561 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3564 | WriteDeclUpdatesBlocks(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3565 | WriteDeclReplacementsBlock(); |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3566 | WriteMergedDecls(); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3567 | WriteRedeclarations(); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3568 | WriteObjCCategories(); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3570 | // Some simple statistics |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3571 | Record.clear(); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3572 | Record.push_back(NumStatements); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 3573 | Record.push_back(NumMacros); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3574 | Record.push_back(NumLexicalDeclContexts); |
| 3575 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3576 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3577 | Stream.ExitBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3580 | /// \brief Go through the declaration update blocks and resolve declaration |
| 3581 | /// pointers into declaration IDs. |
| 3582 | void ASTWriter::ResolveDeclUpdatesBlocks() { |
| 3583 | for (DeclUpdateMap::iterator |
| 3584 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3585 | const Decl *D = I->first; |
| 3586 | UpdateRecord &URec = I->second; |
| 3587 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3588 | if (isRewritten(D)) |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3589 | continue; // The decl will be written completely |
| 3590 | |
| 3591 | unsigned Idx = 0, N = URec.size(); |
| 3592 | while (Idx < N) { |
| 3593 | switch ((DeclUpdateKind)URec[Idx++]) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3594 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 3595 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 3596 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
| 3597 | URec[Idx] = GetDeclRef(reinterpret_cast<Decl *>(URec[Idx])); |
| 3598 | ++Idx; |
| 3599 | break; |
| 3600 | |
| 3601 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
| 3602 | ++Idx; |
| 3603 | break; |
| 3604 | } |
| 3605 | } |
| 3606 | } |
| 3607 | } |
| 3608 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3609 | void ASTWriter::WriteDeclUpdatesBlocks() { |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3610 | if (DeclUpdates.empty()) |
| 3611 | return; |
| 3612 | |
| 3613 | RecordData OffsetsRecord; |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3614 | Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3615 | for (DeclUpdateMap::iterator |
| 3616 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3617 | const Decl *D = I->first; |
| 3618 | UpdateRecord &URec = I->second; |
| 3619 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3620 | if (isRewritten(D)) |
Argyrios Kyrtzidis | ba901b5 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 3621 | continue; // The decl will be written completely,no need to store updates. |
| 3622 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3623 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 3624 | Stream.EmitRecord(DECL_UPDATES, URec); |
| 3625 | |
| 3626 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 3627 | OffsetsRecord.push_back(Offset); |
| 3628 | } |
| 3629 | Stream.ExitBlock(); |
| 3630 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); |
| 3631 | } |
| 3632 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3633 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3634 | if (ReplacedDecls.empty()) |
| 3635 | return; |
| 3636 | |
| 3637 | RecordData Record; |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 3638 | for (SmallVector<ReplacedDeclInfo, 16>::iterator |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3639 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 3640 | Record.push_back(I->ID); |
| 3641 | Record.push_back(I->Offset); |
| 3642 | Record.push_back(I->Loc); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3643 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3644 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3645 | } |
| 3646 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3647 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3648 | Record.push_back(Loc.getRawEncoding()); |
| 3649 | } |
| 3650 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3651 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3652 | AddSourceLocation(Range.getBegin(), Record); |
| 3653 | AddSourceLocation(Range.getEnd(), Record); |
| 3654 | } |
| 3655 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3656 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3657 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3658 | const uint64_t *Words = Value.getRawData(); |
| 3659 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3660 | } |
| 3661 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3662 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3663 | Record.push_back(Value.isUnsigned()); |
| 3664 | AddAPInt(Value, Record); |
| 3665 | } |
| 3666 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3667 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 3668 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 3669 | } |
| 3670 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3671 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3672 | Record.push_back(getIdentifierRef(II)); |
| 3673 | } |
| 3674 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3675 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3676 | if (II == 0) |
| 3677 | return 0; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3678 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3679 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3680 | if (ID == 0) |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3681 | ID = NextIdentID++; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3682 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3683 | } |
| 3684 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3685 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3686 | Record.push_back(getSelectorRef(SelRef)); |
| 3687 | } |
| 3688 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3689 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3690 | if (Sel.getAsOpaquePtr() == 0) { |
| 3691 | return 0; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3692 | } |
| 3693 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3694 | SelectorID &SID = SelectorIDs[Sel]; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3695 | if (SID == 0 && Chain) { |
| 3696 | // This might trigger a ReadSelector callback, which will set the ID for |
| 3697 | // this selector. |
| 3698 | Chain->LoadSelector(Sel); |
| 3699 | } |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3700 | if (SID == 0) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3701 | SID = NextSelectorID++; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3702 | } |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3703 | return SID; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3704 | } |
| 3705 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3706 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 3707 | AddDeclRef(Temp->getDestructor(), Record); |
| 3708 | } |
| 3709 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3710 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
| 3711 | CXXBaseSpecifier const *BasesEnd, |
| 3712 | RecordDataImpl &Record) { |
| 3713 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 3714 | CXXBaseSpecifiersToWrite.push_back( |
| 3715 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 3716 | Bases, BasesEnd)); |
| 3717 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 3718 | } |
| 3719 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3720 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3721 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3722 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3723 | switch (Kind) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3724 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3725 | AddStmt(Arg.getAsExpr()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3726 | break; |
| 3727 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3728 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3729 | break; |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3730 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3731 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3732 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3733 | break; |
| 3734 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3735 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3736 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3737 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3738 | break; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3739 | case TemplateArgument::Null: |
| 3740 | case TemplateArgument::Integral: |
| 3741 | case TemplateArgument::Declaration: |
| 3742 | case TemplateArgument::Pack: |
| 3743 | break; |
| 3744 | } |
| 3745 | } |
| 3746 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3747 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3748 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3749 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3750 | |
| 3751 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 3752 | bool InfoHasSameExpr |
| 3753 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 3754 | Record.push_back(InfoHasSameExpr); |
| 3755 | if (InfoHasSameExpr) |
| 3756 | return; // Avoid storing the same expr twice. |
| 3757 | } |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3758 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 3759 | Record); |
| 3760 | } |
| 3761 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3762 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 3763 | RecordDataImpl &Record) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3764 | if (TInfo == 0) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3765 | AddTypeRef(QualType(), Record); |
| 3766 | return; |
| 3767 | } |
| 3768 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3769 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 3770 | } |
| 3771 | |
| 3772 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 3773 | AddTypeRef(TL.getType(), Record); |
| 3774 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3775 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3776 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3777 | TLW.Visit(TL); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3780 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 7fb3518 | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 3781 | Record.push_back(GetOrCreateTypeID(T)); |
| 3782 | } |
| 3783 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3784 | TypeID ASTWriter::GetOrCreateTypeID( QualType T) { |
| 3785 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3786 | std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); |
| 3787 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3788 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3789 | TypeID ASTWriter::getTypeID(QualType T) const { |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3790 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3791 | std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { |
| 3795 | if (T.isNull()) |
| 3796 | return TypeIdx(); |
| 3797 | assert(!T.getLocalFastQualifiers()); |
| 3798 | |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 3799 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3800 | if (Idx.getIndex() == 0) { |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3801 | // We haven't seen this type before. Assign it a new ID and put it |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3802 | // into the queue of types to emit. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3803 | Idx = TypeIdx(NextTypeID++); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3804 | DeclTypesToEmit.push(T); |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3805 | } |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3806 | return Idx; |
| 3807 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3808 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3809 | TypeIdx ASTWriter::getTypeIdx(QualType T) const { |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3810 | if (T.isNull()) |
| 3811 | return TypeIdx(); |
| 3812 | assert(!T.getLocalFastQualifiers()); |
| 3813 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3814 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3815 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 3816 | return I->second; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3819 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3820 | Record.push_back(GetDeclRef(D)); |
| 3821 | } |
| 3822 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3823 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3824 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
| 3825 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3826 | if (D == 0) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3827 | return 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3828 | } |
Douglas Gregor | 1c7946a | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 3829 | |
| 3830 | // If D comes from an AST file, its declaration ID is already known and |
| 3831 | // fixed. |
| 3832 | if (D->isFromASTFile()) |
| 3833 | return D->getGlobalID(); |
| 3834 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3835 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3836 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3837 | if (ID == 0) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3838 | // We haven't seen this declaration before. Give it a new ID and |
| 3839 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3840 | ID = NextDeclID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3841 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3844 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3845 | } |
| 3846 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3847 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3848 | if (D == 0) |
| 3849 | return 0; |
| 3850 | |
Douglas Gregor | 1c7946a | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 3851 | // If D comes from an AST file, its declaration ID is already known and |
| 3852 | // fixed. |
| 3853 | if (D->isFromASTFile()) |
| 3854 | return D->getGlobalID(); |
| 3855 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3856 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 3857 | return DeclIDs[D]; |
| 3858 | } |
| 3859 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3860 | static inline bool compLocDecl(std::pair<unsigned, serialization::DeclID> L, |
| 3861 | std::pair<unsigned, serialization::DeclID> R) { |
| 3862 | return L.first < R.first; |
| 3863 | } |
| 3864 | |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 3865 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3866 | assert(ID); |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 3867 | assert(D); |
| 3868 | |
| 3869 | SourceLocation Loc = D->getLocation(); |
| 3870 | if (Loc.isInvalid()) |
| 3871 | return; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3872 | |
| 3873 | // We only keep track of the file-level declarations of each file. |
| 3874 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 3875 | return; |
Argyrios Kyrtzidis | 69015c2 | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 3876 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 3877 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | 8cceefa | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 3878 | if (isa<ParmVarDecl>(D)) |
| 3879 | return; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3880 | |
| 3881 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 3882 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3883 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 3884 | FileID FID; |
| 3885 | unsigned Offset; |
| 3886 | llvm::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3887 | if (FID.isInvalid()) |
| 3888 | return; |
| 3889 | const SrcMgr::SLocEntry *Entry = &SM.getSLocEntry(FID); |
| 3890 | assert(Entry->isFile()); |
| 3891 | |
| 3892 | DeclIDInFileInfo *&Info = FileDeclIDs[Entry]; |
| 3893 | if (!Info) |
| 3894 | Info = new DeclIDInFileInfo(); |
| 3895 | |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 3896 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3897 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 3898 | |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 3899 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3900 | Decls.push_back(LocDecl); |
| 3901 | return; |
| 3902 | } |
| 3903 | |
| 3904 | LocDeclIDsTy::iterator |
| 3905 | I = std::upper_bound(Decls.begin(), Decls.end(), LocDecl, compLocDecl); |
| 3906 | |
| 3907 | Decls.insert(I, LocDecl); |
| 3908 | } |
| 3909 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3910 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 3911 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3912 | Record.push_back(Name.getNameKind()); |
| 3913 | switch (Name.getNameKind()) { |
| 3914 | case DeclarationName::Identifier: |
| 3915 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 3916 | break; |
| 3917 | |
| 3918 | case DeclarationName::ObjCZeroArgSelector: |
| 3919 | case DeclarationName::ObjCOneArgSelector: |
| 3920 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3921 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3922 | break; |
| 3923 | |
| 3924 | case DeclarationName::CXXConstructorName: |
| 3925 | case DeclarationName::CXXDestructorName: |
| 3926 | case DeclarationName::CXXConversionFunctionName: |
| 3927 | AddTypeRef(Name.getCXXNameType(), Record); |
| 3928 | break; |
| 3929 | |
| 3930 | case DeclarationName::CXXOperatorName: |
| 3931 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 3932 | break; |
| 3933 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3934 | case DeclarationName::CXXLiteralOperatorName: |
| 3935 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 3936 | break; |
| 3937 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3938 | case DeclarationName::CXXUsingDirective: |
| 3939 | // No extra data to emit |
| 3940 | break; |
| 3941 | } |
| 3942 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3943 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3944 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3945 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3946 | switch (Name.getNameKind()) { |
| 3947 | case DeclarationName::CXXConstructorName: |
| 3948 | case DeclarationName::CXXDestructorName: |
| 3949 | case DeclarationName::CXXConversionFunctionName: |
| 3950 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 3951 | break; |
| 3952 | |
| 3953 | case DeclarationName::CXXOperatorName: |
| 3954 | AddSourceLocation( |
| 3955 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 3956 | Record); |
| 3957 | AddSourceLocation( |
| 3958 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 3959 | Record); |
| 3960 | break; |
| 3961 | |
| 3962 | case DeclarationName::CXXLiteralOperatorName: |
| 3963 | AddSourceLocation( |
| 3964 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 3965 | Record); |
| 3966 | break; |
| 3967 | |
| 3968 | case DeclarationName::Identifier: |
| 3969 | case DeclarationName::ObjCZeroArgSelector: |
| 3970 | case DeclarationName::ObjCOneArgSelector: |
| 3971 | case DeclarationName::ObjCMultiArgSelector: |
| 3972 | case DeclarationName::CXXUsingDirective: |
| 3973 | break; |
| 3974 | } |
| 3975 | } |
| 3976 | |
| 3977 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3978 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3979 | AddDeclarationName(NameInfo.getName(), Record); |
| 3980 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 3981 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 3982 | } |
| 3983 | |
| 3984 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3985 | RecordDataImpl &Record) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3986 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3987 | Record.push_back(Info.NumTemplParamLists); |
| 3988 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 3989 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 3990 | } |
| 3991 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3992 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3993 | RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3994 | // Nested name specifiers usually aren't too long. I think that 8 would |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 3995 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3996 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3997 | |
| 3998 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 3999 | while (NNS) { |
| 4000 | NestedNames.push_back(NNS); |
| 4001 | NNS = NNS->getPrefix(); |
| 4002 | } |
| 4003 | |
| 4004 | Record.push_back(NestedNames.size()); |
| 4005 | while(!NestedNames.empty()) { |
| 4006 | NNS = NestedNames.pop_back_val(); |
| 4007 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 4008 | Record.push_back(Kind); |
| 4009 | switch (Kind) { |
| 4010 | case NestedNameSpecifier::Identifier: |
| 4011 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 4012 | break; |
| 4013 | |
| 4014 | case NestedNameSpecifier::Namespace: |
| 4015 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 4016 | break; |
| 4017 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4018 | case NestedNameSpecifier::NamespaceAlias: |
| 4019 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 4020 | break; |
| 4021 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4022 | case NestedNameSpecifier::TypeSpec: |
| 4023 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4024 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 4025 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4026 | break; |
| 4027 | |
| 4028 | case NestedNameSpecifier::Global: |
| 4029 | // Don't need to write an associated value. |
| 4030 | break; |
| 4031 | } |
| 4032 | } |
| 4033 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4034 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4035 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 4036 | RecordDataImpl &Record) { |
| 4037 | // Nested name specifiers usually aren't too long. I think that 8 would |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 4038 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4039 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4040 | |
| 4041 | // Push each of the nested-name-specifiers's onto a stack for |
| 4042 | // serialization in reverse order. |
| 4043 | while (NNS) { |
| 4044 | NestedNames.push_back(NNS); |
| 4045 | NNS = NNS.getPrefix(); |
| 4046 | } |
| 4047 | |
| 4048 | Record.push_back(NestedNames.size()); |
| 4049 | while(!NestedNames.empty()) { |
| 4050 | NNS = NestedNames.pop_back_val(); |
| 4051 | NestedNameSpecifier::SpecifierKind Kind |
| 4052 | = NNS.getNestedNameSpecifier()->getKind(); |
| 4053 | Record.push_back(Kind); |
| 4054 | switch (Kind) { |
| 4055 | case NestedNameSpecifier::Identifier: |
| 4056 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 4057 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4058 | break; |
| 4059 | |
| 4060 | case NestedNameSpecifier::Namespace: |
| 4061 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 4062 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4063 | break; |
| 4064 | |
| 4065 | case NestedNameSpecifier::NamespaceAlias: |
| 4066 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 4067 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4068 | break; |
| 4069 | |
| 4070 | case NestedNameSpecifier::TypeSpec: |
| 4071 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4072 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4073 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 4074 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4075 | break; |
| 4076 | |
| 4077 | case NestedNameSpecifier::Global: |
| 4078 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4079 | break; |
| 4080 | } |
| 4081 | } |
| 4082 | } |
| 4083 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4084 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4085 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4086 | Record.push_back(Kind); |
| 4087 | switch (Kind) { |
| 4088 | case TemplateName::Template: |
| 4089 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 4090 | break; |
| 4091 | |
| 4092 | case TemplateName::OverloadedTemplate: { |
| 4093 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 4094 | Record.push_back(OvT->size()); |
| 4095 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 4096 | I != E; ++I) |
| 4097 | AddDeclRef(*I, Record); |
| 4098 | break; |
| 4099 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4100 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4101 | case TemplateName::QualifiedTemplate: { |
| 4102 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 4103 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 4104 | Record.push_back(QualT->hasTemplateKeyword()); |
| 4105 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 4106 | break; |
| 4107 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4108 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4109 | case TemplateName::DependentTemplate: { |
| 4110 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 4111 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 4112 | Record.push_back(DepT->isIdentifier()); |
| 4113 | if (DepT->isIdentifier()) |
| 4114 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 4115 | else |
| 4116 | Record.push_back(DepT->getOperator()); |
| 4117 | break; |
| 4118 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4119 | |
| 4120 | case TemplateName::SubstTemplateTemplateParm: { |
| 4121 | SubstTemplateTemplateParmStorage *subst |
| 4122 | = Name.getAsSubstTemplateTemplateParm(); |
| 4123 | AddDeclRef(subst->getParameter(), Record); |
| 4124 | AddTemplateName(subst->getReplacement(), Record); |
| 4125 | break; |
| 4126 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4127 | |
| 4128 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4129 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 4130 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 4131 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 4132 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 4133 | break; |
| 4134 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4135 | } |
| 4136 | } |
| 4137 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4138 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4139 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4140 | Record.push_back(Arg.getKind()); |
| 4141 | switch (Arg.getKind()) { |
| 4142 | case TemplateArgument::Null: |
| 4143 | break; |
| 4144 | case TemplateArgument::Type: |
| 4145 | AddTypeRef(Arg.getAsType(), Record); |
| 4146 | break; |
| 4147 | case TemplateArgument::Declaration: |
| 4148 | AddDeclRef(Arg.getAsDecl(), Record); |
| 4149 | break; |
| 4150 | case TemplateArgument::Integral: |
| 4151 | AddAPSInt(*Arg.getAsIntegral(), Record); |
| 4152 | AddTypeRef(Arg.getIntegralType(), Record); |
| 4153 | break; |
| 4154 | case TemplateArgument::Template: |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4155 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 4156 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4157 | case TemplateArgument::TemplateExpansion: |
| 4158 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4159 | if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
| 4160 | Record.push_back(*NumExpansions + 1); |
| 4161 | else |
| 4162 | Record.push_back(0); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4163 | break; |
| 4164 | case TemplateArgument::Expression: |
| 4165 | AddStmt(Arg.getAsExpr()); |
| 4166 | break; |
| 4167 | case TemplateArgument::Pack: |
| 4168 | Record.push_back(Arg.pack_size()); |
| 4169 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 4170 | I != E; ++I) |
| 4171 | AddTemplateArgument(*I, Record); |
| 4172 | break; |
| 4173 | } |
| 4174 | } |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4175 | |
| 4176 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4177 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4178 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4179 | assert(TemplateParams && "No TemplateParams!"); |
| 4180 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 4181 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 4182 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 4183 | Record.push_back(TemplateParams->size()); |
| 4184 | for (TemplateParameterList::const_iterator |
| 4185 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 4186 | P != PEnd; ++P) |
| 4187 | AddDeclRef(*P, Record); |
| 4188 | } |
| 4189 | |
| 4190 | /// \brief Emit a template argument list. |
| 4191 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4192 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4193 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4194 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4195 | Record.push_back(TemplateArgs->size()); |
| 4196 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4197 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 4198 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4199 | |
| 4200 | |
| 4201 | void |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4202 | ASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4203 | Record.push_back(Set.size()); |
| 4204 | for (UnresolvedSetImpl::const_iterator |
| 4205 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 4206 | AddDeclRef(I.getDecl(), Record); |
| 4207 | Record.push_back(I.getAccess()); |
| 4208 | } |
| 4209 | } |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4210 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4211 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4212 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4213 | Record.push_back(Base.isVirtual()); |
| 4214 | Record.push_back(Base.isBaseOfClass()); |
| 4215 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4216 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4217 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4218 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4219 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 4220 | : SourceLocation(), |
| 4221 | Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4222 | } |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4223 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4224 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 4225 | RecordData Record; |
| 4226 | for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { |
| 4227 | Record.clear(); |
| 4228 | |
| 4229 | // Record the offset of this base-specifier set. |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4230 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4231 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 4232 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 4233 | else { |
| 4234 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 4235 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 4236 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 4237 | } |
| 4238 | |
| 4239 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 4240 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 4241 | Record.push_back(BEnd - B); |
| 4242 | for (; B != BEnd; ++B) |
| 4243 | AddCXXBaseSpecifier(*B, Record); |
| 4244 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | acec34b | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 4245 | |
| 4246 | // Flush any expressions that were written as part of the base specifiers. |
| 4247 | FlushStmts(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | CXXBaseSpecifiersToWrite.clear(); |
| 4251 | } |
| 4252 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4253 | void ASTWriter::AddCXXCtorInitializers( |
| 4254 | const CXXCtorInitializer * const *CtorInitializers, |
| 4255 | unsigned NumCtorInitializers, |
| 4256 | RecordDataImpl &Record) { |
| 4257 | Record.push_back(NumCtorInitializers); |
| 4258 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 4259 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4260 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4261 | if (Init->isBaseInitializer()) { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4262 | Record.push_back(CTOR_INITIALIZER_BASE); |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4263 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4264 | Record.push_back(Init->isBaseVirtual()); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4265 | } else if (Init->isDelegatingInitializer()) { |
| 4266 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4267 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4268 | } else if (Init->isMemberInitializer()){ |
| 4269 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 4270 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4271 | } else { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4272 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 4273 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4274 | } |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4275 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4276 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 4277 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4278 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 4279 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 4280 | Record.push_back(Init->isWritten()); |
| 4281 | if (Init->isWritten()) { |
| 4282 | Record.push_back(Init->getSourceOrder()); |
| 4283 | } else { |
| 4284 | Record.push_back(Init->getNumArrayIndices()); |
| 4285 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 4286 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 4287 | } |
| 4288 | } |
| 4289 | } |
| 4290 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4291 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
| 4292 | assert(D->DefinitionData); |
| 4293 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4294 | Record.push_back(Data.IsLambda); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4295 | Record.push_back(Data.UserDeclaredConstructor); |
| 4296 | Record.push_back(Data.UserDeclaredCopyConstructor); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4297 | Record.push_back(Data.UserDeclaredMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4298 | Record.push_back(Data.UserDeclaredCopyAssignment); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4299 | Record.push_back(Data.UserDeclaredMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4300 | Record.push_back(Data.UserDeclaredDestructor); |
| 4301 | Record.push_back(Data.Aggregate); |
| 4302 | Record.push_back(Data.PlainOldData); |
| 4303 | Record.push_back(Data.Empty); |
| 4304 | Record.push_back(Data.Polymorphic); |
| 4305 | Record.push_back(Data.Abstract); |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 4306 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 4307 | Record.push_back(Data.HasNoNonEmptyBases); |
| 4308 | Record.push_back(Data.HasPrivateFields); |
| 4309 | Record.push_back(Data.HasProtectedFields); |
| 4310 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 4311 | Record.push_back(Data.HasMutableFields); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4312 | Record.push_back(Data.HasOnlyCMembers); |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 4313 | Record.push_back(Data.HasTrivialDefaultConstructor); |
Richard Smith | 6b8bc07 | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 4314 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4315 | Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
| 4316 | Record.push_back(Data.DefaultedCopyConstructorIsConstexpr); |
| 4317 | Record.push_back(Data.DefaultedMoveConstructorIsConstexpr); |
| 4318 | Record.push_back(Data.HasConstexprDefaultConstructor); |
| 4319 | Record.push_back(Data.HasConstexprCopyConstructor); |
| 4320 | Record.push_back(Data.HasConstexprMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4321 | Record.push_back(Data.HasTrivialCopyConstructor); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 4322 | Record.push_back(Data.HasTrivialMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4323 | Record.push_back(Data.HasTrivialCopyAssignment); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 4324 | Record.push_back(Data.HasTrivialMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4325 | Record.push_back(Data.HasTrivialDestructor); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4326 | Record.push_back(Data.HasIrrelevantDestructor); |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 4327 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4328 | Record.push_back(Data.ComputedVisibleConversions); |
Sean Hunt | cdee3fe | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 4329 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4330 | Record.push_back(Data.DeclaredDefaultConstructor); |
| 4331 | Record.push_back(Data.DeclaredCopyConstructor); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4332 | Record.push_back(Data.DeclaredMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4333 | Record.push_back(Data.DeclaredCopyAssignment); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4334 | Record.push_back(Data.DeclaredMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4335 | Record.push_back(Data.DeclaredDestructor); |
Sebastian Redl | 14c3633 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 4336 | Record.push_back(Data.FailedImplicitMoveConstructor); |
| 4337 | Record.push_back(Data.FailedImplicitMoveAssignment); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4338 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4339 | |
| 4340 | Record.push_back(Data.NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4341 | if (Data.NumBases > 0) |
| 4342 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 4343 | Record); |
| 4344 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4345 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 4346 | Record.push_back(Data.NumVBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4347 | if (Data.NumVBases > 0) |
| 4348 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 4349 | Record); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4350 | |
| 4351 | AddUnresolvedSet(Data.Conversions, Record); |
| 4352 | AddUnresolvedSet(Data.VisibleConversions, Record); |
| 4353 | // Data.Definition is the owning decl, no need to write it. |
| 4354 | AddDeclRef(Data.FirstFriend, Record); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4355 | |
| 4356 | // Add lambda-specific data. |
| 4357 | if (Data.IsLambda) { |
| 4358 | CXXRecordDecl::LambdaDefinitionData &Lambda = D->getLambdaData(); |
Douglas Gregor | f4b7de1 | 2012-02-21 19:11:17 +0000 | [diff] [blame] | 4359 | Record.push_back(Lambda.Dependent); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4360 | Record.push_back(Lambda.NumCaptures); |
| 4361 | Record.push_back(Lambda.NumExplicitCaptures); |
Douglas Gregor | 9e8c92a | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 4362 | Record.push_back(Lambda.ManglingNumber); |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 4363 | AddDeclRef(Lambda.ContextDecl, Record); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4364 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
| 4365 | LambdaExpr::Capture &Capture = Lambda.Captures[I]; |
| 4366 | AddSourceLocation(Capture.getLocation(), Record); |
| 4367 | Record.push_back(Capture.isImplicit()); |
| 4368 | Record.push_back(Capture.getCaptureKind()); // FIXME: stable! |
| 4369 | VarDecl *Var = Capture.capturesVariable()? Capture.getCapturedVar() : 0; |
| 4370 | AddDeclRef(Var, Record); |
| 4371 | AddSourceLocation(Capture.isPackExpansion()? Capture.getEllipsisLoc() |
| 4372 | : SourceLocation(), |
| 4373 | Record); |
| 4374 | } |
| 4375 | } |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4378 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4379 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4380 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4381 | assert(FirstDeclID == NextDeclID && |
| 4382 | FirstTypeID == NextTypeID && |
| 4383 | FirstIdentID == NextIdentID && |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4384 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4385 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4386 | "Setting chain after writing has started."); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4387 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4388 | Chain = Reader; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4389 | |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4390 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 4391 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 4392 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4393 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4394 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4395 | NextDeclID = FirstDeclID; |
| 4396 | NextTypeID = FirstTypeID; |
| 4397 | NextIdentID = FirstIdentID; |
| 4398 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4399 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4400 | } |
| 4401 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4402 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4403 | IdentifierIDs[II] = ID; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 4404 | if (II->hasMacroDefinition()) |
| 4405 | DeserializedMacroNames.push_back(II); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4406 | } |
| 4407 | |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4408 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4409 | // Always take the highest-numbered type index. This copes with an interesting |
| 4410 | // case for chained AST writing where we schedule writing the type and then, |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4411 | // later, deserialize the type from another AST. In this case, we want to |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4412 | // keep the higher-numbered entry so that we can properly write it out to |
| 4413 | // the AST file. |
| 4414 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 4415 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 4416 | StoredIdx = Idx; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4419 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4420 | SelectorIDs[S] = ID; |
| 4421 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4422 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4423 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4424 | MacroDefinition *MD) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4425 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4426 | MacroDefinitions[MD] = ID; |
| 4427 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4428 | |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 4429 | void ASTWriter::MacroVisible(IdentifierInfo *II) { |
| 4430 | DeserializedMacroNames.push_back(II); |
| 4431 | } |
| 4432 | |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 4433 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 4434 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 4435 | SubmoduleIDs[Mod] = ID; |
| 4436 | } |
| 4437 | |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4438 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4439 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4440 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4441 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 4442 | // We are interested when a PCH decl is modified. |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4443 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4444 | // A forward reference was mutated into a definition. Rewrite it. |
| 4445 | // FIXME: This happens during template instantiation, should we |
| 4446 | // have created a new definition decl instead ? |
Argyrios Kyrtzidis | d3d0755 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 4447 | RewriteDecl(RD); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4448 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4449 | } |
| 4450 | } |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4451 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4452 | assert(!WritingAST && "Already writing the AST!"); |
| 4453 | |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4454 | // TU and namespaces are handled elsewhere. |
| 4455 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 4456 | return; |
| 4457 | |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4458 | if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile())) |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4459 | return; // Not a source decl added to a DeclContext from PCH. |
| 4460 | |
| 4461 | AddUpdatedDeclContext(DC); |
| 4462 | } |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4463 | |
| 4464 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4465 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4466 | assert(D->isImplicit()); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4467 | if (!(!D->isFromASTFile() && RD->isFromASTFile())) |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4468 | return; // Not a source member added to a class from PCH. |
| 4469 | if (!isa<CXXMethodDecl>(D)) |
| 4470 | return; // We are interested in lazily declared implicit methods. |
| 4471 | |
| 4472 | // A decl coming from PCH was modified. |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4473 | assert(RD->isCompleteDefinition()); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4474 | UpdateRecord &Record = DeclUpdates[RD]; |
| 4475 | Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4476 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4477 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4478 | |
| 4479 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 4480 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4481 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4482 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4483 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4484 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4485 | return; // Not a source specialization added to a template from PCH. |
| 4486 | |
| 4487 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4488 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4489 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4490 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 4491 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4492 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 4493 | const FunctionDecl *D) { |
| 4494 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4495 | assert(!WritingAST && "Already writing the AST!"); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4496 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4497 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4498 | return; // Not a source specialization added to a template from PCH. |
| 4499 | |
| 4500 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4501 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4502 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4505 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4506 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4507 | if (!D->isFromASTFile()) |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4508 | return; // Declaration not imported from PCH. |
| 4509 | |
| 4510 | // Implicit decl from a PCH was defined. |
| 4511 | // FIXME: Should implicit definition be a separate FunctionDecl? |
| 4512 | RewriteDecl(D); |
| 4513 | } |
| 4514 | |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4515 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4516 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4517 | if (!D->isFromASTFile()) |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4518 | return; |
| 4519 | |
| 4520 | // Since the actual instantiation is delayed, this really means that we need |
| 4521 | // to update the instantiation location. |
| 4522 | UpdateRecord &Record = DeclUpdates[D]; |
| 4523 | Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); |
| 4524 | AddSourceLocation( |
| 4525 | D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); |
| 4526 | } |
| 4527 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4528 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 4529 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4530 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4531 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4532 | return; // Declaration not imported from PCH. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4533 | |
| 4534 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 4535 | ObjCClassesWithCategories.insert( |
| 4536 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4537 | } |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 4538 | |
Argyrios Kyrtzidis | 1a43415 | 2011-11-12 21:07:52 +0000 | [diff] [blame] | 4539 | |
Argyrios Kyrtzidis | c80553e | 2011-11-14 04:52:29 +0000 | [diff] [blame] | 4540 | void ASTWriter::AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, |
| 4541 | const ObjCPropertyDecl *OrigProp, |
| 4542 | const ObjCCategoryDecl *ClassExt) { |
| 4543 | const ObjCInterfaceDecl *D = ClassExt->getClassInterface(); |
| 4544 | if (!D) |
| 4545 | return; |
| 4546 | |
| 4547 | assert(!WritingAST && "Already writing the AST!"); |
| 4548 | if (!D->isFromASTFile()) |
| 4549 | return; // Declaration not imported from PCH. |
| 4550 | |
| 4551 | RewriteDecl(D); |
| 4552 | } |