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 | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclContextInternals.h" |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclFriend.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 23 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 24 | #include "clang/AST/TypeLocVisitor.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 25 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 26 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 27 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 28 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 29 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 30 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 31 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 32 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 33 | #include "clang/Basic/VersionTuple.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 34 | #include "clang/Lex/HeaderSearch.h" |
| 35 | #include "clang/Lex/HeaderSearchOptions.h" |
| 36 | #include "clang/Lex/MacroInfo.h" |
| 37 | #include "clang/Lex/PreprocessingRecord.h" |
| 38 | #include "clang/Lex/Preprocessor.h" |
| 39 | #include "clang/Lex/PreprocessorOptions.h" |
| 40 | #include "clang/Sema/IdentifierResolver.h" |
| 41 | #include "clang/Sema/Sema.h" |
| 42 | #include "clang/Serialization/ASTReader.h" |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 43 | #include "llvm/ADT/APFloat.h" |
| 44 | #include "llvm/ADT/APInt.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 45 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 46 | #include "llvm/Bitcode/BitstreamWriter.h" |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 47 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 48 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 49 | #include "llvm/Support/Path.h" |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 50 | #include <algorithm> |
Chris Lattner | 3c304bd | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 51 | #include <cstdio> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 52 | #include <string.h> |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 53 | #include <utility> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 54 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 55 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 56 | |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 57 | template <typename T, typename Allocator> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 58 | static StringRef data(const std::vector<T, Allocator> &v) { |
| 59 | if (v.empty()) return StringRef(); |
| 60 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 61 | sizeof(T) * v.size()); |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 62 | } |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 63 | |
| 64 | template <typename T> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 65 | static StringRef data(const SmallVectorImpl<T> &v) { |
| 66 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 67 | sizeof(T) * v.size()); |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 70 | //===----------------------------------------------------------------------===// |
| 71 | // Type serialization |
| 72 | //===----------------------------------------------------------------------===// |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 73 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 74 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 75 | class ASTTypeWriter { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 76 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 77 | ASTWriter::RecordDataImpl &Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 78 | |
| 79 | public: |
| 80 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 81 | TypeCode Code; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 82 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 83 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 84 | : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 85 | |
| 86 | void VisitArrayType(const ArrayType *T); |
| 87 | void VisitFunctionType(const FunctionType *T); |
| 88 | void VisitTagType(const TagType *T); |
| 89 | |
| 90 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 91 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 92 | #include "clang/AST/TypeNodes.def" |
| 93 | }; |
| 94 | } |
| 95 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 96 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 97 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 100 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 101 | Writer.AddTypeRef(T->getElementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 102 | Code = TYPE_COMPLEX; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 105 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 106 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 107 | Code = TYPE_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 110 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 112 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 115 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 116 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
| 117 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 118 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 121 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 122 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 123 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 126 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 127 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 128 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 129 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 132 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 133 | Writer.AddTypeRef(T->getElementType(), Record); |
| 134 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 135 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 138 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 139 | VisitArrayType(T); |
| 140 | Writer.AddAPInt(T->getSize(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 141 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 144 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 145 | VisitArrayType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 146 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 149 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 150 | VisitArrayType(T); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 151 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 152 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 153 | Writer.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 154 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 157 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 158 | Writer.AddTypeRef(T->getElementType(), Record); |
| 159 | Record.push_back(T->getNumElements()); |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 160 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 161 | Code = TYPE_VECTOR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 164 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 165 | VisitVectorType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 166 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 169 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 170 | Writer.AddTypeRef(T->getResultType(), Record); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 171 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 172 | Record.push_back(C.getNoReturn()); |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 173 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 174 | Record.push_back(C.getRegParm()); |
Douglas Gregor | ab8bbf4 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 175 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 176 | Record.push_back(C.getCC()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 177 | Record.push_back(C.getProducesResult()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 180 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 181 | VisitFunctionType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 182 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 185 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 186 | VisitFunctionType(T); |
| 187 | Record.push_back(T->getNumArgs()); |
| 188 | for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) |
| 189 | Writer.AddTypeRef(T->getArgType(I), Record); |
| 190 | Record.push_back(T->isVariadic()); |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 191 | Record.push_back(T->hasTrailingReturn()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 192 | Record.push_back(T->getTypeQuals()); |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 193 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 194 | Record.push_back(T->getExceptionSpecType()); |
| 195 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 196 | Record.push_back(T->getNumExceptions()); |
| 197 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 198 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 199 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 200 | Writer.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 201 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
| 202 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
| 203 | Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); |
Richard Smith | b9d0b76 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 204 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
| 205 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 206 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 207 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 210 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 211 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 212 | Code = TYPE_UNRESOLVED_USING; |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 213 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 214 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 215 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 216 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 217 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 218 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 219 | Code = TYPE_TYPEDEF; |
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::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 223 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 224 | Code = TYPE_TYPEOF_EXPR; |
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::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 228 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 229 | Code = TYPE_TYPEOF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 232 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 233 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 234 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 235 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 238 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 239 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 240 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 241 | Record.push_back(T->getUTTKind()); |
| 242 | Code = TYPE_UNARY_TRANSFORM; |
| 243 | } |
| 244 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 245 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 246 | Writer.AddTypeRef(T->getDeducedType(), Record); |
| 247 | Code = TYPE_AUTO; |
| 248 | } |
| 249 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 250 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 251 | Record.push_back(T->isDependentType()); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 252 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 253 | assert(!T->isBeingDefined() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 254 | "Cannot serialize in the middle of a type definition"); |
| 255 | } |
| 256 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 257 | void ASTTypeWriter::VisitRecordType(const RecordType *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_RECORD; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 262 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 263 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 264 | Code = TYPE_ENUM; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 265 | } |
| 266 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 267 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 268 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 269 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 270 | Record.push_back(T->getAttrKind()); |
| 271 | Code = TYPE_ATTRIBUTED; |
| 272 | } |
| 273 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 274 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 275 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 276 | const SubstTemplateTypeParmType *T) { |
| 277 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 278 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 279 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | void |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 283 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 284 | const SubstTemplateTypeParmPackType *T) { |
| 285 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 286 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 287 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 288 | } |
| 289 | |
| 290 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 291 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 292 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 293 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 294 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 295 | Record.push_back(T->getNumArgs()); |
| 296 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 297 | ArgI != ArgE; ++ArgI) |
| 298 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 299 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 300 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 301 | : T->getCanonicalTypeInternal(), |
| 302 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 303 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 307 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 308 | VisitArrayType(T); |
| 309 | Writer.AddStmt(T->getSizeExpr()); |
| 310 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 311 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 315 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 316 | const DependentSizedExtVectorType *T) { |
| 317 | // FIXME: Serialize this type (C++ only) |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 318 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 322 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 323 | Record.push_back(T->getDepth()); |
| 324 | Record.push_back(T->getIndex()); |
| 325 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 326 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 327 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 331 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 332 | Record.push_back(T->getKeyword()); |
| 333 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 334 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 335 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 336 | : T->getCanonicalTypeInternal(), |
| 337 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 338 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 342 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 343 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 344 | Record.push_back(T->getKeyword()); |
| 345 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 346 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 347 | Record.push_back(T->getNumArgs()); |
| 348 | for (DependentTemplateSpecializationType::iterator |
| 349 | I = T->begin(), E = T->end(); I != E; ++I) |
| 350 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 351 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 354 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 355 | Writer.AddTypeRef(T->getPattern(), Record); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 356 | if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) |
| 357 | Record.push_back(*NumExpansions + 1); |
| 358 | else |
| 359 | Record.push_back(0); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 360 | Code = TYPE_PACK_EXPANSION; |
| 361 | } |
| 362 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 363 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 364 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 365 | Code = TYPE_PAREN; |
| 366 | } |
| 367 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 368 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 369 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 370 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 371 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 372 | Code = TYPE_ELABORATED; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 375 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Douglas Gregor | a8e0b97 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 376 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 377 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 378 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 381 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 382 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 383 | Code = TYPE_OBJC_INTERFACE; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 386 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 387 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 388 | Record.push_back(T->getNumProtocols()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 389 | for (ObjCObjectType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 446ee4e | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 390 | E = T->qual_end(); I != E; ++I) |
| 391 | Writer.AddDeclRef(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 392 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 395 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 396 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 398 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 401 | void |
| 402 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
| 403 | Writer.AddTypeRef(T->getValueType(), Record); |
| 404 | Code = TYPE_ATOMIC; |
| 405 | } |
| 406 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 407 | namespace { |
| 408 | |
| 409 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 410 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 411 | ASTWriter::RecordDataImpl &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 412 | |
| 413 | public: |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 414 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 415 | : Writer(Writer), Record(Record) { } |
| 416 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 417 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 418 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 419 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 420 | #include "clang/AST/TypeLocNodes.def" |
| 421 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 422 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 423 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 424 | }; |
| 425 | |
| 426 | } |
| 427 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 428 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 429 | // nothing to do |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 430 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 431 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 432 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 433 | if (TL.needsExtraLocalData()) { |
| 434 | Record.push_back(TL.getWrittenTypeSpec()); |
| 435 | Record.push_back(TL.getWrittenSignSpec()); |
| 436 | Record.push_back(TL.getWrittenWidthSpec()); |
| 437 | Record.push_back(TL.hasModeAttr()); |
| 438 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 439 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 440 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 441 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 442 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 443 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 444 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 445 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 446 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 447 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 448 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 449 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 450 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 451 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 452 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 453 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 454 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 455 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 456 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 457 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 458 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 459 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 460 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 461 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 462 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 463 | if (TL.getSizeExpr()) |
| 464 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 465 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 466 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 467 | VisitArrayTypeLoc(TL); |
| 468 | } |
| 469 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 470 | VisitArrayTypeLoc(TL); |
| 471 | } |
| 472 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 473 | VisitArrayTypeLoc(TL); |
| 474 | } |
| 475 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 476 | DependentSizedArrayTypeLoc TL) { |
| 477 | VisitArrayTypeLoc(TL); |
| 478 | } |
| 479 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 480 | DependentSizedExtVectorTypeLoc TL) { |
| 481 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 482 | } |
| 483 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 484 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 485 | } |
| 486 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 487 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 488 | } |
| 489 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 490 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 491 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 492 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 493 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 494 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 495 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 496 | } |
| 497 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 498 | VisitFunctionTypeLoc(TL); |
| 499 | } |
| 500 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 501 | VisitFunctionTypeLoc(TL); |
| 502 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 503 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 504 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 505 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 506 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 507 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 508 | } |
| 509 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 510 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 511 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 512 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 513 | } |
| 514 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 515 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 516 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 517 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 518 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 519 | } |
| 520 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 521 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 522 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 523 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 524 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 525 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 526 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 527 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 528 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 529 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 530 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 531 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 532 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 533 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 534 | } |
| 535 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 536 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 537 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 538 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 539 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 540 | if (TL.hasAttrOperand()) { |
| 541 | SourceRange range = TL.getAttrOperandParensRange(); |
| 542 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 543 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 544 | } |
| 545 | if (TL.hasAttrExprOperand()) { |
| 546 | Expr *operand = TL.getAttrExprOperand(); |
| 547 | Record.push_back(operand ? 1 : 0); |
| 548 | if (operand) Writer.AddStmt(operand); |
| 549 | } else if (TL.hasAttrEnumOperand()) { |
| 550 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 551 | } |
| 552 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 553 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 554 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 555 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 556 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 557 | SubstTemplateTypeParmTypeLoc TL) { |
| 558 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 559 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 560 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 561 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 562 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 563 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 564 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 565 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 566 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 567 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 568 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 569 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 570 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 571 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 572 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 573 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 574 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 575 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 576 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 577 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 578 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 579 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 580 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 581 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 582 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 583 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 584 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 585 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 586 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 587 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 588 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 589 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 590 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 591 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 592 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 593 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 594 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 595 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 596 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 597 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 598 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 599 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 600 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 601 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 602 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 603 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 604 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 605 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 606 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 607 | } |
| 608 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 609 | Record.push_back(TL.hasBaseTypeAsWritten()); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 610 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 611 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 612 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 613 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 614 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 615 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 616 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 617 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 618 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 619 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 620 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 621 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 622 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 623 | |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 624 | //===----------------------------------------------------------------------===// |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 625 | // ASTWriter Implementation |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 626 | //===----------------------------------------------------------------------===// |
| 627 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 628 | static void EmitBlockID(unsigned ID, const char *Name, |
| 629 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 630 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 631 | Record.clear(); |
| 632 | Record.push_back(ID); |
| 633 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 634 | |
| 635 | // Emit the block name if present. |
| 636 | if (Name == 0 || Name[0] == 0) return; |
| 637 | Record.clear(); |
| 638 | while (*Name) |
| 639 | Record.push_back(*Name++); |
| 640 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 641 | } |
| 642 | |
| 643 | static void EmitRecordID(unsigned ID, const char *Name, |
| 644 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 645 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 646 | Record.clear(); |
| 647 | Record.push_back(ID); |
| 648 | while (*Name) |
| 649 | Record.push_back(*Name++); |
| 650 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 654 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 655 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 656 | RECORD(STMT_STOP); |
| 657 | RECORD(STMT_NULL_PTR); |
| 658 | RECORD(STMT_NULL); |
| 659 | RECORD(STMT_COMPOUND); |
| 660 | RECORD(STMT_CASE); |
| 661 | RECORD(STMT_DEFAULT); |
| 662 | RECORD(STMT_LABEL); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 663 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 664 | RECORD(STMT_IF); |
| 665 | RECORD(STMT_SWITCH); |
| 666 | RECORD(STMT_WHILE); |
| 667 | RECORD(STMT_DO); |
| 668 | RECORD(STMT_FOR); |
| 669 | RECORD(STMT_GOTO); |
| 670 | RECORD(STMT_INDIRECT_GOTO); |
| 671 | RECORD(STMT_CONTINUE); |
| 672 | RECORD(STMT_BREAK); |
| 673 | RECORD(STMT_RETURN); |
| 674 | RECORD(STMT_DECL); |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 675 | RECORD(STMT_GCCASM); |
Chad Rosier | cd518a0 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 676 | RECORD(STMT_MSASM); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 677 | RECORD(EXPR_PREDEFINED); |
| 678 | RECORD(EXPR_DECL_REF); |
| 679 | RECORD(EXPR_INTEGER_LITERAL); |
| 680 | RECORD(EXPR_FLOATING_LITERAL); |
| 681 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 682 | RECORD(EXPR_STRING_LITERAL); |
| 683 | RECORD(EXPR_CHARACTER_LITERAL); |
| 684 | RECORD(EXPR_PAREN); |
| 685 | RECORD(EXPR_UNARY_OPERATOR); |
| 686 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 687 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 688 | RECORD(EXPR_CALL); |
| 689 | RECORD(EXPR_MEMBER); |
| 690 | RECORD(EXPR_BINARY_OPERATOR); |
| 691 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 692 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 693 | RECORD(EXPR_IMPLICIT_CAST); |
| 694 | RECORD(EXPR_CSTYLE_CAST); |
| 695 | RECORD(EXPR_COMPOUND_LITERAL); |
| 696 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 697 | RECORD(EXPR_INIT_LIST); |
| 698 | RECORD(EXPR_DESIGNATED_INIT); |
| 699 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 700 | RECORD(EXPR_VA_ARG); |
| 701 | RECORD(EXPR_ADDR_LABEL); |
| 702 | RECORD(EXPR_STMT); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 703 | RECORD(EXPR_CHOOSE); |
| 704 | RECORD(EXPR_GNU_NULL); |
| 705 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 706 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 707 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 708 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 709 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 710 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 711 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 712 | RECORD(EXPR_OBJC_ENCODE); |
| 713 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 714 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 715 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 716 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 717 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 718 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 719 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 720 | RECORD(STMT_OBJC_CATCH); |
| 721 | RECORD(STMT_OBJC_FINALLY); |
| 722 | RECORD(STMT_OBJC_AT_TRY); |
| 723 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 724 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 725 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 726 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 727 | RECORD(EXPR_CXX_CONSTRUCT); |
| 728 | RECORD(EXPR_CXX_STATIC_CAST); |
| 729 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 730 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 731 | RECORD(EXPR_CXX_CONST_CAST); |
| 732 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 733 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 734 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 735 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 736 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 737 | RECORD(EXPR_CXX_TYPEID_TYPE); |
| 738 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 739 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 740 | RECORD(EXPR_CXX_THIS); |
| 741 | RECORD(EXPR_CXX_THROW); |
| 742 | RECORD(EXPR_CXX_DEFAULT_ARG); |
| 743 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 744 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 745 | RECORD(EXPR_CXX_NEW); |
| 746 | RECORD(EXPR_CXX_DELETE); |
| 747 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 748 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 749 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 750 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 751 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 752 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 753 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
| 754 | RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); |
| 755 | RECORD(EXPR_CXX_NOEXCEPT); |
| 756 | RECORD(EXPR_OPAQUE_VALUE); |
| 757 | RECORD(EXPR_BINARY_TYPE_TRAIT); |
| 758 | RECORD(EXPR_PACK_EXPANSION); |
| 759 | RECORD(EXPR_SIZEOF_PACK); |
| 760 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 761 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 762 | #undef RECORD |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 763 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 765 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 766 | RecordData Record; |
| 767 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 769 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 770 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 771 | |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 772 | // Control Block. |
| 773 | BLOCK(CONTROL_BLOCK); |
| 774 | RECORD(METADATA); |
| 775 | RECORD(IMPORTS); |
| 776 | RECORD(LANGUAGE_OPTIONS); |
| 777 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 778 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 779 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 992d917 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 780 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 781 | RECORD(INPUT_FILE_OFFSETS); |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 782 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 783 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 784 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 785 | RECORD(PREPROCESSOR_OPTIONS); |
| 786 | |
Douglas Gregor | c337fef | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 787 | BLOCK(INPUT_FILES_BLOCK); |
| 788 | RECORD(INPUT_FILE); |
| 789 | |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 790 | // AST Top-Level Block. |
| 791 | BLOCK(AST_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 792 | RECORD(TYPE_OFFSET); |
| 793 | RECORD(DECL_OFFSET); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 794 | RECORD(IDENTIFIER_OFFSET); |
| 795 | RECORD(IDENTIFIER_TABLE); |
| 796 | RECORD(EXTERNAL_DEFINITIONS); |
| 797 | RECORD(SPECIAL_TYPES); |
| 798 | RECORD(STATISTICS); |
| 799 | RECORD(TENTATIVE_DEFINITIONS); |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 800 | RECORD(UNUSED_FILESCOPED_DECLS); |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 801 | RECORD(LOCALLY_SCOPED_EXTERN_C_DECLS); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 802 | RECORD(SELECTOR_OFFSETS); |
| 803 | RECORD(METHOD_POOL); |
| 804 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 805 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 806 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 807 | RECORD(EXT_VECTOR_DECLS); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 808 | RECORD(PPD_ENTITIES_OFFSETS); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 809 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 810 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 811 | RECORD(LOCAL_REDECLARATIONS_MAP); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 812 | RECORD(SEMA_DECL_REFS); |
| 813 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 814 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 815 | RECORD(DECL_REPLACEMENTS); |
| 816 | RECORD(UPDATE_VISIBLE); |
| 817 | RECORD(DECL_UPDATE_OFFSETS); |
| 818 | RECORD(DECL_UPDATES); |
| 819 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 820 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 821 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 822 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 823 | RECORD(FP_PRAGMA_OPTIONS); |
| 824 | RECORD(OPENCL_EXTENSIONS); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 825 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 826 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 837593f | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 827 | RECORD(MODULE_OFFSET_MAP); |
| 828 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 829 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | a126651 | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 830 | RECORD(FILE_SORTED_DECLS); |
| 831 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 832 | RECORD(MERGED_DECLARATIONS); |
| 833 | RECORD(LOCAL_REDECLARATIONS); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 834 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 835 | RECORD(MACRO_OFFSET); |
| 836 | RECORD(MACRO_UPDATES); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 837 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 838 | // SourceManager Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 839 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 840 | RECORD(SM_SLOC_FILE_ENTRY); |
| 841 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 842 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 843 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 844 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 845 | // Preprocessor Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 846 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 847 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 848 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 849 | RECORD(PP_TOKEN); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 850 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 851 | // Decls and Types block. |
| 852 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 853 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 854 | RECORD(TYPE_COMPLEX); |
| 855 | RECORD(TYPE_POINTER); |
| 856 | RECORD(TYPE_BLOCK_POINTER); |
| 857 | RECORD(TYPE_LVALUE_REFERENCE); |
| 858 | RECORD(TYPE_RVALUE_REFERENCE); |
| 859 | RECORD(TYPE_MEMBER_POINTER); |
| 860 | RECORD(TYPE_CONSTANT_ARRAY); |
| 861 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 862 | RECORD(TYPE_VARIABLE_ARRAY); |
| 863 | RECORD(TYPE_VECTOR); |
| 864 | RECORD(TYPE_EXT_VECTOR); |
| 865 | RECORD(TYPE_FUNCTION_PROTO); |
| 866 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 867 | RECORD(TYPE_TYPEDEF); |
| 868 | RECORD(TYPE_TYPEOF_EXPR); |
| 869 | RECORD(TYPE_TYPEOF); |
| 870 | RECORD(TYPE_RECORD); |
| 871 | RECORD(TYPE_ENUM); |
| 872 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | a53d2cb | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 873 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 874 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 875 | RECORD(TYPE_DECLTYPE); |
| 876 | RECORD(TYPE_ELABORATED); |
| 877 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 878 | RECORD(TYPE_UNRESOLVED_USING); |
| 879 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 880 | RECORD(TYPE_OBJC_OBJECT); |
| 881 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 882 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 883 | RECORD(TYPE_DEPENDENT_NAME); |
| 884 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 885 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 886 | RECORD(TYPE_PAREN); |
| 887 | RECORD(TYPE_PACK_EXPANSION); |
| 888 | RECORD(TYPE_ATTRIBUTED); |
| 889 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 890 | RECORD(TYPE_ATOMIC); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 891 | RECORD(DECL_TYPEDEF); |
| 892 | RECORD(DECL_ENUM); |
| 893 | RECORD(DECL_RECORD); |
| 894 | RECORD(DECL_ENUM_CONSTANT); |
| 895 | RECORD(DECL_FUNCTION); |
| 896 | RECORD(DECL_OBJC_METHOD); |
| 897 | RECORD(DECL_OBJC_INTERFACE); |
| 898 | RECORD(DECL_OBJC_PROTOCOL); |
| 899 | RECORD(DECL_OBJC_IVAR); |
| 900 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 901 | RECORD(DECL_OBJC_CATEGORY); |
| 902 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 903 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 904 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 905 | RECORD(DECL_OBJC_PROPERTY); |
| 906 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 907 | RECORD(DECL_FIELD); |
| 908 | RECORD(DECL_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 909 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 910 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 911 | RECORD(DECL_FILE_SCOPE_ASM); |
| 912 | RECORD(DECL_BLOCK); |
| 913 | RECORD(DECL_CONTEXT_LEXICAL); |
| 914 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 915 | RECORD(DECL_NAMESPACE); |
| 916 | RECORD(DECL_NAMESPACE_ALIAS); |
| 917 | RECORD(DECL_USING); |
| 918 | RECORD(DECL_USING_SHADOW); |
| 919 | RECORD(DECL_USING_DIRECTIVE); |
| 920 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 921 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 922 | RECORD(DECL_LINKAGE_SPEC); |
| 923 | RECORD(DECL_CXX_RECORD); |
| 924 | RECORD(DECL_CXX_METHOD); |
| 925 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 926 | RECORD(DECL_CXX_DESTRUCTOR); |
| 927 | RECORD(DECL_CXX_CONVERSION); |
| 928 | RECORD(DECL_ACCESS_SPEC); |
| 929 | RECORD(DECL_FRIEND); |
| 930 | RECORD(DECL_FRIEND_TEMPLATE); |
| 931 | RECORD(DECL_CLASS_TEMPLATE); |
| 932 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 933 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
| 934 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 935 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 936 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 937 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 938 | RECORD(DECL_STATIC_ASSERT); |
| 939 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 940 | RECORD(DECL_INDIRECTFIELD); |
| 941 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 942 | |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 943 | // Statements and Exprs can occur in the Decls and Types block. |
| 944 | AddStmtsExprs(Stream, Record); |
| 945 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 946 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 947 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 948 | RECORD(PPD_MACRO_DEFINITION); |
| 949 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 950 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 951 | #undef RECORD |
| 952 | #undef BLOCK |
| 953 | Stream.ExitBlock(); |
| 954 | } |
| 955 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 956 | /// \brief Adjusts the given filename to only write out the portion of the |
| 957 | /// filename that is not part of the system root directory. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | /// |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 959 | /// \param Filename the file name to adjust. |
| 960 | /// |
| 961 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 962 | /// the returned filename will be adjusted by this system root. |
| 963 | /// |
| 964 | /// \returns either the original filename (if it needs no adjustment) or the |
| 965 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 966 | static const char * |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 967 | adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 968 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 970 | if (isysroot.empty()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 971 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 972 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 973 | // Verify that the filename and the system root have the same prefix. |
| 974 | unsigned Pos = 0; |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 975 | for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 976 | if (Filename[Pos] != isysroot[Pos]) |
| 977 | return Filename; // Prefixes don't match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 979 | // We hit the end of the filename before we hit the end of the system root. |
| 980 | if (!Filename[Pos]) |
| 981 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 982 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 983 | // If the file name has a '/' at the current position, skip over the '/'. |
| 984 | // We distinguish sysroot-based includes from absolute includes by the |
| 985 | // absence of '/' at the beginning of sysroot-based includes. |
| 986 | if (Filename[Pos] == '/') |
| 987 | ++Pos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 989 | return Filename + Pos; |
| 990 | } |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 992 | /// \brief Write the control block. |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 993 | void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, |
| 994 | StringRef isysroot, |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 995 | const std::string &OutputFile) { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 996 | using namespace llvm; |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 997 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
| 998 | RecordData Record; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 999 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1000 | // Metadata |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1001 | BitCodeAbbrev *MetadataAbbrev = new BitCodeAbbrev(); |
| 1002 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1003 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1004 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1005 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1006 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1007 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
| 1008 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1009 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1010 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
| 1011 | Record.push_back(METADATA); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1012 | Record.push_back(VERSION_MAJOR); |
| 1013 | Record.push_back(VERSION_MINOR); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1014 | Record.push_back(CLANG_VERSION_MAJOR); |
| 1015 | Record.push_back(CLANG_VERSION_MINOR); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1016 | Record.push_back(!isysroot.empty()); |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 1017 | Record.push_back(ASTHasCompilerErrors); |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1018 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1019 | getClangFullRepositoryVersion()); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1020 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1021 | // Imports |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1022 | if (Chain) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1023 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1024 | SmallVector<char, 128> ModulePaths; |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1025 | Record.clear(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1026 | |
| 1027 | for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end(); |
| 1028 | M != MEnd; ++M) { |
| 1029 | // Skip modules that weren't directly imported. |
| 1030 | if (!(*M)->isDirectlyImported()) |
| 1031 | continue; |
| 1032 | |
| 1033 | Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding |
Argyrios Kyrtzidis | 958bcaf | 2012-11-15 18:57:22 +0000 | [diff] [blame] | 1034 | AddSourceLocation((*M)->ImportLoc, Record); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1035 | // FIXME: This writes the absolute path for AST files we depend on. |
| 1036 | const std::string &FileName = (*M)->FileName; |
| 1037 | Record.push_back(FileName.size()); |
| 1038 | Record.append(FileName.begin(), FileName.end()); |
| 1039 | } |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1040 | Stream.EmitRecord(IMPORTS, Record); |
| 1041 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1042 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1043 | // Language options. |
| 1044 | Record.clear(); |
| 1045 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1046 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1047 | Record.push_back(LangOpts.Name); |
| 1048 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1049 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
| 1050 | #include "clang/Basic/LangOptions.def" |
Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1051 | #define SANITIZER(NAME, ID) Record.push_back(LangOpts.Sanitize.ID); |
| 1052 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1053 | |
| 1054 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1055 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
| 1056 | |
| 1057 | Record.push_back(LangOpts.CurrentModule.size()); |
| 1058 | Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end()); |
| 1059 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1060 | |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1061 | // Target options. |
| 1062 | Record.clear(); |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1063 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1064 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1065 | AddString(TargetOpts.Triple, Record); |
| 1066 | AddString(TargetOpts.CPU, Record); |
| 1067 | AddString(TargetOpts.ABI, Record); |
| 1068 | AddString(TargetOpts.CXXABI, Record); |
| 1069 | AddString(TargetOpts.LinkerVersion, Record); |
| 1070 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1071 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1072 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1073 | } |
| 1074 | Record.push_back(TargetOpts.Features.size()); |
| 1075 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1076 | AddString(TargetOpts.Features[I], Record); |
| 1077 | } |
| 1078 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1079 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1080 | // Diagnostic options. |
| 1081 | Record.clear(); |
| 1082 | const DiagnosticOptions &DiagOpts |
| 1083 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1084 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1085 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1086 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1087 | #include "clang/Basic/DiagnosticOptions.def" |
| 1088 | Record.push_back(DiagOpts.Warnings.size()); |
| 1089 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1090 | AddString(DiagOpts.Warnings[I], Record); |
| 1091 | // Note: we don't serialize the log or serialization file names, because they |
| 1092 | // are generally transient files and will almost always be overridden. |
| 1093 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1094 | |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1095 | // File system options. |
| 1096 | Record.clear(); |
| 1097 | const FileSystemOptions &FSOpts |
| 1098 | = Context.getSourceManager().getFileManager().getFileSystemOptions(); |
| 1099 | AddString(FSOpts.WorkingDir, Record); |
| 1100 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1101 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1102 | // Header search options. |
| 1103 | Record.clear(); |
| 1104 | const HeaderSearchOptions &HSOpts |
| 1105 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1106 | AddString(HSOpts.Sysroot, Record); |
| 1107 | |
| 1108 | // Include entries. |
| 1109 | Record.push_back(HSOpts.UserEntries.size()); |
| 1110 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1111 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1112 | AddString(Entry.Path, Record); |
| 1113 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
| 1114 | Record.push_back(Entry.IsUserSupplied); |
| 1115 | Record.push_back(Entry.IsFramework); |
| 1116 | Record.push_back(Entry.IgnoreSysRoot); |
| 1117 | Record.push_back(Entry.IsInternal); |
| 1118 | Record.push_back(Entry.ImplicitExternC); |
| 1119 | } |
| 1120 | |
| 1121 | // System header prefixes. |
| 1122 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1123 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1124 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1125 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1126 | } |
| 1127 | |
| 1128 | AddString(HSOpts.ResourceDir, Record); |
| 1129 | AddString(HSOpts.ModuleCachePath, Record); |
| 1130 | Record.push_back(HSOpts.DisableModuleHash); |
| 1131 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1132 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1133 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1134 | Record.push_back(HSOpts.UseLibcxx); |
| 1135 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1136 | |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1137 | // Preprocessor options. |
| 1138 | Record.clear(); |
| 1139 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1140 | |
| 1141 | // Macro definitions. |
| 1142 | Record.push_back(PPOpts.Macros.size()); |
| 1143 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1144 | AddString(PPOpts.Macros[I].first, Record); |
| 1145 | Record.push_back(PPOpts.Macros[I].second); |
| 1146 | } |
| 1147 | |
| 1148 | // Includes |
| 1149 | Record.push_back(PPOpts.Includes.size()); |
| 1150 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1151 | AddString(PPOpts.Includes[I], Record); |
| 1152 | |
| 1153 | // Macro includes |
| 1154 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1155 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1156 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1157 | |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1158 | Record.push_back(PPOpts.UsePredefines); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1159 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1160 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1161 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1162 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1163 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1164 | // Original file name and file ID |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1165 | SourceManager &SM = Context.getSourceManager(); |
| 1166 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 1167 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1168 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1169 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1170 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1171 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1172 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1173 | SmallString<128> MainFilePath(MainFile->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1174 | |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1175 | llvm::sys::fs::make_absolute(MainFilePath); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1176 | |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1177 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1178 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1179 | isysroot); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1180 | Record.clear(); |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1181 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1182 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1183 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1184 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1185 | |
Argyrios Kyrtzidis | 992d917 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1186 | Record.clear(); |
| 1187 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1188 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1189 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1190 | // Original PCH directory |
| 1191 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1192 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1193 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1194 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1195 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1196 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1197 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1198 | |
| 1199 | llvm::sys::fs::make_absolute(OutputPath); |
| 1200 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1201 | |
| 1202 | RecordData Record; |
| 1203 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1204 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1205 | } |
| 1206 | |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1207 | WriteInputFiles(Context.SourceMgr, isysroot); |
| 1208 | Stream.ExitBlock(); |
| 1209 | } |
| 1210 | |
| 1211 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, StringRef isysroot) { |
| 1212 | using namespace llvm; |
| 1213 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
| 1214 | RecordData Record; |
| 1215 | |
| 1216 | // Create input-file abbreviation. |
| 1217 | BitCodeAbbrev *IFAbbrev = new BitCodeAbbrev(); |
| 1218 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1219 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1220 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1221 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1222 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1223 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1224 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1225 | |
| 1226 | // Write out all of the input files. |
| 1227 | std::vector<uint32_t> InputFileOffsets; |
| 1228 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1229 | // Get this source location entry. |
| 1230 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | bacc2c5 | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1231 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1232 | |
| 1233 | // We only care about file entries that were not overridden. |
| 1234 | if (!SLoc->isFile()) |
| 1235 | continue; |
| 1236 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1237 | if (!Cache->OrigEntry) |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1238 | continue; |
| 1239 | |
Argyrios Kyrtzidis | a89b618 | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1240 | uint32_t &InputFileID = InputFileIDs[Cache->OrigEntry]; |
| 1241 | if (InputFileID != 0) |
| 1242 | continue; // already recorded this file. |
| 1243 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1244 | // Record this entry's offset. |
| 1245 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | a89b618 | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1246 | |
| 1247 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1248 | |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1249 | Record.clear(); |
| 1250 | Record.push_back(INPUT_FILE); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1251 | Record.push_back(InputFileOffsets.size()); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1252 | |
| 1253 | // Emit size/modification time for this file. |
| 1254 | Record.push_back(Cache->OrigEntry->getSize()); |
| 1255 | Record.push_back(Cache->OrigEntry->getModificationTime()); |
| 1256 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1257 | // Whether this file was overridden. |
| 1258 | Record.push_back(Cache->BufferOverridden); |
| 1259 | |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1260 | // Turn the file name into an absolute path, if it isn't already. |
| 1261 | const char *Filename = Cache->OrigEntry->getName(); |
| 1262 | SmallString<128> FilePath(Filename); |
| 1263 | |
| 1264 | // Ask the file manager to fixup the relative path for us. This will |
| 1265 | // honor the working directory. |
| 1266 | SourceMgr.getFileManager().FixupRelativePath(FilePath); |
| 1267 | |
| 1268 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1269 | // call to FixupRelativePath should always return an absolute path. |
| 1270 | llvm::sys::fs::make_absolute(FilePath); |
| 1271 | Filename = FilePath.c_str(); |
| 1272 | |
| 1273 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1274 | |
| 1275 | Stream.EmitRecordWithBlob(IFAbbrevCode, Record, Filename); |
| 1276 | } |
| 1277 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1278 | Stream.ExitBlock(); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1279 | |
| 1280 | // Create input file offsets abbreviation. |
| 1281 | BitCodeAbbrev *OffsetsAbbrev = new BitCodeAbbrev(); |
| 1282 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1283 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
| 1284 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
| 1285 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); |
| 1286 | |
| 1287 | // Write input file offsets. |
| 1288 | Record.clear(); |
| 1289 | Record.push_back(INPUT_FILE_OFFSETS); |
| 1290 | Record.push_back(InputFileOffsets.size()); |
| 1291 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, data(InputFileOffsets)); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1294 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1295 | // stat cache Serialization |
| 1296 | //===----------------------------------------------------------------------===// |
| 1297 | |
| 1298 | namespace { |
| 1299 | // Trait used for the on-disk hash table of stat cache results. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1300 | class ASTStatCacheTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1301 | public: |
| 1302 | typedef const char * key_type; |
| 1303 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1305 | typedef struct stat data_type; |
| 1306 | typedef const data_type &data_type_ref; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1307 | |
| 1308 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1309 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1310 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | |
| 1312 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1313 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1314 | data_type_ref Data) { |
| 1315 | unsigned StrLen = strlen(path); |
| 1316 | clang::io::Emit16(Out, StrLen); |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1317 | unsigned DataLen = 4 + 4 + 2 + 8 + 8; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1318 | clang::io::Emit8(Out, DataLen); |
| 1319 | return std::make_pair(StrLen + 1, DataLen); |
| 1320 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1321 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1322 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1323 | Out.write(path, KeyLen); |
| 1324 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1326 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1327 | data_type_ref Data, unsigned DataLen) { |
| 1328 | using namespace clang::io; |
| 1329 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1331 | Emit32(Out, (uint32_t) Data.st_ino); |
| 1332 | Emit32(Out, (uint32_t) Data.st_dev); |
| 1333 | Emit16(Out, (uint16_t) Data.st_mode); |
| 1334 | Emit64(Out, (uint64_t) Data.st_mtime); |
| 1335 | Emit64(Out, (uint64_t) Data.st_size); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1336 | |
| 1337 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1338 | } |
| 1339 | }; |
| 1340 | } // end anonymous namespace |
| 1341 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1342 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1343 | // Source Manager Serialization |
| 1344 | //===----------------------------------------------------------------------===// |
| 1345 | |
| 1346 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1347 | /// file. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1348 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1349 | using namespace llvm; |
| 1350 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1351 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1352 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1353 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1354 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1355 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1356 | // FileEntry fields. |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1357 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1358 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1359 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1360 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1361 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1365 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1366 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1367 | using namespace llvm; |
| 1368 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1369 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1370 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1371 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1372 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1373 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1374 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1375 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1379 | /// buffer's blob. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1380 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1381 | using namespace llvm; |
| 1382 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1383 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1384 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1385 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1388 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1389 | /// expansion. |
| 1390 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1391 | using namespace llvm; |
| 1392 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1393 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1394 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1395 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1396 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1397 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1398 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1399 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1402 | namespace { |
| 1403 | // Trait used for the on-disk hash table of header search information. |
| 1404 | class HeaderFileInfoTrait { |
| 1405 | ASTWriter &Writer; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1406 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1407 | // Keep track of the framework names we've used during serialization. |
| 1408 | SmallVector<char, 128> FrameworkStringData; |
| 1409 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1410 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1411 | public: |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 1412 | HeaderFileInfoTrait(ASTWriter &Writer) |
| 1413 | : Writer(Writer) { } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1414 | |
| 1415 | typedef const char *key_type; |
| 1416 | typedef key_type key_type_ref; |
| 1417 | |
| 1418 | typedef HeaderFileInfo data_type; |
| 1419 | typedef const data_type &data_type_ref; |
| 1420 | |
| 1421 | static unsigned ComputeHash(const char *path) { |
| 1422 | // The hash is based only on the filename portion of the key, so that the |
| 1423 | // reader can match based on filenames when symlinking or excess path |
| 1424 | // elements ("foo/../", "../") change the form of the name. However, |
| 1425 | // complete path is still the key. |
| 1426 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1427 | } |
| 1428 | |
| 1429 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1430 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1431 | data_type_ref Data) { |
| 1432 | unsigned StrLen = strlen(path); |
| 1433 | clang::io::Emit16(Out, StrLen); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1434 | unsigned DataLen = 1 + 2 + 4 + 4; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1435 | clang::io::Emit8(Out, DataLen); |
| 1436 | return std::make_pair(StrLen + 1, DataLen); |
| 1437 | } |
| 1438 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1439 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1440 | Out.write(path, KeyLen); |
| 1441 | } |
| 1442 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1443 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1444 | data_type_ref Data, unsigned DataLen) { |
| 1445 | using namespace clang::io; |
| 1446 | uint64_t Start = Out.tell(); (void)Start; |
| 1447 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1448 | unsigned char Flags = (Data.isImport << 5) |
| 1449 | | (Data.isPragmaOnce << 4) |
| 1450 | | (Data.DirInfo << 2) |
| 1451 | | (Data.Resolved << 1) |
| 1452 | | Data.IndexHeaderMapHeader; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1453 | Emit8(Out, (uint8_t)Flags); |
| 1454 | Emit16(Out, (uint16_t) Data.NumIncludes); |
| 1455 | |
| 1456 | if (!Data.ControllingMacro) |
| 1457 | Emit32(Out, (uint32_t)Data.ControllingMacroID); |
| 1458 | else |
| 1459 | Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1460 | |
| 1461 | unsigned Offset = 0; |
| 1462 | if (!Data.Framework.empty()) { |
| 1463 | // If this header refers into a framework, save the framework name. |
| 1464 | llvm::StringMap<unsigned>::iterator Pos |
| 1465 | = FrameworkNameOffset.find(Data.Framework); |
| 1466 | if (Pos == FrameworkNameOffset.end()) { |
| 1467 | Offset = FrameworkStringData.size() + 1; |
| 1468 | FrameworkStringData.append(Data.Framework.begin(), |
| 1469 | Data.Framework.end()); |
| 1470 | FrameworkStringData.push_back(0); |
| 1471 | |
| 1472 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1473 | } else |
| 1474 | Offset = Pos->second; |
| 1475 | } |
| 1476 | Emit32(Out, Offset); |
| 1477 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1478 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1479 | } |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1480 | |
| 1481 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1482 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1483 | }; |
| 1484 | } // end anonymous namespace |
| 1485 | |
| 1486 | /// \brief Write the header search block for the list of files that |
| 1487 | /// |
| 1488 | /// \param HS The header search structure to save. |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1489 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1490 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1491 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1492 | |
| 1493 | if (FilesByUID.size() > HS.header_file_size()) |
| 1494 | FilesByUID.resize(HS.header_file_size()); |
| 1495 | |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 1496 | HeaderFileInfoTrait GeneratorTrait(*this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1497 | OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1498 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1499 | unsigned NumHeaderSearchEntries = 0; |
| 1500 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1501 | const FileEntry *File = FilesByUID[UID]; |
| 1502 | if (!File) |
| 1503 | continue; |
| 1504 | |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1505 | // Use HeaderSearch's getFileInfo to make sure we get the HeaderFileInfo |
| 1506 | // from the external source if it was not provided already. |
| 1507 | const HeaderFileInfo &HFI = HS.getFileInfo(File); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1508 | if (HFI.External && Chain) |
| 1509 | continue; |
| 1510 | |
| 1511 | // Turn the file name into an absolute path, if it isn't already. |
| 1512 | const char *Filename = File->getName(); |
| 1513 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1514 | |
| 1515 | // If we performed any translation on the file name at all, we need to |
| 1516 | // save this string, since the generator will refer to it later. |
| 1517 | if (Filename != File->getName()) { |
| 1518 | Filename = strdup(Filename); |
| 1519 | SavedStrings.push_back(Filename); |
| 1520 | } |
| 1521 | |
| 1522 | Generator.insert(Filename, HFI, GeneratorTrait); |
| 1523 | ++NumHeaderSearchEntries; |
| 1524 | } |
| 1525 | |
| 1526 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1527 | SmallString<4096> TableData; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1528 | uint32_t BucketOffset; |
| 1529 | { |
| 1530 | llvm::raw_svector_ostream Out(TableData); |
| 1531 | // Make sure that no bucket is at offset 0 |
| 1532 | clang::io::Emit32(Out, 0); |
| 1533 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1534 | } |
| 1535 | |
| 1536 | // Create a blob abbreviation |
| 1537 | using namespace llvm; |
| 1538 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1539 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1540 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1541 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1542 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1543 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1544 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1545 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1546 | // Write the header search table |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1547 | RecordData Record; |
| 1548 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1549 | Record.push_back(BucketOffset); |
| 1550 | Record.push_back(NumHeaderSearchEntries); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1551 | Record.push_back(TableData.size()); |
| 1552 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1553 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); |
| 1554 | |
| 1555 | // Free all of the strings we had to duplicate. |
| 1556 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | 6444483 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1557 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1560 | /// \brief Writes the block containing the serialized form of the |
| 1561 | /// source manager. |
| 1562 | /// |
| 1563 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1564 | /// blob), indexed based on the file name, so that we only create |
| 1565 | /// entries for files that we actually need. In the common case (no |
| 1566 | /// errors), we probably won't have to create file entries for any of |
| 1567 | /// the files in the AST. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1568 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1569 | const Preprocessor &PP, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1570 | StringRef isysroot) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1571 | RecordData Record; |
| 1572 | |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1573 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1574 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1575 | |
| 1576 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | 828e18c | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1577 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1578 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1579 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1580 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1581 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1582 | // Write out the source location entry table. We skip the first |
| 1583 | // entry, which is always the same dummy entry. |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1584 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1585 | RecordData PreloadSLocs; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1586 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1587 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1588 | I != N; ++I) { |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1589 | // Get this source location entry. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1590 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1591 | FileID FID = FileID::get(I); |
| 1592 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1593 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1594 | // Record the offset of this source-location entry. |
| 1595 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1596 | |
| 1597 | // Figure out which record code to use. |
| 1598 | unsigned Code; |
| 1599 | if (SLoc->isFile()) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1600 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1601 | if (Cache->OrigEntry) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1602 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1603 | } else |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1604 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1605 | } else |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1606 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1607 | Record.clear(); |
| 1608 | Record.push_back(Code); |
| 1609 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1610 | // Starting offset of this entry within this module, so skip the dummy. |
| 1611 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1612 | if (SLoc->isFile()) { |
| 1613 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1614 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1615 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1616 | Record.push_back(File.hasLineDirectives()); |
| 1617 | |
| 1618 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1619 | if (Content->OrigEntry) { |
| 1620 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1621 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1622 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1623 | // The source location entry is a file. Emit input file ID. |
| 1624 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 1625 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1626 | |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1627 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1628 | |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1629 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1630 | if (FDI != FileDeclIDs.end()) { |
| 1631 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1632 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1633 | } else { |
| 1634 | Record.push_back(0); |
| 1635 | Record.push_back(0); |
| 1636 | } |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1638 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1639 | |
| 1640 | if (Content->BufferOverridden) { |
| 1641 | Record.clear(); |
| 1642 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
| 1643 | const llvm::MemoryBuffer *Buffer |
| 1644 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1645 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
| 1646 | StringRef(Buffer->getBufferStart(), |
| 1647 | Buffer->getBufferSize() + 1)); |
| 1648 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1649 | } else { |
| 1650 | // The source location entry is a buffer. The blob associated |
| 1651 | // with this entry contains the contents of the buffer. |
| 1652 | |
| 1653 | // We add one to the size so that we capture the trailing NULL |
| 1654 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1655 | // the reader side). |
Douglas Gregor | 36c35ba | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1656 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1657 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1658 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1659 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1660 | StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1661 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1662 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1663 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1664 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1665 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1666 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1667 | if (strcmp(Name, "<built-in>") == 0) { |
| 1668 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1669 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1670 | } |
| 1671 | } else { |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1672 | // The source location entry is a macro expansion. |
Chandler Carruth | 1728762 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1673 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 78df836 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1674 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1675 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | d21683c | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1676 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1677 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1678 | |
| 1679 | // Compute the token length for this macro expansion. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1680 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1681 | if (I + 1 != N) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1682 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1683 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1684 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1688 | Stream.ExitBlock(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1689 | |
| 1690 | if (SLocEntryOffsets.empty()) |
| 1691 | return; |
| 1692 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1693 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1694 | // table is used for lazily loading source-location information. |
| 1695 | using namespace llvm; |
| 1696 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1697 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1698 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1699 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1700 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1701 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1702 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1703 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1704 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1705 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1706 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1707 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1708 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1709 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1710 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1711 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1712 | |
| 1713 | // Write the line table. It depends on remapping working, so it must come |
| 1714 | // after the source location offsets. |
| 1715 | if (SourceMgr.hasLineTable()) { |
| 1716 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1717 | |
| 1718 | Record.clear(); |
| 1719 | // Emit the file names |
| 1720 | Record.push_back(LineTable.getNumFilenames()); |
| 1721 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1722 | // Emit the file name |
| 1723 | const char *Filename = LineTable.getFilename(I); |
| 1724 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1725 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1726 | Record.push_back(FilenameLen); |
| 1727 | if (FilenameLen) |
| 1728 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1729 | } |
| 1730 | |
| 1731 | // Emit the line entries |
| 1732 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1733 | L != LEnd; ++L) { |
| 1734 | // Only emit entries for local files. |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1735 | if (L->first.ID < 0) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1736 | continue; |
| 1737 | |
| 1738 | // Emit the file ID |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1739 | Record.push_back(L->first.ID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1740 | |
| 1741 | // Emit the line entries |
| 1742 | Record.push_back(L->second.size()); |
| 1743 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1744 | LEEnd = L->second.end(); |
| 1745 | LE != LEEnd; ++LE) { |
| 1746 | Record.push_back(LE->FileOffset); |
| 1747 | Record.push_back(LE->LineNo); |
| 1748 | Record.push_back(LE->FilenameID); |
| 1749 | Record.push_back((unsigned)LE->FileKind); |
| 1750 | Record.push_back(LE->IncludeOffset); |
| 1751 | } |
| 1752 | } |
| 1753 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1754 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1757 | //===----------------------------------------------------------------------===// |
| 1758 | // Preprocessor Serialization |
| 1759 | //===----------------------------------------------------------------------===// |
| 1760 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1761 | static int compareMacroDefinitions(const void *XPtr, const void *YPtr) { |
| 1762 | const std::pair<const IdentifierInfo *, MacroInfo *> &X = |
| 1763 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; |
| 1764 | const std::pair<const IdentifierInfo *, MacroInfo *> &Y = |
| 1765 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; |
| 1766 | return X.first->getName().compare(Y.first->getName()); |
| 1767 | } |
| 1768 | |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1769 | /// \brief Writes the block containing the serialized form of the |
| 1770 | /// preprocessor. |
| 1771 | /// |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1772 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1773 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 1774 | if (PPRec) |
| 1775 | WritePreprocessorDetail(*PPRec); |
| 1776 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1777 | RecordData Record; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1778 | |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1779 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1780 | if (PP.getCounterValue() != 0) { |
| 1781 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1782 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1783 | Record.clear(); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | // Enter the preprocessor block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1787 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1788 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1789 | // 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] | 1790 | // FIXME: use diagnostics subsystem for localization etc. |
| 1791 | if (PP.SawDateOrTime()) |
| 1792 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1793 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1794 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1795 | // Loop over all the macro definitions that are live at the end of the file, |
| 1796 | // emitting each to the PP section. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1797 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1798 | // Construct the list of macro definitions that need to be serialized. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1799 | SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1800 | MacrosToEmit; |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame^] | 1801 | llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1802 | for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1803 | E = PP.macro_end(Chain == 0); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1804 | I != E; ++I) { |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1805 | if (!IsModule || I->second->isPublic()) { |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame^] | 1806 | MacroDefinitionsSeen.insert(I->first); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1807 | MacrosToEmit.push_back(std::make_pair(I->first, I->second)); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1808 | } |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1809 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1810 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1811 | // Sort the set of macro definitions that need to be serialized by the |
| 1812 | // name of the macro, to provide a stable ordering. |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1813 | llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1814 | &compareMacroDefinitions); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1815 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1816 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 1817 | /// the local macro ID |
| 1818 | /// |
| 1819 | /// For each identifier that is associated with a macro, this map |
| 1820 | /// provides the offset into the bitstream where that macro is |
| 1821 | /// defined. |
| 1822 | std::vector<uint32_t> MacroOffsets; |
| 1823 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1824 | for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { |
| 1825 | const IdentifierInfo *Name = MacrosToEmit[I].first; |
Douglas Gregor | ee9b0ba | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 1826 | |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame^] | 1827 | for (MacroInfo *MI = MacrosToEmit[I].second; MI; |
| 1828 | MI = MI->getPreviousDefinition()) { |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1829 | MacroID ID = getMacroRef(MI); |
| 1830 | if (!ID) |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1831 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1832 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1833 | // Skip macros from a AST file if we're chaining. |
| 1834 | if (Chain && MI->isFromAST() && !MI->hasChangedAfterLoad()) |
| 1835 | continue; |
| 1836 | |
| 1837 | if (ID < FirstMacroID) { |
| 1838 | // This will have been dealt with via an update record. |
| 1839 | assert(MacroUpdates.count(MI) > 0 && "Missing macro update"); |
| 1840 | continue; |
| 1841 | } |
| 1842 | |
| 1843 | // Record the local offset of this macro. |
| 1844 | unsigned Index = ID - FirstMacroID; |
| 1845 | if (Index == MacroOffsets.size()) |
| 1846 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1847 | else { |
| 1848 | if (Index > MacroOffsets.size()) |
| 1849 | MacroOffsets.resize(Index + 1); |
| 1850 | |
| 1851 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 1852 | } |
| 1853 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1854 | AddIdentifierRef(Name, Record); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1855 | addMacroRef(MI, Record); |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1856 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1857 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
Argyrios Kyrtzidis | 8169b67 | 2013-01-07 19:16:23 +0000 | [diff] [blame] | 1858 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1859 | AddSourceLocation(MI->getUndefLoc(), Record); |
| 1860 | Record.push_back(MI->isUsed()); |
| 1861 | Record.push_back(MI->isPublic()); |
| 1862 | AddSourceLocation(MI->getVisibilityLocation(), Record); |
| 1863 | unsigned Code; |
| 1864 | if (MI->isObjectLike()) { |
| 1865 | Code = PP_MACRO_OBJECT_LIKE; |
| 1866 | } else { |
| 1867 | Code = PP_MACRO_FUNCTION_LIKE; |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1868 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1869 | Record.push_back(MI->isC99Varargs()); |
| 1870 | Record.push_back(MI->isGNUVarargs()); |
Eli Friedman | 4fa4b48 | 2012-11-14 02:18:46 +0000 | [diff] [blame] | 1871 | Record.push_back(MI->hasCommaPasting()); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1872 | Record.push_back(MI->getNumArgs()); |
| 1873 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1874 | I != E; ++I) |
| 1875 | AddIdentifierRef(*I, Record); |
| 1876 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1878 | // If we have a detailed preprocessing record, record the macro definition |
| 1879 | // ID that corresponds to this macro. |
| 1880 | if (PPRec) |
| 1881 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 1882 | |
| 1883 | Stream.EmitRecord(Code, Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1884 | Record.clear(); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1885 | |
| 1886 | // Emit the tokens array. |
| 1887 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1888 | // Note that we know that the preprocessor does not have any annotation |
| 1889 | // tokens in it because they are created by the parser, and thus can't |
| 1890 | // be in a macro definition. |
| 1891 | const Token &Tok = MI->getReplacementToken(TokNo); |
| 1892 | |
| 1893 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1894 | Record.push_back(Tok.getLength()); |
| 1895 | |
| 1896 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 1897 | // if it is needed. |
| 1898 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 1899 | // FIXME: Should translate token kind to a stable encoding. |
| 1900 | Record.push_back(Tok.getKind()); |
| 1901 | // FIXME: Should translate token flags to a stable encoding. |
| 1902 | Record.push_back(Tok.getFlags()); |
| 1903 | |
| 1904 | Stream.EmitRecord(PP_TOKEN, Record); |
| 1905 | Record.clear(); |
| 1906 | } |
| 1907 | ++NumMacros; |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1908 | } |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1909 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1910 | Stream.ExitBlock(); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1911 | |
| 1912 | // Write the offsets table for macro IDs. |
| 1913 | using namespace llvm; |
| 1914 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1915 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 1916 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 1917 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 1918 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1919 | |
| 1920 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1921 | Record.clear(); |
| 1922 | Record.push_back(MACRO_OFFSET); |
| 1923 | Record.push_back(MacroOffsets.size()); |
| 1924 | Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS); |
| 1925 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, |
| 1926 | data(MacroOffsets)); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | b6441ef | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 1930 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1931 | return; |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1932 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1933 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1934 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1935 | // Enter the preprocessor block. |
| 1936 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1937 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1938 | // If the preprocessor has a preprocessing record, emit it. |
| 1939 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1940 | using namespace llvm; |
| 1941 | |
| 1942 | // Set up the abbreviation for |
| 1943 | unsigned InclusionAbbrev = 0; |
| 1944 | { |
| 1945 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1946 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1947 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 1948 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 1949 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 1950 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1951 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1952 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1953 | } |
| 1954 | |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1955 | unsigned FirstPreprocessorEntityID |
| 1956 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 1957 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 1958 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1959 | RecordData Record; |
Argyrios Kyrtzidis | b6441ef | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 1960 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 1961 | EEnd = PPRec.local_end(); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1962 | E != EEnd; |
| 1963 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1964 | Record.clear(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1965 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1966 | PreprocessedEntityOffsets.push_back(PPEntityOffset((*E)->getSourceRange(), |
| 1967 | Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1968 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1969 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1970 | // Record this macro definition's ID. |
| 1971 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1972 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1973 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1974 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 1975 | continue; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1976 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1977 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1978 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 8f7c540 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1979 | Record.push_back(ME->isBuiltinMacro()); |
| 1980 | if (ME->isBuiltinMacro()) |
| 1981 | AddIdentifierRef(ME->getName(), Record); |
| 1982 | else |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1983 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1984 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1985 | continue; |
| 1986 | } |
| 1987 | |
| 1988 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 1989 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1990 | Record.push_back(ID->getFileName().size()); |
| 1991 | Record.push_back(ID->wasInQuotes()); |
| 1992 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 1993 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1994 | SmallString<64> Buffer; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1995 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 1996 | // Check that the FileEntry is not null because it was not resolved and |
| 1997 | // we create a PCH even with compiler errors. |
| 1998 | if (ID->getFile()) |
| 1999 | Buffer += ID->getFile()->getName(); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2000 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 2001 | continue; |
| 2002 | } |
| 2003 | |
| 2004 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2005 | } |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2006 | Stream.ExitBlock(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2007 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2008 | // Write the offsets table for the preprocessing record. |
| 2009 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2010 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2011 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2012 | // Write the offsets table for identifier IDs. |
| 2013 | using namespace llvm; |
| 2014 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2015 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2016 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2017 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2018 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2019 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2020 | Record.clear(); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2021 | Record.push_back(PPD_ENTITIES_OFFSETS); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2022 | Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2023 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
| 2024 | data(PreprocessedEntityOffsets)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2025 | } |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2028 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2029 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2030 | if (Known != SubmoduleIDs.end()) |
| 2031 | return Known->second; |
| 2032 | |
| 2033 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2034 | } |
| 2035 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2036 | /// \brief Compute the number of modules within the given tree (including the |
| 2037 | /// given module). |
| 2038 | static unsigned getNumberOfModules(Module *Mod) { |
| 2039 | unsigned ChildModules = 0; |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2040 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2041 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2042 | Sub != SubEnd; ++Sub) |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2043 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2044 | |
| 2045 | return ChildModules + 1; |
| 2046 | } |
| 2047 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2048 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 4bc8738d | 2011-12-05 16:35:23 +0000 | [diff] [blame] | 2049 | // Determine the dependencies of our module and each of it's submodules. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2050 | // FIXME: This feels like it belongs somewhere else, but there are no |
| 2051 | // other consumers of this information. |
| 2052 | SourceManager &SrcMgr = PP->getSourceManager(); |
| 2053 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
| 2054 | for (ASTContext::import_iterator I = Context->local_import_begin(), |
| 2055 | IEnd = Context->local_import_end(); |
| 2056 | I != IEnd; ++I) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2057 | if (Module *ImportedFrom |
| 2058 | = ModMap.inferModuleFromLocation(FullSourceLoc(I->getLocation(), |
| 2059 | SrcMgr))) { |
| 2060 | ImportedFrom->Imports.push_back(I->getImportedModule()); |
| 2061 | } |
| 2062 | } |
| 2063 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2064 | // Enter the submodule description block. |
| 2065 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
| 2066 | |
| 2067 | // Write the abbreviations needed for the submodules block. |
| 2068 | using namespace llvm; |
| 2069 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2070 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2071 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2072 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2073 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2074 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2075 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2076 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2077 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2078 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2079 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2080 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2081 | |
| 2082 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2083 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2084 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2085 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2086 | |
| 2087 | Abbrev = new BitCodeAbbrev(); |
| 2088 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2089 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2090 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2091 | |
| 2092 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2093 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2094 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2095 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2096 | |
| 2097 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2098 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2099 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2100 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2101 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2102 | Abbrev = new BitCodeAbbrev(); |
| 2103 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
| 2104 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
| 2105 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2106 | |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2107 | Abbrev = new BitCodeAbbrev(); |
| 2108 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2109 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2110 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2111 | |
Douglas Gregor | b6cbe51 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2112 | Abbrev = new BitCodeAbbrev(); |
| 2113 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2114 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2115 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2116 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2117 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2118 | // Write the submodule metadata block. |
| 2119 | RecordData Record; |
| 2120 | Record.push_back(getNumberOfModules(WritingModule)); |
| 2121 | Record.push_back(FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS); |
| 2122 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2123 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2124 | // Write all of the submodules. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2125 | std::queue<Module *> Q; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2126 | Q.push(WritingModule); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2127 | while (!Q.empty()) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2128 | Module *Mod = Q.front(); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2129 | Q.pop(); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2130 | unsigned ID = getSubmoduleID(Mod); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2131 | |
| 2132 | // Emit the definition of the block. |
| 2133 | Record.clear(); |
| 2134 | Record.push_back(SUBMODULE_DEFINITION); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2135 | Record.push_back(ID); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2136 | if (Mod->Parent) { |
| 2137 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
| 2138 | Record.push_back(SubmoduleIDs[Mod->Parent]); |
| 2139 | } else { |
| 2140 | Record.push_back(0); |
| 2141 | } |
| 2142 | Record.push_back(Mod->IsFramework); |
| 2143 | Record.push_back(Mod->IsExplicit); |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2144 | Record.push_back(Mod->IsSystem); |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2145 | Record.push_back(Mod->InferSubmodules); |
| 2146 | Record.push_back(Mod->InferExplicitSubmodules); |
| 2147 | Record.push_back(Mod->InferExportWildcard); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2148 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2149 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2150 | // Emit the requirements. |
| 2151 | for (unsigned I = 0, N = Mod->Requires.size(); I != N; ++I) { |
| 2152 | Record.clear(); |
| 2153 | Record.push_back(SUBMODULE_REQUIRES); |
| 2154 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, |
| 2155 | Mod->Requires[I].data(), |
| 2156 | Mod->Requires[I].size()); |
| 2157 | } |
| 2158 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2159 | // Emit the umbrella header, if there is one. |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 2160 | if (const FileEntry *UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2161 | Record.clear(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2162 | Record.push_back(SUBMODULE_UMBRELLA_HEADER); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2163 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 2164 | UmbrellaHeader->getName()); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2165 | } else if (const DirectoryEntry *UmbrellaDir = Mod->getUmbrellaDir()) { |
| 2166 | Record.clear(); |
| 2167 | Record.push_back(SUBMODULE_UMBRELLA_DIR); |
| 2168 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
| 2169 | UmbrellaDir->getName()); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | // Emit the headers. |
| 2173 | for (unsigned I = 0, N = Mod->Headers.size(); I != N; ++I) { |
| 2174 | Record.clear(); |
| 2175 | Record.push_back(SUBMODULE_HEADER); |
| 2176 | Stream.EmitRecordWithBlob(HeaderAbbrev, Record, |
| 2177 | Mod->Headers[I]->getName()); |
| 2178 | } |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2179 | // Emit the excluded headers. |
| 2180 | for (unsigned I = 0, N = Mod->ExcludedHeaders.size(); I != N; ++I) { |
| 2181 | Record.clear(); |
| 2182 | Record.push_back(SUBMODULE_EXCLUDED_HEADER); |
| 2183 | Stream.EmitRecordWithBlob(ExcludedHeaderAbbrev, Record, |
| 2184 | Mod->ExcludedHeaders[I]->getName()); |
| 2185 | } |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2186 | for (unsigned I = 0, N = Mod->TopHeaders.size(); I != N; ++I) { |
| 2187 | Record.clear(); |
| 2188 | Record.push_back(SUBMODULE_TOPHEADER); |
| 2189 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, |
| 2190 | Mod->TopHeaders[I]->getName()); |
| 2191 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2192 | |
| 2193 | // Emit the imports. |
| 2194 | if (!Mod->Imports.empty()) { |
| 2195 | Record.clear(); |
| 2196 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
Douglas Gregor | bab9f4a | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2197 | unsigned ImportedID = getSubmoduleID(Mod->Imports[I]); |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2198 | assert(ImportedID && "Unknown submodule!"); |
| 2199 | Record.push_back(ImportedID); |
| 2200 | } |
| 2201 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2202 | } |
| 2203 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2204 | // Emit the exports. |
| 2205 | if (!Mod->Exports.empty()) { |
| 2206 | Record.clear(); |
| 2207 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
Douglas Gregor | bab9f4a | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2208 | if (Module *Exported = Mod->Exports[I].getPointer()) { |
| 2209 | unsigned ExportedID = SubmoduleIDs[Exported]; |
| 2210 | assert(ExportedID > 0 && "Unknown submodule ID?"); |
| 2211 | Record.push_back(ExportedID); |
| 2212 | } else { |
| 2213 | Record.push_back(0); |
| 2214 | } |
| 2215 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2216 | Record.push_back(Mod->Exports[I].getInt()); |
| 2217 | } |
| 2218 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2219 | } |
Douglas Gregor | b6cbe51 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2220 | |
| 2221 | // Emit the link libraries. |
| 2222 | for (unsigned I = 0, N = Mod->LinkLibraries.size(); I != N; ++I) { |
| 2223 | Record.clear(); |
| 2224 | Record.push_back(SUBMODULE_LINK_LIBRARY); |
| 2225 | Record.push_back(Mod->LinkLibraries[I].IsFramework); |
| 2226 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, |
| 2227 | Mod->LinkLibraries[I].Library); |
| 2228 | } |
| 2229 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2230 | // Queue up the submodules of this module. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2231 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2232 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2233 | Sub != SubEnd; ++Sub) |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2234 | Q.push(*Sub); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | Stream.ExitBlock(); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2238 | |
| 2239 | assert((NextSubmoduleID - FirstSubmoduleID |
| 2240 | == getNumberOfModules(WritingModule)) && "Wrong # of submodules"); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2243 | serialization::SubmoduleID |
| 2244 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2245 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2246 | return 0; // No submodule |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2247 | |
| 2248 | // Find the module that owns this location. |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2249 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2250 | Module *OwningMod |
| 2251 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2252 | if (!OwningMod) |
| 2253 | return 0; |
| 2254 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2255 | // Check whether this submodule is part of our own module. |
| 2256 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2257 | return 0; |
| 2258 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2259 | return getSubmoduleID(OwningMod); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2262 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) { |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2263 | // FIXME: Make it work properly with modules. |
| 2264 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2265 | DiagStateIDMap; |
| 2266 | unsigned CurrID = 0; |
| 2267 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2268 | RecordData Record; |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2269 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2270 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2271 | I != E; ++I) { |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2272 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2273 | if (point.Loc.isInvalid()) |
| 2274 | continue; |
| 2275 | |
| 2276 | Record.push_back(point.Loc.getRawEncoding()); |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2277 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2278 | Record.push_back(DiagStateID); |
| 2279 | |
| 2280 | if (DiagStateID == 0) { |
| 2281 | DiagStateID = ++CurrID; |
| 2282 | for (DiagnosticsEngine::DiagState::const_iterator |
| 2283 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
| 2284 | if (I->second.isPragma()) { |
| 2285 | Record.push_back(I->first); |
| 2286 | Record.push_back(I->second.getMapping()); |
| 2287 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2288 | } |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2289 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2290 | // location. |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2291 | } |
| 2292 | } |
| 2293 | |
Argyrios Kyrtzidis | 60f7684 | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2294 | if (!Record.empty()) |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2295 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2298 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2299 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2300 | return; |
| 2301 | |
| 2302 | RecordData Record; |
| 2303 | |
| 2304 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2305 | using namespace llvm; |
| 2306 | |
| 2307 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2308 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2309 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2310 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2311 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2312 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2313 | // Write the base specifier offsets table. |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2314 | Record.clear(); |
| 2315 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 2316 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 2317 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2318 | data(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2321 | //===----------------------------------------------------------------------===// |
| 2322 | // Type Serialization |
| 2323 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2324 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2325 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2326 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2327 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2328 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2329 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2330 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2331 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | 55f48de | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2332 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2333 | // Record the offset for this type. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2334 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2335 | if (TypeOffsets.size() == Index) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2336 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2337 | else if (TypeOffsets.size() < Index) { |
| 2338 | TypeOffsets.resize(Index + 1); |
| 2339 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | RecordData Record; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2343 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2344 | // Emit the type's representation. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2345 | ASTTypeWriter W(*this, Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2346 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2347 | if (T.hasLocalNonFastQualifiers()) { |
| 2348 | Qualifiers Qs = T.getLocalQualifiers(); |
| 2349 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2350 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2351 | W.Code = TYPE_EXT_QUAL; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2352 | } else { |
| 2353 | switch (T->getTypeClass()) { |
| 2354 | // For all of the concrete, non-dependent types, call the |
| 2355 | // appropriate visitor function. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2356 | #define TYPE(Class, Base) \ |
Mike Stump | b716633 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 2357 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2358 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2359 | #include "clang/AST/TypeNodes.def" |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2360 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | // Emit the serialized record. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2364 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2365 | |
| 2366 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2367 | FlushStmts(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2370 | //===----------------------------------------------------------------------===// |
| 2371 | // Declaration Serialization |
| 2372 | //===----------------------------------------------------------------------===// |
| 2373 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2374 | /// \brief Write the block containing all of the declaration IDs |
| 2375 | /// lexically declared within the given DeclContext. |
| 2376 | /// |
| 2377 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2378 | /// bistream, or 0 if no block was written. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2379 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2380 | DeclContext *DC) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2381 | if (DC->decls_empty()) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2382 | return 0; |
| 2383 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2384 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2385 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2386 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2387 | SmallVector<KindDeclIDPair, 64> Decls; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2388 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 2389 | D != DEnd; ++D) |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2390 | Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2391 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2392 | ++NumLexicalDeclContexts; |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2393 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2394 | return Offset; |
| 2395 | } |
| 2396 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2397 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2398 | using namespace llvm; |
| 2399 | RecordData Record; |
| 2400 | |
| 2401 | // Write the type offsets array |
| 2402 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2403 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2404 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2405 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2406 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2407 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2408 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2409 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2410 | Record.push_back(TypeOffsets.size()); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2411 | Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2412 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2413 | |
| 2414 | // Write the declaration offsets array |
| 2415 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2416 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2417 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2418 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2419 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2420 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2421 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2422 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2423 | Record.push_back(DeclOffsets.size()); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2424 | Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2425 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2428 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2429 | using namespace llvm; |
| 2430 | RecordData Record; |
| 2431 | |
| 2432 | // Join the vectors of DeclIDs from all files. |
| 2433 | SmallVector<DeclID, 256> FileSortedIDs; |
| 2434 | for (FileDeclIDsTy::iterator |
| 2435 | FI = FileDeclIDs.begin(), FE = FileDeclIDs.end(); FI != FE; ++FI) { |
| 2436 | DeclIDInFileInfo &Info = *FI->second; |
| 2437 | Info.FirstDeclIndex = FileSortedIDs.size(); |
| 2438 | for (LocDeclIDsTy::iterator |
| 2439 | DI = Info.DeclIDs.begin(), DE = Info.DeclIDs.end(); DI != DE; ++DI) |
| 2440 | FileSortedIDs.push_back(DI->second); |
| 2441 | } |
| 2442 | |
| 2443 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2444 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2445 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2446 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2447 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 2448 | Record.push_back(FILE_SORTED_DECLS); |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2449 | Record.push_back(FileSortedIDs.size()); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2450 | Stream.EmitRecordWithBlob(AbbrevCode, Record, data(FileSortedIDs)); |
| 2451 | } |
| 2452 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2453 | void ASTWriter::WriteComments() { |
| 2454 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2455 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2456 | RecordData Record; |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2457 | for (ArrayRef<RawComment *>::iterator I = RawComments.begin(), |
| 2458 | E = RawComments.end(); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2459 | I != E; ++I) { |
| 2460 | Record.clear(); |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2461 | AddSourceRange((*I)->getSourceRange(), Record); |
| 2462 | Record.push_back((*I)->getKind()); |
| 2463 | Record.push_back((*I)->isTrailingComment()); |
| 2464 | Record.push_back((*I)->isAlmostTrailingComment()); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2465 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2466 | } |
| 2467 | Stream.ExitBlock(); |
| 2468 | } |
| 2469 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2470 | //===----------------------------------------------------------------------===// |
| 2471 | // Global Method Pool and Selector Serialization |
| 2472 | //===----------------------------------------------------------------------===// |
| 2473 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2474 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2475 | // 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] | 2476 | class ASTMethodPoolTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2477 | ASTWriter &Writer; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2478 | |
| 2479 | public: |
| 2480 | typedef Selector key_type; |
| 2481 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2482 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2483 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2484 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2485 | ObjCMethodList Instance, Factory; |
| 2486 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2487 | typedef const data_type& data_type_ref; |
| 2488 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2489 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2490 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2491 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2492 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2494 | |
| 2495 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2496 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2497 | data_type_ref Methods) { |
| 2498 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 2499 | clang::io::Emit16(Out, KeyLen); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2500 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2501 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2502 | Method = Method->Next) |
| 2503 | if (Method->Method) |
| 2504 | DataLen += 4; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2505 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2506 | Method = Method->Next) |
| 2507 | if (Method->Method) |
| 2508 | DataLen += 4; |
| 2509 | clang::io::Emit16(Out, DataLen); |
| 2510 | return std::make_pair(KeyLen, DataLen); |
| 2511 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2512 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2513 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2514 | uint64_t Start = Out.tell(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2515 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2516 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2517 | unsigned N = Sel.getNumArgs(); |
| 2518 | clang::io::Emit16(Out, N); |
| 2519 | if (N == 0) |
| 2520 | N = 1; |
| 2521 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2522 | clang::io::Emit32(Out, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2523 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 2524 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2525 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2526 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2527 | data_type_ref Methods, unsigned DataLen) { |
| 2528 | uint64_t Start = Out.tell(); (void)Start; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2529 | clang::io::Emit32(Out, Methods.ID); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2530 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2531 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2532 | Method = Method->Next) |
| 2533 | if (Method->Method) |
| 2534 | ++NumInstanceMethods; |
| 2535 | |
| 2536 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2537 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2538 | Method = Method->Next) |
| 2539 | if (Method->Method) |
| 2540 | ++NumFactoryMethods; |
| 2541 | |
| 2542 | clang::io::Emit16(Out, NumInstanceMethods); |
| 2543 | clang::io::Emit16(Out, NumFactoryMethods); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2544 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2545 | Method = Method->Next) |
| 2546 | if (Method->Method) |
| 2547 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2548 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2549 | Method = Method->Next) |
| 2550 | if (Method->Method) |
| 2551 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2552 | |
| 2553 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2554 | } |
| 2555 | }; |
| 2556 | } // end anonymous namespace |
| 2557 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2558 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2559 | /// |
| 2560 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2561 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2562 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2563 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2564 | using namespace llvm; |
| 2565 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2566 | // Do we have to do anything at all? |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2567 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2568 | return; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2569 | unsigned NumTableEntries = 0; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2570 | // 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] | 2571 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2572 | OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2573 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2575 | // Create the on-disk hash table representation. We walk through every |
| 2576 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2577 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2578 | for (llvm::DenseMap<Selector, SelectorID>::iterator |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2579 | I = SelectorIDs.begin(), E = SelectorIDs.end(); |
| 2580 | I != E; ++I) { |
| 2581 | Selector S = I->first; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2582 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2583 | ASTMethodPoolTrait::data_type Data = { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2584 | I->second, |
| 2585 | ObjCMethodList(), |
| 2586 | ObjCMethodList() |
| 2587 | }; |
| 2588 | if (F != SemaRef.MethodPool.end()) { |
| 2589 | Data.Instance = F->second.first; |
| 2590 | Data.Factory = F->second.second; |
| 2591 | } |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2592 | // 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] | 2593 | // changed. |
| 2594 | if (Chain && I->second < FirstSelectorID) { |
| 2595 | // Selector already exists. Did it change? |
| 2596 | bool changed = false; |
| 2597 | for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; |
| 2598 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2599 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2600 | changed = true; |
| 2601 | } |
| 2602 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; |
| 2603 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2604 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2605 | changed = true; |
| 2606 | } |
| 2607 | if (!changed) |
| 2608 | continue; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2609 | } else if (Data.Instance.Method || Data.Factory.Method) { |
| 2610 | // A new method pool entry. |
| 2611 | ++NumTableEntries; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2612 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2613 | Generator.insert(S, Data, Trait); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2616 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2617 | SmallString<4096> MethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2618 | uint32_t BucketOffset; |
| 2619 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2620 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2621 | llvm::raw_svector_ostream Out(MethodPool); |
| 2622 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2623 | clang::io::Emit32(Out, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2624 | BucketOffset = Generator.Emit(Out, Trait); |
| 2625 | } |
| 2626 | |
| 2627 | // Create a blob abbreviation |
| 2628 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2629 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2630 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2631 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2632 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2633 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2634 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2635 | // Write the method pool |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2636 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2637 | Record.push_back(METHOD_POOL); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2638 | Record.push_back(BucketOffset); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2639 | Record.push_back(NumTableEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2640 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2641 | |
| 2642 | // Create a blob abbreviation for the selector table offsets. |
| 2643 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2644 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2645 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2646 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2647 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2648 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2649 | |
| 2650 | // Write the selector offsets table. |
| 2651 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2652 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2653 | Record.push_back(SelectorOffsets.size()); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2654 | Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2655 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2656 | data(SelectorOffsets)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2657 | } |
| 2658 | } |
| 2659 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2660 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2661 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2662 | using namespace llvm; |
| 2663 | if (SemaRef.ReferencedSelectors.empty()) |
| 2664 | return; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2665 | |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2666 | RecordData Record; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2667 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2668 | // 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] | 2669 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 2670 | // headers, probably not worth it. It's not a correctness issue. |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2671 | for (DenseMap<Selector, SourceLocation>::iterator S = |
| 2672 | SemaRef.ReferencedSelectors.begin(), |
| 2673 | E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { |
| 2674 | Selector Sel = (*S).first; |
| 2675 | SourceLocation Loc = (*S).second; |
| 2676 | AddSelectorRef(Sel, Record); |
| 2677 | AddSourceLocation(Loc, Record); |
| 2678 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2679 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2682 | //===----------------------------------------------------------------------===// |
| 2683 | // Identifier Table Serialization |
| 2684 | //===----------------------------------------------------------------------===// |
| 2685 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2686 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2687 | class ASTIdentifierTableTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2688 | ASTWriter &Writer; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2689 | Preprocessor &PP; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2690 | IdentifierResolver &IdResolver; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2691 | bool IsModule; |
| 2692 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2693 | /// \brief Determines whether this is an "interesting" identifier |
| 2694 | /// that needs a full IdentifierInfo structure written into the hash |
| 2695 | /// table. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2696 | bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) { |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2697 | if (II->isPoisoned() || |
| 2698 | II->isExtensionToken() || |
| 2699 | II->getObjCOrBuiltinID() || |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2700 | II->hasRevertedTokenIDToIdentifier() || |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2701 | II->getFETokenInfo<void>()) |
| 2702 | return true; |
| 2703 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2704 | return hadMacroDefinition(II, Macro); |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2705 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2706 | |
| 2707 | bool hadMacroDefinition(IdentifierInfo *II, MacroInfo *&Macro) { |
| 2708 | if (!II->hadMacroDefinition()) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2709 | return false; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2710 | |
| 2711 | if (Macro || (Macro = PP.getMacroInfoHistory(II))) |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 2712 | return !Macro->isBuiltinMacro() && (!IsModule || Macro->isPublic()); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2713 | |
| 2714 | return false; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2717 | public: |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2718 | typedef IdentifierInfo* key_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2719 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2720 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2721 | typedef IdentID data_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2722 | typedef data_type data_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2723 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2724 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
| 2725 | IdentifierResolver &IdResolver, bool IsModule) |
| 2726 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule) { } |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2727 | |
| 2728 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 2729 | return llvm::HashString(II->getName()); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2730 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2731 | |
| 2732 | std::pair<unsigned,unsigned> |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2733 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2734 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2735 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2736 | MacroInfo *Macro = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2737 | if (isInterestingIdentifier(II, Macro)) { |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2738 | DataLen += 2; // 2 bytes for builtin ID |
| 2739 | DataLen += 2; // 2 bytes for flags |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame^] | 2740 | if (hadMacroDefinition(II, Macro)) { |
| 2741 | for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { |
| 2742 | if (Writer.getMacroRef(M) != 0) |
| 2743 | DataLen += 4; |
| 2744 | } |
| 2745 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2746 | DataLen += 4; |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame^] | 2747 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2748 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2749 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 2750 | DEnd = IdResolver.end(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2751 | D != DEnd; ++D) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2752 | DataLen += sizeof(DeclID); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2753 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2754 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 2755 | // We emit the key length after the data length so that every |
| 2756 | // string is preceded by a 16-bit length. This matches the PTH |
| 2757 | // format for storing identifiers. |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2758 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2759 | return std::make_pair(KeyLen, DataLen); |
| 2760 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2761 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2762 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2763 | unsigned KeyLen) { |
| 2764 | // Record the location of the key data. This is used when generating |
| 2765 | // the mapping from persistent IDs to strings. |
| 2766 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2767 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2768 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2769 | |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2770 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2771 | IdentID ID, unsigned) { |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2772 | MacroInfo *Macro = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2773 | if (!isInterestingIdentifier(II, Macro)) { |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2774 | clang::io::Emit32(Out, ID << 1); |
| 2775 | return; |
| 2776 | } |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2777 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2778 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2779 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 2780 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
| 2781 | clang::io::Emit16(Out, Bits); |
| 2782 | Bits = 0; |
| 2783 | bool HadMacroDefinition = hadMacroDefinition(II, Macro); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2784 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2785 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 2786 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 2787 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2788 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2789 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2790 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2791 | if (HadMacroDefinition) { |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame^] | 2792 | // Write all of the macro IDs associated with this identifier. |
| 2793 | for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { |
| 2794 | if (MacroID ID = Writer.getMacroRef(M)) |
| 2795 | clang::io::Emit32(Out, ID); |
| 2796 | } |
| 2797 | |
| 2798 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2799 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2800 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2801 | // Emit the declaration IDs in reverse order, because the |
| 2802 | // IdentifierResolver provides the declarations as they would be |
| 2803 | // visible (e.g., the function "stat" would come before the struct |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2804 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 2805 | // (so we need to see the struct "status" before the function "status"). |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2806 | // Only emit declarations that aren't from a chained PCH, though. |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2807 | SmallVector<Decl *, 16> Decls(IdResolver.begin(II), |
| 2808 | IdResolver.end()); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2809 | for (SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2810 | DEnd = Decls.rend(); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2811 | D != DEnd; ++D) |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 2812 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2813 | } |
| 2814 | }; |
| 2815 | } // end anonymous namespace |
| 2816 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2817 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2818 | /// |
| 2819 | /// The identifier table consists of a blob containing string data |
| 2820 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 2821 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2822 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 2823 | IdentifierResolver &IdResolver, |
| 2824 | bool IsModule) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2825 | using namespace llvm; |
| 2826 | |
| 2827 | // Create and write out the blob that contains the identifier |
| 2828 | // strings. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2829 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2830 | OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2831 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2832 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2833 | // Look for any identifiers that were named while processing the |
| 2834 | // headers, but are otherwise not needed. We add these to the hash |
| 2835 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2836 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2837 | // file. |
| 2838 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 2839 | IDEnd = PP.getIdentifierTable().end(); |
| 2840 | ID != IDEnd; ++ID) |
| 2841 | getIdentifierRef(ID->second); |
| 2842 | |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2843 | // Create the on-disk hash table representation. We only store offsets |
| 2844 | // for identifiers that appear here for the first time. |
| 2845 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2846 | for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2847 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 2848 | ID != IDEnd; ++ID) { |
| 2849 | assert(ID->first && "NULL identifier in identifier table"); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2850 | if (!Chain || !ID->first->isFromAST() || |
| 2851 | ID->first->hasChangedSinceDeserialization()) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2852 | Generator.insert(const_cast<IdentifierInfo *>(ID->first), ID->second, |
| 2853 | Trait); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2854 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2855 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2856 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2857 | SmallString<4096> IdentifierTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2858 | uint32_t BucketOffset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2859 | { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2860 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2861 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2862 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2863 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2864 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | // Create a blob abbreviation |
| 2868 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2869 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2870 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2871 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2872 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2873 | |
| 2874 | // Write the identifier table |
| 2875 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2876 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2877 | Record.push_back(BucketOffset); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2878 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2882 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2883 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2884 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2885 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2886 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2887 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2888 | |
| 2889 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2890 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2891 | Record.push_back(IdentifierOffsets.size()); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2892 | Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2893 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2894 | data(IdentifierOffsets)); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2897 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2898 | // DeclContext's Name Lookup Table Serialization |
| 2899 | //===----------------------------------------------------------------------===// |
| 2900 | |
| 2901 | namespace { |
| 2902 | // Trait used for the on-disk hash table used in the method pool. |
| 2903 | class ASTDeclContextNameLookupTrait { |
| 2904 | ASTWriter &Writer; |
| 2905 | |
| 2906 | public: |
| 2907 | typedef DeclarationName key_type; |
| 2908 | typedef key_type key_type_ref; |
| 2909 | |
| 2910 | typedef DeclContext::lookup_result data_type; |
| 2911 | typedef const data_type& data_type_ref; |
| 2912 | |
| 2913 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 2914 | |
| 2915 | unsigned ComputeHash(DeclarationName Name) { |
| 2916 | llvm::FoldingSetNodeID ID; |
| 2917 | ID.AddInteger(Name.getNameKind()); |
| 2918 | |
| 2919 | switch (Name.getNameKind()) { |
| 2920 | case DeclarationName::Identifier: |
| 2921 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 2922 | break; |
| 2923 | case DeclarationName::ObjCZeroArgSelector: |
| 2924 | case DeclarationName::ObjCOneArgSelector: |
| 2925 | case DeclarationName::ObjCMultiArgSelector: |
| 2926 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 2927 | break; |
| 2928 | case DeclarationName::CXXConstructorName: |
| 2929 | case DeclarationName::CXXDestructorName: |
| 2930 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2931 | break; |
| 2932 | case DeclarationName::CXXOperatorName: |
| 2933 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 2934 | break; |
| 2935 | case DeclarationName::CXXLiteralOperatorName: |
| 2936 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 2937 | case DeclarationName::CXXUsingDirective: |
| 2938 | break; |
| 2939 | } |
| 2940 | |
| 2941 | return ID.ComputeHash(); |
| 2942 | } |
| 2943 | |
| 2944 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2945 | EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2946 | data_type_ref Lookup) { |
| 2947 | unsigned KeyLen = 1; |
| 2948 | switch (Name.getNameKind()) { |
| 2949 | case DeclarationName::Identifier: |
| 2950 | case DeclarationName::ObjCZeroArgSelector: |
| 2951 | case DeclarationName::ObjCOneArgSelector: |
| 2952 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2953 | case DeclarationName::CXXLiteralOperatorName: |
| 2954 | KeyLen += 4; |
| 2955 | break; |
| 2956 | case DeclarationName::CXXOperatorName: |
| 2957 | KeyLen += 1; |
| 2958 | break; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2959 | case DeclarationName::CXXConstructorName: |
| 2960 | case DeclarationName::CXXDestructorName: |
| 2961 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2962 | case DeclarationName::CXXUsingDirective: |
| 2963 | break; |
| 2964 | } |
| 2965 | clang::io::Emit16(Out, KeyLen); |
| 2966 | |
| 2967 | // 2 bytes for num of decls and 4 for each DeclID. |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2968 | unsigned DataLen = 2 + 4 * Lookup.size(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2969 | clang::io::Emit16(Out, DataLen); |
| 2970 | |
| 2971 | return std::make_pair(KeyLen, DataLen); |
| 2972 | } |
| 2973 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2974 | void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2975 | using namespace clang::io; |
| 2976 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2977 | Emit8(Out, Name.getNameKind()); |
| 2978 | switch (Name.getNameKind()) { |
| 2979 | case DeclarationName::Identifier: |
| 2980 | Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2981 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2982 | case DeclarationName::ObjCZeroArgSelector: |
| 2983 | case DeclarationName::ObjCOneArgSelector: |
| 2984 | case DeclarationName::ObjCMultiArgSelector: |
| 2985 | Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2986 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2987 | case DeclarationName::CXXOperatorName: |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2988 | assert(Name.getCXXOverloadedOperator() < NUM_OVERLOADED_OPERATORS && |
| 2989 | "Invalid operator?"); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2990 | Emit8(Out, Name.getCXXOverloadedOperator()); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2991 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2992 | case DeclarationName::CXXLiteralOperatorName: |
| 2993 | Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2994 | return; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2995 | case DeclarationName::CXXConstructorName: |
| 2996 | case DeclarationName::CXXDestructorName: |
| 2997 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2998 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2999 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3000 | } |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3001 | |
| 3002 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3005 | void EmitData(raw_ostream& Out, key_type_ref, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3006 | data_type Lookup, unsigned DataLen) { |
| 3007 | uint64_t Start = Out.tell(); (void)Start; |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3008 | clang::io::Emit16(Out, Lookup.size()); |
| 3009 | for (DeclContext::lookup_iterator I = Lookup.begin(), E = Lookup.end(); |
| 3010 | I != E; ++I) |
| 3011 | clang::io::Emit32(Out, Writer.GetDeclRef(*I)); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3012 | |
| 3013 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3014 | } |
| 3015 | }; |
| 3016 | } // end anonymous namespace |
| 3017 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3018 | /// \brief Write the block containing all of the declaration IDs |
| 3019 | /// visible from the given DeclContext. |
| 3020 | /// |
| 3021 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3022 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3023 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3024 | DeclContext *DC) { |
| 3025 | if (DC->getPrimaryContext() != DC) |
| 3026 | return 0; |
| 3027 | |
| 3028 | // Since there is no name lookup into functions or methods, don't bother to |
| 3029 | // build a visible-declarations table for these entities. |
| 3030 | if (DC->isFunctionOrMethod()) |
| 3031 | return 0; |
| 3032 | |
| 3033 | // If not in C++, we perform name lookup for the translation unit via the |
| 3034 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 3035 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 3036 | // 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] | 3037 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3038 | return 0; |
| 3039 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3040 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3041 | // although we have two very different code paths, the serialized |
| 3042 | // representation is the same for both cases: a declaration name, |
| 3043 | // followed by a size, followed by references to the visible |
| 3044 | // declarations that have that name. |
| 3045 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | c5d3e80 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3046 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3047 | if (!Map || Map->empty()) |
| 3048 | return 0; |
| 3049 | |
| 3050 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 3051 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3052 | |
| 3053 | // Create the on-disk hash table representation. |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3054 | DeclarationName ConversionName; |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3055 | SmallVector<NamedDecl *, 4> ConversionDecls; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3056 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 3057 | D != DEnd; ++D) { |
| 3058 | DeclarationName Name = D->first; |
| 3059 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3060 | if (!Result.empty()) { |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3061 | if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 3062 | // Hash all conversion function names to the same name. The actual |
| 3063 | // type information in conversion function name is not used in the |
| 3064 | // key (since such type information is not stable across different |
| 3065 | // modules), so the intended effect is to coalesce all of the conversion |
| 3066 | // functions under a single key. |
| 3067 | if (!ConversionName) |
| 3068 | ConversionName = Name; |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3069 | ConversionDecls.append(Result.begin(), Result.end()); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3070 | continue; |
| 3071 | } |
| 3072 | |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 3073 | Generator.insert(Name, Result, Trait); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3074 | } |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3075 | } |
| 3076 | |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3077 | // Add the conversion functions |
| 3078 | if (!ConversionDecls.empty()) { |
| 3079 | Generator.insert(ConversionName, |
| 3080 | DeclContext::lookup_result(ConversionDecls.begin(), |
| 3081 | ConversionDecls.end()), |
| 3082 | Trait); |
| 3083 | } |
| 3084 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3085 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3086 | SmallString<4096> LookupTable; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3087 | uint32_t BucketOffset; |
| 3088 | { |
| 3089 | llvm::raw_svector_ostream Out(LookupTable); |
| 3090 | // Make sure that no bucket is at offset 0 |
| 3091 | clang::io::Emit32(Out, 0); |
| 3092 | BucketOffset = Generator.Emit(Out, Trait); |
| 3093 | } |
| 3094 | |
| 3095 | // Write the lookup table |
| 3096 | RecordData Record; |
| 3097 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 3098 | Record.push_back(BucketOffset); |
| 3099 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
| 3100 | LookupTable.str()); |
| 3101 | |
| 3102 | Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); |
| 3103 | ++NumVisibleDeclContexts; |
| 3104 | return Offset; |
| 3105 | } |
| 3106 | |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3107 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3108 | /// |
| 3109 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3110 | /// 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] | 3111 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3112 | /// enumeration members (in C++11). |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3113 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3114 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 3115 | if (!Map || Map->empty()) |
| 3116 | return; |
| 3117 | |
| 3118 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 3119 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3120 | |
| 3121 | // Create the hash table. |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3122 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 3123 | D != DEnd; ++D) { |
| 3124 | DeclarationName Name = D->first; |
| 3125 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3126 | // For any name that appears in this table, the results are complete, i.e. |
| 3127 | // they overwrite results from previous PCHs. Merging is always a mess. |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3128 | if (!Result.empty()) |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 3129 | Generator.insert(Name, Result, Trait); |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3133 | SmallString<4096> LookupTable; |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3134 | uint32_t BucketOffset; |
| 3135 | { |
| 3136 | llvm::raw_svector_ostream Out(LookupTable); |
| 3137 | // Make sure that no bucket is at offset 0 |
| 3138 | clang::io::Emit32(Out, 0); |
| 3139 | BucketOffset = Generator.Emit(Out, Trait); |
| 3140 | } |
| 3141 | |
| 3142 | // Write the lookup table |
| 3143 | RecordData Record; |
| 3144 | Record.push_back(UPDATE_VISIBLE); |
| 3145 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 3146 | Record.push_back(BucketOffset); |
| 3147 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); |
| 3148 | } |
| 3149 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3150 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3151 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 3152 | RecordData Record; |
| 3153 | Record.push_back(Opts.fp_contract); |
| 3154 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3155 | } |
| 3156 | |
| 3157 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3158 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3159 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3160 | return; |
| 3161 | |
| 3162 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3163 | RecordData Record; |
| 3164 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3165 | #include "clang/Basic/OpenCLExtensions.def" |
| 3166 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3167 | } |
| 3168 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3169 | void ASTWriter::WriteRedeclarations() { |
| 3170 | RecordData LocalRedeclChains; |
| 3171 | SmallVector<serialization::LocalRedeclarationsInfo, 2> LocalRedeclsMap; |
| 3172 | |
| 3173 | for (unsigned I = 0, N = Redeclarations.size(); I != N; ++I) { |
| 3174 | Decl *First = Redeclarations[I]; |
| 3175 | assert(First->getPreviousDecl() == 0 && "Not the first declaration?"); |
| 3176 | |
| 3177 | Decl *MostRecent = First->getMostRecentDecl(); |
| 3178 | |
| 3179 | // If we only have a single declaration, there is no point in storing |
| 3180 | // a redeclaration chain. |
| 3181 | if (First == MostRecent) |
| 3182 | continue; |
| 3183 | |
| 3184 | unsigned Offset = LocalRedeclChains.size(); |
| 3185 | unsigned Size = 0; |
| 3186 | LocalRedeclChains.push_back(0); // Placeholder for the size. |
| 3187 | |
| 3188 | // Collect the set of local redeclarations of this declaration. |
| 3189 | for (Decl *Prev = MostRecent; Prev != First; |
| 3190 | Prev = Prev->getPreviousDecl()) { |
| 3191 | if (!Prev->isFromASTFile()) { |
| 3192 | AddDeclRef(Prev, LocalRedeclChains); |
| 3193 | ++Size; |
| 3194 | } |
| 3195 | } |
| 3196 | LocalRedeclChains[Offset] = Size; |
| 3197 | |
| 3198 | // Reverse the set of local redeclarations, so that we store them in |
| 3199 | // order (since we found them in reverse order). |
| 3200 | std::reverse(LocalRedeclChains.end() - Size, LocalRedeclChains.end()); |
| 3201 | |
| 3202 | // Add the mapping from the first ID to the set of local declarations. |
| 3203 | LocalRedeclarationsInfo Info = { getDeclID(First), Offset }; |
| 3204 | LocalRedeclsMap.push_back(Info); |
| 3205 | |
| 3206 | assert(N == Redeclarations.size() && |
| 3207 | "Deserialized a declaration we shouldn't have"); |
| 3208 | } |
| 3209 | |
| 3210 | if (LocalRedeclChains.empty()) |
| 3211 | return; |
| 3212 | |
| 3213 | // Sort the local redeclarations map by the first declaration ID, |
| 3214 | // since the reader will be performing binary searches on this information. |
| 3215 | llvm::array_pod_sort(LocalRedeclsMap.begin(), LocalRedeclsMap.end()); |
| 3216 | |
| 3217 | // Emit the local redeclarations map. |
| 3218 | using namespace llvm; |
| 3219 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3220 | Abbrev->Add(BitCodeAbbrevOp(LOCAL_REDECLARATIONS_MAP)); |
| 3221 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3222 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3223 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3224 | |
| 3225 | RecordData Record; |
| 3226 | Record.push_back(LOCAL_REDECLARATIONS_MAP); |
| 3227 | Record.push_back(LocalRedeclsMap.size()); |
| 3228 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3229 | reinterpret_cast<char*>(LocalRedeclsMap.data()), |
| 3230 | LocalRedeclsMap.size() * sizeof(LocalRedeclarationsInfo)); |
| 3231 | |
| 3232 | // Emit the redeclaration chains. |
| 3233 | Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedeclChains); |
| 3234 | } |
| 3235 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3236 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3237 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3238 | RecordData Categories; |
| 3239 | |
| 3240 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3241 | unsigned Size = 0; |
| 3242 | unsigned StartIndex = Categories.size(); |
| 3243 | |
| 3244 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3245 | |
| 3246 | // Allocate space for the size. |
| 3247 | Categories.push_back(0); |
| 3248 | |
| 3249 | // Add the categories. |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3250 | for (ObjCInterfaceDecl::known_categories_iterator |
| 3251 | Cat = Class->known_categories_begin(), |
| 3252 | CatEnd = Class->known_categories_end(); |
| 3253 | Cat != CatEnd; ++Cat, ++Size) { |
| 3254 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 3255 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | // Update the size. |
| 3259 | Categories[StartIndex] = Size; |
| 3260 | |
| 3261 | // Record this interface -> category map. |
| 3262 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3263 | CategoriesMap.push_back(CatInfo); |
| 3264 | } |
| 3265 | |
| 3266 | // Sort the categories map by the definition ID, since the reader will be |
| 3267 | // performing binary searches on this information. |
| 3268 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3269 | |
| 3270 | // Emit the categories map. |
| 3271 | using namespace llvm; |
| 3272 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3273 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3274 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3275 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3276 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3277 | |
| 3278 | RecordData Record; |
| 3279 | Record.push_back(OBJC_CATEGORIES_MAP); |
| 3280 | Record.push_back(CategoriesMap.size()); |
| 3281 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3282 | reinterpret_cast<char*>(CategoriesMap.data()), |
| 3283 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
| 3284 | |
| 3285 | // Emit the category lists. |
| 3286 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3287 | } |
| 3288 | |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3289 | void ASTWriter::WriteMergedDecls() { |
| 3290 | if (!Chain || Chain->MergedDecls.empty()) |
| 3291 | return; |
| 3292 | |
| 3293 | RecordData Record; |
| 3294 | for (ASTReader::MergedDeclsMap::iterator I = Chain->MergedDecls.begin(), |
| 3295 | IEnd = Chain->MergedDecls.end(); |
| 3296 | I != IEnd; ++I) { |
Douglas Gregor | b6b60c1 | 2012-01-05 22:27:05 +0000 | [diff] [blame] | 3297 | DeclID CanonID = I->first->isFromASTFile()? I->first->getGlobalID() |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3298 | : getDeclID(I->first); |
| 3299 | assert(CanonID && "Merged declaration not known?"); |
| 3300 | |
| 3301 | Record.push_back(CanonID); |
| 3302 | Record.push_back(I->second.size()); |
| 3303 | Record.append(I->second.begin(), I->second.end()); |
| 3304 | } |
| 3305 | Stream.EmitRecord(MERGED_DECLARATIONS, Record); |
| 3306 | } |
| 3307 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3308 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3309 | // General Serialization Routines |
| 3310 | //===----------------------------------------------------------------------===// |
| 3311 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3312 | /// \brief Write a record containing the given attributes. |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3313 | void ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, |
| 3314 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4eb9fc0 | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3315 | Record.push_back(Attrs.size()); |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3316 | for (ArrayRef<const Attr *>::iterator i = Attrs.begin(), |
| 3317 | e = Attrs.end(); i != e; ++i){ |
| 3318 | const Attr *A = *i; |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3319 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 768d6ca | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 3320 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3321 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3322 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3323 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3324 | } |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3327 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3328 | Record.push_back(Str.size()); |
| 3329 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 3330 | } |
| 3331 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3332 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 3333 | RecordDataImpl &Record) { |
| 3334 | Record.push_back(Version.getMajor()); |
| 3335 | if (llvm::Optional<unsigned> Minor = Version.getMinor()) |
| 3336 | Record.push_back(*Minor + 1); |
| 3337 | else |
| 3338 | Record.push_back(0); |
| 3339 | if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) |
| 3340 | Record.push_back(*Subminor + 1); |
| 3341 | else |
| 3342 | Record.push_back(0); |
| 3343 | } |
| 3344 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3345 | /// \brief Note that the identifier II occurs at the given offset |
| 3346 | /// within the identifier table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3347 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3348 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3349 | // 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] | 3350 | // up earlier in the chain and thus don't need an offset. |
| 3351 | if (ID >= FirstIdentID) |
| 3352 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3353 | } |
| 3354 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3355 | /// \brief Note that the selector Sel occurs at the given offset |
| 3356 | /// within the method pool/selector table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3357 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3358 | unsigned ID = SelectorIDs[Sel]; |
| 3359 | assert(ID && "Unknown selector"); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3360 | // Don't record offsets for selectors that are also available in a different |
| 3361 | // file. |
| 3362 | if (ID < FirstSelectorID) |
| 3363 | return; |
| 3364 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3367 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3368 | : Stream(Stream), Context(0), PP(0), Chain(0), WritingModule(0), |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3369 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 3370 | ASTHasCompilerErrors(false), |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3371 | FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3372 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3373 | FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), |
| 3374 | FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID), |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3375 | FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
| 3376 | NextSubmoduleID(FirstSubmoduleID), |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3377 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3378 | CollectedStmts(&StmtsToEmit), |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3379 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3380 | NumVisibleDeclContexts(0), |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3381 | NextCXXBaseSpecifiersID(1), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3382 | DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3383 | DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), |
| 3384 | DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), |
| 3385 | DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3386 | DeclTypedefAbbrev(0), |
| 3387 | DeclVarAbbrev(0), DeclFieldAbbrev(0), |
| 3388 | DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3389 | { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3390 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3391 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3392 | ASTWriter::~ASTWriter() { |
| 3393 | for (FileDeclIDsTy::iterator |
| 3394 | I = FileDeclIDs.begin(), E = FileDeclIDs.end(); I != E; ++I) |
| 3395 | delete I->second; |
| 3396 | } |
| 3397 | |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 3398 | void ASTWriter::WriteAST(Sema &SemaRef, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 3399 | const std::string &OutputFile, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3400 | Module *WritingModule, StringRef isysroot, |
| 3401 | bool hasErrors) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3402 | WritingAST = true; |
| 3403 | |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3404 | ASTHasCompilerErrors = hasErrors; |
| 3405 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3406 | // Emit the file header. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3407 | Stream.Emit((unsigned)'C', 8); |
| 3408 | Stream.Emit((unsigned)'P', 8); |
| 3409 | Stream.Emit((unsigned)'C', 8); |
| 3410 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3411 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 3412 | WriteBlockInfoBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3413 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3414 | Context = &SemaRef.Context; |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3415 | PP = &SemaRef.PP; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3416 | this->WritingModule = WritingModule; |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 3417 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3418 | Context = 0; |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3419 | PP = 0; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3420 | this->WritingModule = 0; |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3421 | |
| 3422 | WritingAST = false; |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3423 | } |
| 3424 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3425 | template<typename Vector> |
| 3426 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 3427 | ASTWriter::RecordData &Record) { |
| 3428 | for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end(); |
| 3429 | I != E; ++I) { |
| 3430 | Writer.AddDeclRef(*I, Record); |
| 3431 | } |
| 3432 | } |
| 3433 | |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 3434 | void ASTWriter::WriteASTCore(Sema &SemaRef, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3435 | StringRef isysroot, |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3436 | const std::string &OutputFile, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3437 | Module *WritingModule) { |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3438 | using namespace llvm; |
| 3439 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3440 | // Make sure that the AST reader knows to finalize itself. |
| 3441 | if (Chain) |
| 3442 | Chain->finalizeForWriting(); |
| 3443 | |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3444 | ASTContext &Context = SemaRef.Context; |
| 3445 | Preprocessor &PP = SemaRef.PP; |
| 3446 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3447 | // Set up predefined declaration IDs. |
| 3448 | DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 3449 | if (Context.ObjCIdDecl) |
| 3450 | DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID; |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 3451 | if (Context.ObjCSelDecl) |
| 3452 | DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 3453 | if (Context.ObjCClassDecl) |
| 3454 | DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 3455 | if (Context.ObjCProtocolClassDecl) |
| 3456 | DeclIDs[Context.ObjCProtocolClassDecl] = PREDEF_DECL_OBJC_PROTOCOL_ID; |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 3457 | if (Context.Int128Decl) |
| 3458 | DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; |
| 3459 | if (Context.UInt128Decl) |
| 3460 | DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 3461 | if (Context.ObjCInstanceTypeDecl) |
| 3462 | DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID; |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 3463 | if (Context.BuiltinVaListDecl) |
| 3464 | DeclIDs[Context.getBuiltinVaListDecl()] = PREDEF_DECL_BUILTIN_VA_LIST_ID; |
| 3465 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3466 | if (!Chain) { |
| 3467 | // Make sure that we emit IdentifierInfos (and any attached |
| 3468 | // declarations) for builtins. We don't need to do this when we're |
| 3469 | // emitting chained PCH files, because all of the builtins will be |
| 3470 | // in the original PCH file. |
| 3471 | // FIXME: Modules won't like this at all. |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3472 | IdentifierTable &Table = PP.getIdentifierTable(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3473 | SmallVector<const char *, 32> BuiltinNames; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3474 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3475 | Context.getLangOpts().NoBuiltin); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3476 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 3477 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 3478 | } |
| 3479 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3480 | // If there are any out-of-date identifiers, bring them up to date. |
| 3481 | if (ExternalPreprocessorSource *ExtSource = PP.getExternalSource()) { |
Douglas Gregor | 589dae7 | 2013-01-07 16:56:53 +0000 | [diff] [blame] | 3482 | // Find out-of-date identifiers. |
| 3483 | SmallVector<IdentifierInfo *, 4> OutOfDate; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3484 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 3485 | IDEnd = PP.getIdentifierTable().end(); |
Douglas Gregor | 589dae7 | 2013-01-07 16:56:53 +0000 | [diff] [blame] | 3486 | ID != IDEnd; ++ID) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3487 | if (ID->second->isOutOfDate()) |
Douglas Gregor | 589dae7 | 2013-01-07 16:56:53 +0000 | [diff] [blame] | 3488 | OutOfDate.push_back(ID->second); |
| 3489 | } |
| 3490 | |
| 3491 | // Update the out-of-date identifiers. |
| 3492 | for (unsigned I = 0, N = OutOfDate.size(); I != N; ++I) { |
| 3493 | ExtSource->updateOutOfDateIdentifier(*OutOfDate[I]); |
| 3494 | } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3497 | // 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] | 3498 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3499 | // headers. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3500 | RecordData TentativeDefinitions; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3501 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 3502 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3503 | // Build a record containing all of the file scoped decls in this file. |
| 3504 | RecordData UnusedFileScopedDecls; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3505 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 3506 | UnusedFileScopedDecls); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3507 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3508 | // Build a record containing all of the delegating constructors we still need |
| 3509 | // to resolve. |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3510 | RecordData DelegatingCtorDecls; |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 3511 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3512 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3513 | // Write the set of weak, undeclared identifiers. We always write the |
| 3514 | // entire table, since later PCH files in a PCH chain are only interested in |
| 3515 | // the results at the end of the chain. |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3516 | RecordData WeakUndeclaredIdentifiers; |
| 3517 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 3518 | for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3519 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 3520 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 3521 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 3522 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 3523 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 3524 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 3525 | } |
| 3526 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3527 | |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3528 | // Build a record containing all of the locally-scoped extern "C" |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3529 | // declarations in this header file. Generally, this record will be |
| 3530 | // empty. |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3531 | RecordData LocallyScopedExternCDecls; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3532 | // 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] | 3533 | // nondeterminstic! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3534 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3535 | TD = SemaRef.LocallyScopedExternCDecls.begin(), |
| 3536 | TDEnd = SemaRef.LocallyScopedExternCDecls.end(); |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3537 | TD != TDEnd; ++TD) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3538 | if (!TD->second->isFromASTFile()) |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3539 | AddDeclRef(TD->second, LocallyScopedExternCDecls); |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3540 | } |
| 3541 | |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3542 | // Build a record containing all of the ext_vector declarations. |
| 3543 | RecordData ExtVectorDecls; |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 3544 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3545 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3546 | // Build a record containing all of the VTable uses information. |
| 3547 | RecordData VTableUses; |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3548 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3549 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 3550 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 3551 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 3552 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 3553 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | // Build a record containing all of dynamic classes declarations. |
| 3557 | RecordData DynamicClasses; |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 3558 | AddLazyVectorDecls(*this, SemaRef.DynamicClasses, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3559 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3560 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3561 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3562 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3563 | I = SemaRef.PendingInstantiations.begin(), |
| 3564 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 3565 | AddDeclRef(I->first, PendingInstantiations); |
| 3566 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3567 | } |
| 3568 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 3569 | "There are local ones at end of translation unit!"); |
| 3570 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3571 | // Build a record containing some declaration references. |
| 3572 | RecordData SemaDeclRefs; |
| 3573 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 3574 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 3575 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 3576 | } |
| 3577 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3578 | RecordData CUDASpecialDeclRefs; |
| 3579 | if (Context.getcudaConfigureCallDecl()) { |
| 3580 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 3581 | } |
| 3582 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3583 | // Build a record containing all of the known namespaces. |
| 3584 | RecordData KnownNamespaces; |
| 3585 | for (llvm::DenseMap<NamespaceDecl*, bool>::iterator |
| 3586 | I = SemaRef.KnownNamespaces.begin(), |
| 3587 | IEnd = SemaRef.KnownNamespaces.end(); |
| 3588 | I != IEnd; ++I) { |
| 3589 | if (!I->second) |
| 3590 | AddDeclRef(I->first, KnownNamespaces); |
| 3591 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3592 | |
| 3593 | // Write the control block |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3594 | WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3595 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3596 | // Write the remaining AST contents. |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3597 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3598 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3599 | |
Argyrios Kyrtzidis | 5e24f2d | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 3600 | // This is so that older clang versions, before the introduction |
| 3601 | // of the control block, can read and reject the newer PCH format. |
| 3602 | Record.clear(); |
| 3603 | Record.push_back(VERSION_MAJOR); |
| 3604 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 3605 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3606 | // Create a lexical update block containing all of the declarations in the |
| 3607 | // translation unit that do not come from other AST files. |
| 3608 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
| 3609 | SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
| 3610 | for (DeclContext::decl_iterator I = TU->noload_decls_begin(), |
| 3611 | E = TU->noload_decls_end(); |
| 3612 | I != E; ++I) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3613 | if (!(*I)->isFromASTFile()) |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3614 | NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 3618 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 3619 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3620 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 3621 | Record.clear(); |
| 3622 | Record.push_back(TU_UPDATE_LEXICAL); |
| 3623 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 3624 | data(NewGlobalDecls)); |
| 3625 | |
| 3626 | // And a visible updates block for the translation unit. |
| 3627 | Abv = new llvm::BitCodeAbbrev(); |
| 3628 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 3629 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3630 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 3631 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3632 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 3633 | WriteDeclContextVisibleUpdate(TU); |
| 3634 | |
| 3635 | // If the translation unit has an anonymous namespace, and we don't already |
| 3636 | // have an update block for it, write it as an update block. |
| 3637 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 3638 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
| 3639 | if (Record.empty()) { |
| 3640 | Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3641 | Record.push_back(reinterpret_cast<uint64_t>(NS)); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3642 | } |
| 3643 | } |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3644 | |
| 3645 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 3646 | // an AST file, are registered for serialization. |
| 3647 | for (SmallVector<const Decl *, 16>::iterator |
| 3648 | I = UpdatingVisibleDecls.begin(), |
| 3649 | E = UpdatingVisibleDecls.end(); I != E; ++I) { |
| 3650 | GetDeclRef(*I); |
| 3651 | } |
| 3652 | |
Argyrios Kyrtzidis | 67bc4ba | 2011-11-14 04:52:24 +0000 | [diff] [blame] | 3653 | // Resolve any declaration pointers within the declaration updates block. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3654 | ResolveDeclUpdatesBlocks(); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3655 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3656 | // Form the record of special types. |
| 3657 | RecordData SpecialTypes; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3658 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3659 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 3660 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 3661 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 3662 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 3663 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3664 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 3665 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3666 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3667 | // Keep writing types and declarations until all types and |
| 3668 | // declarations have been written. |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3669 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3670 | WriteDeclsBlockAbbrevs(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3671 | for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), |
| 3672 | E = DeclsToRewrite.end(); |
| 3673 | I != E; ++I) |
| 3674 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3675 | while (!DeclTypesToEmit.empty()) { |
| 3676 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 3677 | DeclTypesToEmit.pop(); |
| 3678 | if (DOT.isType()) |
| 3679 | WriteType(DOT.getType()); |
| 3680 | else |
| 3681 | WriteDecl(Context, DOT.getDecl()); |
| 3682 | } |
| 3683 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3684 | |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3685 | DoneWritingDeclsAndTypes = true; |
| 3686 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3687 | WriteFileDeclIDsMap(); |
| 3688 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3689 | WriteComments(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3690 | |
| 3691 | if (Chain) { |
| 3692 | // Write the mapping information describing our module dependencies and how |
| 3693 | // each of those modules were mapped into our own offset/ID space, so that |
| 3694 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 3695 | // The map consists solely of a blob with the following format: |
| 3696 | // *(module-name-len:i16 module-name:len*i8 |
| 3697 | // source-location-offset:i32 |
| 3698 | // identifier-id:i32 |
| 3699 | // preprocessed-entity-id:i32 |
| 3700 | // macro-definition-id:i32 |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3701 | // submodule-id:i32 |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3702 | // selector-id:i32 |
| 3703 | // declaration-id:i32 |
| 3704 | // c++-base-specifiers-id:i32 |
| 3705 | // type-id:i32) |
| 3706 | // |
| 3707 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3708 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 3709 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3710 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3711 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3712 | { |
| 3713 | llvm::raw_svector_ostream Out(Buffer); |
| 3714 | for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3715 | MEnd = Chain->ModuleMgr.end(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3716 | M != MEnd; ++M) { |
| 3717 | StringRef FileName = (*M)->FileName; |
| 3718 | io::Emit16(Out, FileName.size()); |
| 3719 | Out.write(FileName.data(), FileName.size()); |
| 3720 | io::Emit32(Out, (*M)->SLocEntryBaseOffset); |
| 3721 | io::Emit32(Out, (*M)->BaseIdentifierID); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3722 | io::Emit32(Out, (*M)->BaseMacroID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3723 | io::Emit32(Out, (*M)->BasePreprocessedEntityID); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3724 | io::Emit32(Out, (*M)->BaseSubmoduleID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3725 | io::Emit32(Out, (*M)->BaseSelectorID); |
| 3726 | io::Emit32(Out, (*M)->BaseDeclID); |
| 3727 | io::Emit32(Out, (*M)->BaseTypeIndex); |
| 3728 | } |
| 3729 | } |
| 3730 | Record.clear(); |
| 3731 | Record.push_back(MODULE_OFFSET_MAP); |
| 3732 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 3733 | Buffer.data(), Buffer.size()); |
| 3734 | } |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3735 | WritePreprocessor(PP, WritingModule != 0); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3736 | WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3737 | WriteSelectors(SemaRef); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3738 | WriteReferencedSelectorsPool(SemaRef); |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3739 | WriteIdentifierTable(PP, SemaRef.IdResolver, WritingModule != 0); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3740 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 3741 | WriteOpenCLExtensions(SemaRef); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3742 | |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3743 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3744 | WritePragmaDiagnosticMappings(Context.getDiagnostics()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3745 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 3746 | WriteCXXBaseSpecifiersOffsets(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3747 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3748 | // If we're emitting a module, write out the submodule information. |
| 3749 | if (WritingModule) |
| 3750 | WriteSubmodules(WritingModule); |
| 3751 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3752 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 3753 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3754 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3755 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3756 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3757 | |
| 3758 | // Write the record containing tentative definitions. |
| 3759 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3760 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3761 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3762 | // Write the record containing unused file scoped decls. |
| 3763 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3764 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3765 | |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3766 | // Write the record containing weak undeclared identifiers. |
| 3767 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3768 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3769 | WeakUndeclaredIdentifiers); |
| 3770 | |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3771 | // Write the record containing locally-scoped extern "C" definitions. |
| 3772 | if (!LocallyScopedExternCDecls.empty()) |
| 3773 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERN_C_DECLS, |
| 3774 | LocallyScopedExternCDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3775 | |
| 3776 | // Write the record containing ext_vector type names. |
| 3777 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3778 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3780 | // Write the record containing VTable uses information. |
| 3781 | if (!VTableUses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3782 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3783 | |
| 3784 | // Write the record containing dynamic classes declarations. |
| 3785 | if (!DynamicClasses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3786 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3787 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3788 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3789 | if (!PendingInstantiations.empty()) |
| 3790 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3791 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3792 | // Write the record containing declaration references of Sema. |
| 3793 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3794 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3795 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3796 | // Write the record containing CUDA-specific declaration references. |
| 3797 | if (!CUDASpecialDeclRefs.empty()) |
| 3798 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3799 | |
| 3800 | // Write the delegating constructors. |
| 3801 | if (!DelegatingCtorDecls.empty()) |
| 3802 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3803 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3804 | // Write the known namespaces. |
| 3805 | if (!KnownNamespaces.empty()) |
| 3806 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
| 3807 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3808 | // Write the visible updates to DeclContexts. |
| 3809 | for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |
| 3810 | I = UpdatedDeclContexts.begin(), |
| 3811 | E = UpdatedDeclContexts.end(); |
| 3812 | I != E; ++I) |
| 3813 | WriteDeclContextVisibleUpdate(*I); |
| 3814 | |
Douglas Gregor | c5e0f9b | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 3815 | if (!WritingModule) { |
| 3816 | // Write the submodules that were imported, if any. |
| 3817 | RecordData ImportedModules; |
| 3818 | for (ASTContext::import_iterator I = Context.local_import_begin(), |
| 3819 | IEnd = Context.local_import_end(); |
| 3820 | I != IEnd; ++I) { |
| 3821 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
| 3822 | ImportedModules.push_back(SubmoduleIDs[I->getImportedModule()]); |
| 3823 | } |
| 3824 | if (!ImportedModules.empty()) { |
| 3825 | // Sort module IDs. |
| 3826 | llvm::array_pod_sort(ImportedModules.begin(), ImportedModules.end()); |
| 3827 | |
| 3828 | // Unique module IDs. |
| 3829 | ImportedModules.erase(std::unique(ImportedModules.begin(), |
| 3830 | ImportedModules.end()), |
| 3831 | ImportedModules.end()); |
| 3832 | |
| 3833 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 3834 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 3835 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3836 | |
| 3837 | WriteMacroUpdates(); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3838 | WriteDeclUpdatesBlocks(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3839 | WriteDeclReplacementsBlock(); |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3840 | WriteMergedDecls(); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3841 | WriteRedeclarations(); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3842 | WriteObjCCategories(); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3843 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3844 | // Some simple statistics |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3845 | Record.clear(); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3846 | Record.push_back(NumStatements); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 3847 | Record.push_back(NumMacros); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3848 | Record.push_back(NumLexicalDeclContexts); |
| 3849 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3850 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3851 | Stream.ExitBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3852 | } |
| 3853 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3854 | void ASTWriter::WriteMacroUpdates() { |
| 3855 | if (MacroUpdates.empty()) |
| 3856 | return; |
| 3857 | |
| 3858 | RecordData Record; |
| 3859 | for (MacroUpdatesMap::iterator I = MacroUpdates.begin(), |
| 3860 | E = MacroUpdates.end(); |
| 3861 | I != E; ++I) { |
| 3862 | addMacroRef(I->first, Record); |
| 3863 | AddSourceLocation(I->second.UndefLoc, Record); |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 3864 | Record.push_back(inferSubmoduleIDFromLocation(I->second.UndefLoc)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3865 | } |
| 3866 | Stream.EmitRecord(MACRO_UPDATES, Record); |
| 3867 | } |
| 3868 | |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3869 | /// \brief Go through the declaration update blocks and resolve declaration |
| 3870 | /// pointers into declaration IDs. |
| 3871 | void ASTWriter::ResolveDeclUpdatesBlocks() { |
| 3872 | for (DeclUpdateMap::iterator |
| 3873 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3874 | const Decl *D = I->first; |
| 3875 | UpdateRecord &URec = I->second; |
| 3876 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3877 | if (isRewritten(D)) |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3878 | continue; // The decl will be written completely |
| 3879 | |
| 3880 | unsigned Idx = 0, N = URec.size(); |
| 3881 | while (Idx < N) { |
| 3882 | switch ((DeclUpdateKind)URec[Idx++]) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3883 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 3884 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 3885 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
| 3886 | URec[Idx] = GetDeclRef(reinterpret_cast<Decl *>(URec[Idx])); |
| 3887 | ++Idx; |
| 3888 | break; |
| 3889 | |
| 3890 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
| 3891 | ++Idx; |
| 3892 | break; |
| 3893 | } |
| 3894 | } |
| 3895 | } |
| 3896 | } |
| 3897 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3898 | void ASTWriter::WriteDeclUpdatesBlocks() { |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3899 | if (DeclUpdates.empty()) |
| 3900 | return; |
| 3901 | |
| 3902 | RecordData OffsetsRecord; |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3903 | Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3904 | for (DeclUpdateMap::iterator |
| 3905 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3906 | const Decl *D = I->first; |
| 3907 | UpdateRecord &URec = I->second; |
| 3908 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3909 | if (isRewritten(D)) |
Argyrios Kyrtzidis | ba901b5 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 3910 | continue; // The decl will be written completely,no need to store updates. |
| 3911 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3912 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 3913 | Stream.EmitRecord(DECL_UPDATES, URec); |
| 3914 | |
| 3915 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 3916 | OffsetsRecord.push_back(Offset); |
| 3917 | } |
| 3918 | Stream.ExitBlock(); |
| 3919 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); |
| 3920 | } |
| 3921 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3922 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3923 | if (ReplacedDecls.empty()) |
| 3924 | return; |
| 3925 | |
| 3926 | RecordData Record; |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 3927 | for (SmallVector<ReplacedDeclInfo, 16>::iterator |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3928 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 3929 | Record.push_back(I->ID); |
| 3930 | Record.push_back(I->Offset); |
| 3931 | Record.push_back(I->Loc); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3932 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3933 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3934 | } |
| 3935 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3936 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3937 | Record.push_back(Loc.getRawEncoding()); |
| 3938 | } |
| 3939 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3940 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3941 | AddSourceLocation(Range.getBegin(), Record); |
| 3942 | AddSourceLocation(Range.getEnd(), Record); |
| 3943 | } |
| 3944 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3945 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3946 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3947 | const uint64_t *Words = Value.getRawData(); |
| 3948 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3949 | } |
| 3950 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3951 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3952 | Record.push_back(Value.isUnsigned()); |
| 3953 | AddAPInt(Value, Record); |
| 3954 | } |
| 3955 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3956 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 3957 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 3958 | } |
| 3959 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3960 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3961 | Record.push_back(getIdentifierRef(II)); |
| 3962 | } |
| 3963 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3964 | void ASTWriter::addMacroRef(MacroInfo *MI, RecordDataImpl &Record) { |
| 3965 | Record.push_back(getMacroRef(MI)); |
| 3966 | } |
| 3967 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3968 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3969 | if (II == 0) |
| 3970 | return 0; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3971 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3972 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3973 | if (ID == 0) |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3974 | ID = NextIdentID++; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3975 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3976 | } |
| 3977 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3978 | MacroID ASTWriter::getMacroRef(MacroInfo *MI) { |
| 3979 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 3980 | // have been redefined by the header (in which case they are not |
| 3981 | // isBuiltinMacro). |
| 3982 | if (MI == 0 || MI->isBuiltinMacro()) |
| 3983 | return 0; |
| 3984 | |
| 3985 | MacroID &ID = MacroIDs[MI]; |
| 3986 | if (ID == 0) |
| 3987 | ID = NextMacroID++; |
| 3988 | return ID; |
| 3989 | } |
| 3990 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3991 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3992 | Record.push_back(getSelectorRef(SelRef)); |
| 3993 | } |
| 3994 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3995 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3996 | if (Sel.getAsOpaquePtr() == 0) { |
| 3997 | return 0; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3998 | } |
| 3999 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4000 | SelectorID &SID = SelectorIDs[Sel]; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4001 | if (SID == 0 && Chain) { |
| 4002 | // This might trigger a ReadSelector callback, which will set the ID for |
| 4003 | // this selector. |
| 4004 | Chain->LoadSelector(Sel); |
| 4005 | } |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4006 | if (SID == 0) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4007 | SID = NextSelectorID++; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4008 | } |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4009 | return SID; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4010 | } |
| 4011 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4012 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4013 | AddDeclRef(Temp->getDestructor(), Record); |
| 4014 | } |
| 4015 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4016 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
| 4017 | CXXBaseSpecifier const *BasesEnd, |
| 4018 | RecordDataImpl &Record) { |
| 4019 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 4020 | CXXBaseSpecifiersToWrite.push_back( |
| 4021 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 4022 | Bases, BasesEnd)); |
| 4023 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 4024 | } |
| 4025 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4026 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4027 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4028 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4029 | switch (Kind) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4030 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4031 | AddStmt(Arg.getAsExpr()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4032 | break; |
| 4033 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4034 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4035 | break; |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4036 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4037 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4038 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4039 | break; |
| 4040 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4041 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4042 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4043 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4044 | break; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4045 | case TemplateArgument::Null: |
| 4046 | case TemplateArgument::Integral: |
| 4047 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4048 | case TemplateArgument::NullPtr: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4049 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4050 | // FIXME: Is this right? |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4051 | break; |
| 4052 | } |
| 4053 | } |
| 4054 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4055 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4056 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4057 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4058 | |
| 4059 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 4060 | bool InfoHasSameExpr |
| 4061 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 4062 | Record.push_back(InfoHasSameExpr); |
| 4063 | if (InfoHasSameExpr) |
| 4064 | return; // Avoid storing the same expr twice. |
| 4065 | } |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4066 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 4067 | Record); |
| 4068 | } |
| 4069 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4070 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 4071 | RecordDataImpl &Record) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4072 | if (TInfo == 0) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4073 | AddTypeRef(QualType(), Record); |
| 4074 | return; |
| 4075 | } |
| 4076 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4077 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 4078 | } |
| 4079 | |
| 4080 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 4081 | AddTypeRef(TL.getType(), Record); |
| 4082 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4083 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4084 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4085 | TLW.Visit(TL); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4086 | } |
| 4087 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4088 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 7fb3518 | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 4089 | Record.push_back(GetOrCreateTypeID(T)); |
| 4090 | } |
| 4091 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4092 | TypeID ASTWriter::GetOrCreateTypeID( QualType T) { |
| 4093 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4094 | std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); |
| 4095 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4096 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4097 | TypeID ASTWriter::getTypeID(QualType T) const { |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4098 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4099 | std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { |
| 4103 | if (T.isNull()) |
| 4104 | return TypeIdx(); |
| 4105 | assert(!T.getLocalFastQualifiers()); |
| 4106 | |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 4107 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4108 | if (Idx.getIndex() == 0) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4109 | if (DoneWritingDeclsAndTypes) { |
| 4110 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 4111 | return TypeIdx(); |
| 4112 | } |
| 4113 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 4114 | // 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] | 4115 | // into the queue of types to emit. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4116 | Idx = TypeIdx(NextTypeID++); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4117 | DeclTypesToEmit.push(T); |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 4118 | } |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 4119 | return Idx; |
| 4120 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4121 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4122 | TypeIdx ASTWriter::getTypeIdx(QualType T) const { |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 4123 | if (T.isNull()) |
| 4124 | return TypeIdx(); |
| 4125 | assert(!T.getLocalFastQualifiers()); |
| 4126 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4127 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 4128 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 4129 | return I->second; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4130 | } |
| 4131 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4132 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4133 | Record.push_back(GetDeclRef(D)); |
| 4134 | } |
| 4135 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4136 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4137 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
| 4138 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4139 | if (D == 0) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4140 | return 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4141 | } |
Douglas Gregor | 1c7946a | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4142 | |
| 4143 | // If D comes from an AST file, its declaration ID is already known and |
| 4144 | // fixed. |
| 4145 | if (D->isFromASTFile()) |
| 4146 | return D->getGlobalID(); |
| 4147 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4148 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4149 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | if (ID == 0) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4151 | if (DoneWritingDeclsAndTypes) { |
| 4152 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 4153 | return 0; |
| 4154 | } |
| 4155 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4156 | // We haven't seen this declaration before. Give it a new ID and |
| 4157 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4158 | ID = NextDeclID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4159 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4162 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4165 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4166 | if (D == 0) |
| 4167 | return 0; |
| 4168 | |
Douglas Gregor | 1c7946a | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4169 | // If D comes from an AST file, its declaration ID is already known and |
| 4170 | // fixed. |
| 4171 | if (D->isFromASTFile()) |
| 4172 | return D->getGlobalID(); |
| 4173 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4174 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 4175 | return DeclIDs[D]; |
| 4176 | } |
| 4177 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4178 | static inline bool compLocDecl(std::pair<unsigned, serialization::DeclID> L, |
| 4179 | std::pair<unsigned, serialization::DeclID> R) { |
| 4180 | return L.first < R.first; |
| 4181 | } |
| 4182 | |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4183 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4184 | assert(ID); |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4185 | assert(D); |
| 4186 | |
| 4187 | SourceLocation Loc = D->getLocation(); |
| 4188 | if (Loc.isInvalid()) |
| 4189 | return; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4190 | |
| 4191 | // We only keep track of the file-level declarations of each file. |
| 4192 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 4193 | return; |
Argyrios Kyrtzidis | 69015c2 | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 4194 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 4195 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | 8cceefa | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 4196 | if (isa<ParmVarDecl>(D)) |
| 4197 | return; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4198 | |
| 4199 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4200 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4201 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4202 | FileID FID; |
| 4203 | unsigned Offset; |
| 4204 | llvm::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4205 | if (FID.isInvalid()) |
| 4206 | return; |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4207 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4208 | |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4209 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4210 | if (!Info) |
| 4211 | Info = new DeclIDInFileInfo(); |
| 4212 | |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4213 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4214 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 4215 | |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4216 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4217 | Decls.push_back(LocDecl); |
| 4218 | return; |
| 4219 | } |
| 4220 | |
| 4221 | LocDeclIDsTy::iterator |
| 4222 | I = std::upper_bound(Decls.begin(), Decls.end(), LocDecl, compLocDecl); |
| 4223 | |
| 4224 | Decls.insert(I, LocDecl); |
| 4225 | } |
| 4226 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4227 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 4228 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4229 | Record.push_back(Name.getNameKind()); |
| 4230 | switch (Name.getNameKind()) { |
| 4231 | case DeclarationName::Identifier: |
| 4232 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 4233 | break; |
| 4234 | |
| 4235 | case DeclarationName::ObjCZeroArgSelector: |
| 4236 | case DeclarationName::ObjCOneArgSelector: |
| 4237 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4238 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4239 | break; |
| 4240 | |
| 4241 | case DeclarationName::CXXConstructorName: |
| 4242 | case DeclarationName::CXXDestructorName: |
| 4243 | case DeclarationName::CXXConversionFunctionName: |
| 4244 | AddTypeRef(Name.getCXXNameType(), Record); |
| 4245 | break; |
| 4246 | |
| 4247 | case DeclarationName::CXXOperatorName: |
| 4248 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 4249 | break; |
| 4250 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4251 | case DeclarationName::CXXLiteralOperatorName: |
| 4252 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 4253 | break; |
| 4254 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4255 | case DeclarationName::CXXUsingDirective: |
| 4256 | // No extra data to emit |
| 4257 | break; |
| 4258 | } |
| 4259 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4260 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4261 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4262 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4263 | switch (Name.getNameKind()) { |
| 4264 | case DeclarationName::CXXConstructorName: |
| 4265 | case DeclarationName::CXXDestructorName: |
| 4266 | case DeclarationName::CXXConversionFunctionName: |
| 4267 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 4268 | break; |
| 4269 | |
| 4270 | case DeclarationName::CXXOperatorName: |
| 4271 | AddSourceLocation( |
| 4272 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 4273 | Record); |
| 4274 | AddSourceLocation( |
| 4275 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 4276 | Record); |
| 4277 | break; |
| 4278 | |
| 4279 | case DeclarationName::CXXLiteralOperatorName: |
| 4280 | AddSourceLocation( |
| 4281 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 4282 | Record); |
| 4283 | break; |
| 4284 | |
| 4285 | case DeclarationName::Identifier: |
| 4286 | case DeclarationName::ObjCZeroArgSelector: |
| 4287 | case DeclarationName::ObjCOneArgSelector: |
| 4288 | case DeclarationName::ObjCMultiArgSelector: |
| 4289 | case DeclarationName::CXXUsingDirective: |
| 4290 | break; |
| 4291 | } |
| 4292 | } |
| 4293 | |
| 4294 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4295 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4296 | AddDeclarationName(NameInfo.getName(), Record); |
| 4297 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 4298 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 4299 | } |
| 4300 | |
| 4301 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4302 | RecordDataImpl &Record) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4303 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4304 | Record.push_back(Info.NumTemplParamLists); |
| 4305 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 4306 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 4307 | } |
| 4308 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4309 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4310 | RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4311 | // 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] | 4312 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4313 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4314 | |
| 4315 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 4316 | while (NNS) { |
| 4317 | NestedNames.push_back(NNS); |
| 4318 | NNS = NNS->getPrefix(); |
| 4319 | } |
| 4320 | |
| 4321 | Record.push_back(NestedNames.size()); |
| 4322 | while(!NestedNames.empty()) { |
| 4323 | NNS = NestedNames.pop_back_val(); |
| 4324 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 4325 | Record.push_back(Kind); |
| 4326 | switch (Kind) { |
| 4327 | case NestedNameSpecifier::Identifier: |
| 4328 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 4329 | break; |
| 4330 | |
| 4331 | case NestedNameSpecifier::Namespace: |
| 4332 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 4333 | break; |
| 4334 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4335 | case NestedNameSpecifier::NamespaceAlias: |
| 4336 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 4337 | break; |
| 4338 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4339 | case NestedNameSpecifier::TypeSpec: |
| 4340 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4341 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 4342 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4343 | break; |
| 4344 | |
| 4345 | case NestedNameSpecifier::Global: |
| 4346 | // Don't need to write an associated value. |
| 4347 | break; |
| 4348 | } |
| 4349 | } |
| 4350 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4351 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4352 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 4353 | RecordDataImpl &Record) { |
| 4354 | // 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] | 4355 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4356 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4357 | |
| 4358 | // Push each of the nested-name-specifiers's onto a stack for |
| 4359 | // serialization in reverse order. |
| 4360 | while (NNS) { |
| 4361 | NestedNames.push_back(NNS); |
| 4362 | NNS = NNS.getPrefix(); |
| 4363 | } |
| 4364 | |
| 4365 | Record.push_back(NestedNames.size()); |
| 4366 | while(!NestedNames.empty()) { |
| 4367 | NNS = NestedNames.pop_back_val(); |
| 4368 | NestedNameSpecifier::SpecifierKind Kind |
| 4369 | = NNS.getNestedNameSpecifier()->getKind(); |
| 4370 | Record.push_back(Kind); |
| 4371 | switch (Kind) { |
| 4372 | case NestedNameSpecifier::Identifier: |
| 4373 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 4374 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4375 | break; |
| 4376 | |
| 4377 | case NestedNameSpecifier::Namespace: |
| 4378 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 4379 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4380 | break; |
| 4381 | |
| 4382 | case NestedNameSpecifier::NamespaceAlias: |
| 4383 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 4384 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4385 | break; |
| 4386 | |
| 4387 | case NestedNameSpecifier::TypeSpec: |
| 4388 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4389 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4390 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 4391 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4392 | break; |
| 4393 | |
| 4394 | case NestedNameSpecifier::Global: |
| 4395 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4396 | break; |
| 4397 | } |
| 4398 | } |
| 4399 | } |
| 4400 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4401 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4402 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4403 | Record.push_back(Kind); |
| 4404 | switch (Kind) { |
| 4405 | case TemplateName::Template: |
| 4406 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 4407 | break; |
| 4408 | |
| 4409 | case TemplateName::OverloadedTemplate: { |
| 4410 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 4411 | Record.push_back(OvT->size()); |
| 4412 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 4413 | I != E; ++I) |
| 4414 | AddDeclRef(*I, Record); |
| 4415 | break; |
| 4416 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4417 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4418 | case TemplateName::QualifiedTemplate: { |
| 4419 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 4420 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 4421 | Record.push_back(QualT->hasTemplateKeyword()); |
| 4422 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 4423 | break; |
| 4424 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4425 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4426 | case TemplateName::DependentTemplate: { |
| 4427 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 4428 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 4429 | Record.push_back(DepT->isIdentifier()); |
| 4430 | if (DepT->isIdentifier()) |
| 4431 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 4432 | else |
| 4433 | Record.push_back(DepT->getOperator()); |
| 4434 | break; |
| 4435 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4436 | |
| 4437 | case TemplateName::SubstTemplateTemplateParm: { |
| 4438 | SubstTemplateTemplateParmStorage *subst |
| 4439 | = Name.getAsSubstTemplateTemplateParm(); |
| 4440 | AddDeclRef(subst->getParameter(), Record); |
| 4441 | AddTemplateName(subst->getReplacement(), Record); |
| 4442 | break; |
| 4443 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4444 | |
| 4445 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4446 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 4447 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 4448 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 4449 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 4450 | break; |
| 4451 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4455 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4456 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4457 | Record.push_back(Arg.getKind()); |
| 4458 | switch (Arg.getKind()) { |
| 4459 | case TemplateArgument::Null: |
| 4460 | break; |
| 4461 | case TemplateArgument::Type: |
| 4462 | AddTypeRef(Arg.getAsType(), Record); |
| 4463 | break; |
| 4464 | case TemplateArgument::Declaration: |
| 4465 | AddDeclRef(Arg.getAsDecl(), Record); |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4466 | Record.push_back(Arg.isDeclForReferenceParam()); |
| 4467 | break; |
| 4468 | case TemplateArgument::NullPtr: |
| 4469 | AddTypeRef(Arg.getNullPtrType(), Record); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4470 | break; |
| 4471 | case TemplateArgument::Integral: |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 4472 | AddAPSInt(Arg.getAsIntegral(), Record); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4473 | AddTypeRef(Arg.getIntegralType(), Record); |
| 4474 | break; |
| 4475 | case TemplateArgument::Template: |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4476 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 4477 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4478 | case TemplateArgument::TemplateExpansion: |
| 4479 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4480 | if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
| 4481 | Record.push_back(*NumExpansions + 1); |
| 4482 | else |
| 4483 | Record.push_back(0); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4484 | break; |
| 4485 | case TemplateArgument::Expression: |
| 4486 | AddStmt(Arg.getAsExpr()); |
| 4487 | break; |
| 4488 | case TemplateArgument::Pack: |
| 4489 | Record.push_back(Arg.pack_size()); |
| 4490 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 4491 | I != E; ++I) |
| 4492 | AddTemplateArgument(*I, Record); |
| 4493 | break; |
| 4494 | } |
| 4495 | } |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4496 | |
| 4497 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4498 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4499 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4500 | assert(TemplateParams && "No TemplateParams!"); |
| 4501 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 4502 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 4503 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 4504 | Record.push_back(TemplateParams->size()); |
| 4505 | for (TemplateParameterList::const_iterator |
| 4506 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 4507 | P != PEnd; ++P) |
| 4508 | AddDeclRef(*P, Record); |
| 4509 | } |
| 4510 | |
| 4511 | /// \brief Emit a template argument list. |
| 4512 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4513 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4514 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4515 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4516 | Record.push_back(TemplateArgs->size()); |
| 4517 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4518 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 4519 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4520 | |
| 4521 | |
| 4522 | void |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 4523 | ASTWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4524 | Record.push_back(Set.size()); |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 4525 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4526 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 4527 | AddDeclRef(I.getDecl(), Record); |
| 4528 | Record.push_back(I.getAccess()); |
| 4529 | } |
| 4530 | } |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4531 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4532 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4533 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4534 | Record.push_back(Base.isVirtual()); |
| 4535 | Record.push_back(Base.isBaseOfClass()); |
| 4536 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4537 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4538 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4539 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4540 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 4541 | : SourceLocation(), |
| 4542 | Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4543 | } |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4544 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4545 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 4546 | RecordData Record; |
| 4547 | for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { |
| 4548 | Record.clear(); |
| 4549 | |
| 4550 | // Record the offset of this base-specifier set. |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4551 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4552 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 4553 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 4554 | else { |
| 4555 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 4556 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 4557 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 4558 | } |
| 4559 | |
| 4560 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 4561 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 4562 | Record.push_back(BEnd - B); |
| 4563 | for (; B != BEnd; ++B) |
| 4564 | AddCXXBaseSpecifier(*B, Record); |
| 4565 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | acec34b | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 4566 | |
| 4567 | // Flush any expressions that were written as part of the base specifiers. |
| 4568 | FlushStmts(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | CXXBaseSpecifiersToWrite.clear(); |
| 4572 | } |
| 4573 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4574 | void ASTWriter::AddCXXCtorInitializers( |
| 4575 | const CXXCtorInitializer * const *CtorInitializers, |
| 4576 | unsigned NumCtorInitializers, |
| 4577 | RecordDataImpl &Record) { |
| 4578 | Record.push_back(NumCtorInitializers); |
| 4579 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 4580 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4581 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4582 | if (Init->isBaseInitializer()) { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4583 | Record.push_back(CTOR_INITIALIZER_BASE); |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4584 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4585 | Record.push_back(Init->isBaseVirtual()); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4586 | } else if (Init->isDelegatingInitializer()) { |
| 4587 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4588 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4589 | } else if (Init->isMemberInitializer()){ |
| 4590 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 4591 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4592 | } else { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4593 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 4594 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4595 | } |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4596 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4597 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 4598 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4599 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 4600 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 4601 | Record.push_back(Init->isWritten()); |
| 4602 | if (Init->isWritten()) { |
| 4603 | Record.push_back(Init->getSourceOrder()); |
| 4604 | } else { |
| 4605 | Record.push_back(Init->getNumArrayIndices()); |
| 4606 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 4607 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 4608 | } |
| 4609 | } |
| 4610 | } |
| 4611 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4612 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
| 4613 | assert(D->DefinitionData); |
| 4614 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4615 | Record.push_back(Data.IsLambda); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4616 | Record.push_back(Data.UserDeclaredConstructor); |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 4617 | Record.push_back(Data.UserDeclaredSpecialMembers); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4618 | Record.push_back(Data.Aggregate); |
| 4619 | Record.push_back(Data.PlainOldData); |
| 4620 | Record.push_back(Data.Empty); |
| 4621 | Record.push_back(Data.Polymorphic); |
| 4622 | Record.push_back(Data.Abstract); |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 4623 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 4624 | Record.push_back(Data.HasNoNonEmptyBases); |
| 4625 | Record.push_back(Data.HasPrivateFields); |
| 4626 | Record.push_back(Data.HasProtectedFields); |
| 4627 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 4628 | Record.push_back(Data.HasMutableFields); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4629 | Record.push_back(Data.HasOnlyCMembers); |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 4630 | Record.push_back(Data.HasInClassInitializer); |
Richard Smith | d5bc867 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 4631 | Record.push_back(Data.HasUninitializedReferenceMember); |
Richard Smith | bc2a35d | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 4632 | Record.push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 4633 | Record.push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 4634 | Record.push_back(Data.NeedOverloadResolutionForDestructor); |
| 4635 | Record.push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 4636 | Record.push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 4637 | Record.push_back(Data.DefaultedDestructorIsDeleted); |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 4638 | Record.push_back(Data.HasTrivialSpecialMembers); |
| 4639 | Record.push_back(Data.HasIrrelevantDestructor); |
Richard Smith | 6b8bc07 | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 4640 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4641 | Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4642 | Record.push_back(Data.HasConstexprDefaultConstructor); |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 4643 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4644 | Record.push_back(Data.ComputedVisibleConversions); |
Sean Hunt | cdee3fe | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 4645 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 4646 | Record.push_back(Data.DeclaredSpecialMembers); |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 4647 | Record.push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 4648 | Record.push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 4649 | Record.push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 4650 | Record.push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Sebastian Redl | 14c3633 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 4651 | Record.push_back(Data.FailedImplicitMoveConstructor); |
| 4652 | Record.push_back(Data.FailedImplicitMoveAssignment); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4653 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4654 | |
| 4655 | Record.push_back(Data.NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4656 | if (Data.NumBases > 0) |
| 4657 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 4658 | Record); |
| 4659 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4660 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 4661 | Record.push_back(Data.NumVBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4662 | if (Data.NumVBases > 0) |
| 4663 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 4664 | Record); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4665 | |
| 4666 | AddUnresolvedSet(Data.Conversions, Record); |
| 4667 | AddUnresolvedSet(Data.VisibleConversions, Record); |
| 4668 | // Data.Definition is the owning decl, no need to write it. |
| 4669 | AddDeclRef(Data.FirstFriend, Record); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4670 | |
| 4671 | // Add lambda-specific data. |
| 4672 | if (Data.IsLambda) { |
| 4673 | CXXRecordDecl::LambdaDefinitionData &Lambda = D->getLambdaData(); |
Douglas Gregor | f4b7de1 | 2012-02-21 19:11:17 +0000 | [diff] [blame] | 4674 | Record.push_back(Lambda.Dependent); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4675 | Record.push_back(Lambda.NumCaptures); |
| 4676 | Record.push_back(Lambda.NumExplicitCaptures); |
Douglas Gregor | 9e8c92a | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 4677 | Record.push_back(Lambda.ManglingNumber); |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 4678 | AddDeclRef(Lambda.ContextDecl, Record); |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 4679 | AddTypeSourceInfo(Lambda.MethodTyInfo, Record); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4680 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
| 4681 | LambdaExpr::Capture &Capture = Lambda.Captures[I]; |
| 4682 | AddSourceLocation(Capture.getLocation(), Record); |
| 4683 | Record.push_back(Capture.isImplicit()); |
| 4684 | Record.push_back(Capture.getCaptureKind()); // FIXME: stable! |
| 4685 | VarDecl *Var = Capture.capturesVariable()? Capture.getCapturedVar() : 0; |
| 4686 | AddDeclRef(Var, Record); |
| 4687 | AddSourceLocation(Capture.isPackExpansion()? Capture.getEllipsisLoc() |
| 4688 | : SourceLocation(), |
| 4689 | Record); |
| 4690 | } |
| 4691 | } |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4694 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4695 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4696 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4697 | assert(FirstDeclID == NextDeclID && |
| 4698 | FirstTypeID == NextTypeID && |
| 4699 | FirstIdentID == NextIdentID && |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4700 | FirstMacroID == NextMacroID && |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4701 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4702 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4703 | "Setting chain after writing has started."); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4704 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4705 | Chain = Reader; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4706 | |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4707 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 4708 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 4709 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4710 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4711 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4712 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4713 | NextDeclID = FirstDeclID; |
| 4714 | NextTypeID = FirstTypeID; |
| 4715 | NextIdentID = FirstIdentID; |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4716 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4717 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4718 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4721 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4722 | IdentifierIDs[II] = ID; |
| 4723 | } |
| 4724 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4725 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
| 4726 | MacroIDs[MI] = ID; |
| 4727 | } |
| 4728 | |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4729 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4730 | // Always take the highest-numbered type index. This copes with an interesting |
| 4731 | // 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] | 4732 | // 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] | 4733 | // keep the higher-numbered entry so that we can properly write it out to |
| 4734 | // the AST file. |
| 4735 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 4736 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 4737 | StoredIdx = Idx; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4740 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4741 | SelectorIDs[S] = ID; |
| 4742 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4743 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4744 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4745 | MacroDefinition *MD) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4746 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4747 | MacroDefinitions[MD] = ID; |
| 4748 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4749 | |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 4750 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 4751 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 4752 | SubmoduleIDs[Mod] = ID; |
| 4753 | } |
| 4754 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4755 | void ASTWriter::UndefinedMacro(MacroInfo *MI) { |
| 4756 | MacroUpdates[MI].UndefLoc = MI->getUndefLoc(); |
| 4757 | } |
| 4758 | |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4759 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4760 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4761 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4762 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 4763 | // We are interested when a PCH decl is modified. |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4764 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4765 | // A forward reference was mutated into a definition. Rewrite it. |
| 4766 | // FIXME: This happens during template instantiation, should we |
| 4767 | // have created a new definition decl instead ? |
Argyrios Kyrtzidis | d3d0755 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 4768 | RewriteDecl(RD); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4769 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4770 | } |
| 4771 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4772 | |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4773 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4774 | assert(!WritingAST && "Already writing the AST!"); |
| 4775 | |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4776 | // TU and namespaces are handled elsewhere. |
| 4777 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 4778 | return; |
| 4779 | |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4780 | if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile())) |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4781 | return; // Not a source decl added to a DeclContext from PCH. |
| 4782 | |
| 4783 | AddUpdatedDeclContext(DC); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4784 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4785 | } |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4786 | |
| 4787 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4788 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4789 | assert(D->isImplicit()); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4790 | if (!(!D->isFromASTFile() && RD->isFromASTFile())) |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4791 | return; // Not a source member added to a class from PCH. |
| 4792 | if (!isa<CXXMethodDecl>(D)) |
| 4793 | return; // We are interested in lazily declared implicit methods. |
| 4794 | |
| 4795 | // A decl coming from PCH was modified. |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4796 | assert(RD->isCompleteDefinition()); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4797 | UpdateRecord &Record = DeclUpdates[RD]; |
| 4798 | Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4799 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4800 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4801 | |
| 4802 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 4803 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4804 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4805 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4806 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4807 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4808 | return; // Not a source specialization added to a template from PCH. |
| 4809 | |
| 4810 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4811 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4812 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4813 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 4814 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4815 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 4816 | const FunctionDecl *D) { |
| 4817 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4818 | assert(!WritingAST && "Already writing the AST!"); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4819 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4820 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4821 | return; // Not a source specialization added to a template from PCH. |
| 4822 | |
| 4823 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4824 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4825 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4826 | } |
| 4827 | |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4828 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4829 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4830 | if (!D->isFromASTFile()) |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4831 | return; // Declaration not imported from PCH. |
| 4832 | |
| 4833 | // Implicit decl from a PCH was defined. |
| 4834 | // FIXME: Should implicit definition be a separate FunctionDecl? |
| 4835 | RewriteDecl(D); |
| 4836 | } |
| 4837 | |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4838 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4839 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4840 | if (!D->isFromASTFile()) |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4841 | return; |
| 4842 | |
| 4843 | // Since the actual instantiation is delayed, this really means that we need |
| 4844 | // to update the instantiation location. |
| 4845 | UpdateRecord &Record = DeclUpdates[D]; |
| 4846 | Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); |
| 4847 | AddSourceLocation( |
| 4848 | D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); |
| 4849 | } |
| 4850 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4851 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 4852 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4853 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4854 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4855 | return; // Declaration not imported from PCH. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4856 | |
| 4857 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 4858 | ObjCClassesWithCategories.insert( |
| 4859 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4860 | } |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 4861 | |
Argyrios Kyrtzidis | 1a43415 | 2011-11-12 21:07:52 +0000 | [diff] [blame] | 4862 | |
Argyrios Kyrtzidis | c80553e | 2011-11-14 04:52:29 +0000 | [diff] [blame] | 4863 | void ASTWriter::AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, |
| 4864 | const ObjCPropertyDecl *OrigProp, |
| 4865 | const ObjCCategoryDecl *ClassExt) { |
| 4866 | const ObjCInterfaceDecl *D = ClassExt->getClassInterface(); |
| 4867 | if (!D) |
| 4868 | return; |
| 4869 | |
| 4870 | assert(!WritingAST && "Already writing the AST!"); |
| 4871 | if (!D->isFromASTFile()) |
| 4872 | return; // Declaration not imported from PCH. |
| 4873 | |
| 4874 | RewriteDecl(D); |
| 4875 | } |