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" |
Argyrios Kyrtzidis | ed3802e | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 45 | #include "llvm/ADT/Hashing.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 47 | #include "llvm/Bitcode/BitstreamWriter.h" |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 48 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 49 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 50 | #include "llvm/Support/Path.h" |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 51 | #include <algorithm> |
Chris Lattner | 3c304bd | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 52 | #include <cstdio> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 53 | #include <string.h> |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 54 | #include <utility> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 56 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 57 | |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 58 | template <typename T, typename Allocator> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 59 | static StringRef data(const std::vector<T, Allocator> &v) { |
| 60 | if (v.empty()) return StringRef(); |
| 61 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 62 | sizeof(T) * v.size()); |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 63 | } |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 64 | |
| 65 | template <typename T> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 66 | static StringRef data(const SmallVectorImpl<T> &v) { |
| 67 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 68 | sizeof(T) * v.size()); |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 71 | //===----------------------------------------------------------------------===// |
| 72 | // Type serialization |
| 73 | //===----------------------------------------------------------------------===// |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 74 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 75 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 76 | class ASTTypeWriter { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 77 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 78 | ASTWriter::RecordDataImpl &Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 79 | |
| 80 | public: |
| 81 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 82 | TypeCode Code; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 83 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 84 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 85 | : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 86 | |
| 87 | void VisitArrayType(const ArrayType *T); |
| 88 | void VisitFunctionType(const FunctionType *T); |
| 89 | void VisitTagType(const TagType *T); |
| 90 | |
| 91 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 92 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 93 | #include "clang/AST/TypeNodes.def" |
| 94 | }; |
| 95 | } |
| 96 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 97 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 98 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 101 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 102 | Writer.AddTypeRef(T->getElementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 103 | Code = TYPE_COMPLEX; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 106 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 107 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 108 | Code = TYPE_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 111 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 113 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 116 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 117 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
| 118 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 119 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 122 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 123 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 124 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 127 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 129 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 130 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 133 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 134 | Writer.AddTypeRef(T->getElementType(), Record); |
| 135 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 136 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 139 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 140 | VisitArrayType(T); |
| 141 | Writer.AddAPInt(T->getSize(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 142 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 145 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 146 | VisitArrayType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 147 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 150 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 151 | VisitArrayType(T); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 152 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 153 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 154 | Writer.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 155 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 158 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 159 | Writer.AddTypeRef(T->getElementType(), Record); |
| 160 | Record.push_back(T->getNumElements()); |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 161 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 162 | Code = TYPE_VECTOR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 165 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 166 | VisitVectorType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 167 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 170 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 171 | Writer.AddTypeRef(T->getResultType(), Record); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 172 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 173 | Record.push_back(C.getNoReturn()); |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 174 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 175 | Record.push_back(C.getRegParm()); |
Douglas Gregor | ab8bbf4 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 176 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 177 | Record.push_back(C.getCC()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 178 | Record.push_back(C.getProducesResult()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 181 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 182 | VisitFunctionType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 183 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 186 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 187 | VisitFunctionType(T); |
| 188 | Record.push_back(T->getNumArgs()); |
| 189 | for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) |
| 190 | Writer.AddTypeRef(T->getArgType(I), Record); |
| 191 | Record.push_back(T->isVariadic()); |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 192 | Record.push_back(T->hasTrailingReturn()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 193 | Record.push_back(T->getTypeQuals()); |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 194 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 195 | Record.push_back(T->getExceptionSpecType()); |
| 196 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 197 | Record.push_back(T->getNumExceptions()); |
| 198 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 199 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 200 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 201 | Writer.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 202 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
| 203 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
| 204 | Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); |
Richard Smith | b9d0b76 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 205 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
| 206 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 207 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 208 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 211 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 212 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 213 | Code = TYPE_UNRESOLVED_USING; |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 214 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 215 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 216 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 217 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 218 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 219 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 220 | Code = TYPE_TYPEDEF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 223 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 224 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 225 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 228 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 229 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 230 | Code = TYPE_TYPEOF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 233 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 234 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 235 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 236 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 239 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 240 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 241 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 242 | Record.push_back(T->getUTTKind()); |
| 243 | Code = TYPE_UNARY_TRANSFORM; |
| 244 | } |
| 245 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 246 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 247 | Writer.AddTypeRef(T->getDeducedType(), Record); |
| 248 | Code = TYPE_AUTO; |
| 249 | } |
| 250 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 251 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 252 | Record.push_back(T->isDependentType()); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 253 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 254 | assert(!T->isBeingDefined() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 255 | "Cannot serialize in the middle of a type definition"); |
| 256 | } |
| 257 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 258 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 259 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 260 | Code = TYPE_RECORD; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 263 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 264 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 265 | Code = TYPE_ENUM; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 266 | } |
| 267 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 268 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 269 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 270 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 271 | Record.push_back(T->getAttrKind()); |
| 272 | Code = TYPE_ATTRIBUTED; |
| 273 | } |
| 274 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 275 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 276 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 277 | const SubstTemplateTypeParmType *T) { |
| 278 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 279 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 280 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 284 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 285 | const SubstTemplateTypeParmPackType *T) { |
| 286 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 287 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 288 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 289 | } |
| 290 | |
| 291 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 292 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 293 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 294 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 295 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 296 | Record.push_back(T->getNumArgs()); |
| 297 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 298 | ArgI != ArgE; ++ArgI) |
| 299 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 300 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 301 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 302 | : T->getCanonicalTypeInternal(), |
| 303 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 304 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 308 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 309 | VisitArrayType(T); |
| 310 | Writer.AddStmt(T->getSizeExpr()); |
| 311 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 312 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 316 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 317 | const DependentSizedExtVectorType *T) { |
| 318 | // FIXME: Serialize this type (C++ only) |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 319 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 323 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 324 | Record.push_back(T->getDepth()); |
| 325 | Record.push_back(T->getIndex()); |
| 326 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 327 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 328 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 332 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 333 | Record.push_back(T->getKeyword()); |
| 334 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 335 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 336 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 337 | : T->getCanonicalTypeInternal(), |
| 338 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 339 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 343 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 344 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 345 | Record.push_back(T->getKeyword()); |
| 346 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 347 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 348 | Record.push_back(T->getNumArgs()); |
| 349 | for (DependentTemplateSpecializationType::iterator |
| 350 | I = T->begin(), E = T->end(); I != E; ++I) |
| 351 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 352 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 355 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 356 | Writer.AddTypeRef(T->getPattern(), Record); |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 357 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 358 | Record.push_back(*NumExpansions + 1); |
| 359 | else |
| 360 | Record.push_back(0); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 361 | Code = TYPE_PACK_EXPANSION; |
| 362 | } |
| 363 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 364 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 365 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 366 | Code = TYPE_PAREN; |
| 367 | } |
| 368 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 369 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 370 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 371 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 372 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 373 | Code = TYPE_ELABORATED; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 376 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Douglas Gregor | a8e0b97 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 377 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 378 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 379 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 382 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 383 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 384 | Code = TYPE_OBJC_INTERFACE; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 387 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 388 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 389 | Record.push_back(T->getNumProtocols()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 390 | for (ObjCObjectType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 446ee4e | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 391 | E = T->qual_end(); I != E; ++I) |
| 392 | Writer.AddDeclRef(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 393 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 396 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 397 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 399 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 402 | void |
| 403 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
| 404 | Writer.AddTypeRef(T->getValueType(), Record); |
| 405 | Code = TYPE_ATOMIC; |
| 406 | } |
| 407 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 408 | namespace { |
| 409 | |
| 410 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 411 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 412 | ASTWriter::RecordDataImpl &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 413 | |
| 414 | public: |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 415 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 416 | : Writer(Writer), Record(Record) { } |
| 417 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 418 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 419 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 420 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 421 | #include "clang/AST/TypeLocNodes.def" |
| 422 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 423 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 424 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 425 | }; |
| 426 | |
| 427 | } |
| 428 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 429 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 430 | // nothing to do |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 431 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 432 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 433 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 434 | if (TL.needsExtraLocalData()) { |
| 435 | Record.push_back(TL.getWrittenTypeSpec()); |
| 436 | Record.push_back(TL.getWrittenSignSpec()); |
| 437 | Record.push_back(TL.getWrittenWidthSpec()); |
| 438 | Record.push_back(TL.hasModeAttr()); |
| 439 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 440 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 441 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 442 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 443 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 444 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 445 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 446 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 447 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 448 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 449 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 450 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 451 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 452 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 453 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 454 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 455 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 456 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 457 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 458 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 459 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 460 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 461 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 462 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 463 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 464 | if (TL.getSizeExpr()) |
| 465 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 466 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 467 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 468 | VisitArrayTypeLoc(TL); |
| 469 | } |
| 470 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 471 | VisitArrayTypeLoc(TL); |
| 472 | } |
| 473 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 474 | VisitArrayTypeLoc(TL); |
| 475 | } |
| 476 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 477 | DependentSizedArrayTypeLoc TL) { |
| 478 | VisitArrayTypeLoc(TL); |
| 479 | } |
| 480 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 481 | DependentSizedExtVectorTypeLoc TL) { |
| 482 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 483 | } |
| 484 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 485 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 486 | } |
| 487 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 488 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 489 | } |
| 490 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 491 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 492 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 493 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 494 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 495 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 496 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 497 | } |
| 498 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 499 | VisitFunctionTypeLoc(TL); |
| 500 | } |
| 501 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 502 | VisitFunctionTypeLoc(TL); |
| 503 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 504 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 505 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 506 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 507 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 508 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 509 | } |
| 510 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 511 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 512 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 513 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 514 | } |
| 515 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 516 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 517 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 518 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 519 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 520 | } |
| 521 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 522 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 523 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 524 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 525 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 526 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 527 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 528 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 529 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 530 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 531 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 532 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 533 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 534 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 535 | } |
| 536 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 537 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 538 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 539 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 540 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 541 | if (TL.hasAttrOperand()) { |
| 542 | SourceRange range = TL.getAttrOperandParensRange(); |
| 543 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 544 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 545 | } |
| 546 | if (TL.hasAttrExprOperand()) { |
| 547 | Expr *operand = TL.getAttrExprOperand(); |
| 548 | Record.push_back(operand ? 1 : 0); |
| 549 | if (operand) Writer.AddStmt(operand); |
| 550 | } else if (TL.hasAttrEnumOperand()) { |
| 551 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 552 | } |
| 553 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 554 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 555 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 556 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 557 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 558 | SubstTemplateTypeParmTypeLoc TL) { |
| 559 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 560 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 561 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 562 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 563 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 564 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 565 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 566 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 567 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 568 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 569 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 570 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 571 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 572 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 573 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 574 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 575 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 576 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 577 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 578 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 579 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 580 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 581 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 582 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 583 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 584 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 585 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 586 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 587 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 588 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 589 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 590 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 591 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 592 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 593 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 594 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 595 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 596 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 597 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 598 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 599 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 600 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 601 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 602 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 603 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 604 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 605 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 606 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 607 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 608 | } |
| 609 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 610 | Record.push_back(TL.hasBaseTypeAsWritten()); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 611 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 612 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 613 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 614 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 615 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 616 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 617 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 618 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 619 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 620 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 621 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 622 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 623 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 624 | |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 625 | //===----------------------------------------------------------------------===// |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 626 | // ASTWriter Implementation |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 627 | //===----------------------------------------------------------------------===// |
| 628 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 629 | static void EmitBlockID(unsigned ID, const char *Name, |
| 630 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 631 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 632 | Record.clear(); |
| 633 | Record.push_back(ID); |
| 634 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 635 | |
| 636 | // Emit the block name if present. |
| 637 | if (Name == 0 || Name[0] == 0) return; |
| 638 | Record.clear(); |
| 639 | while (*Name) |
| 640 | Record.push_back(*Name++); |
| 641 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 642 | } |
| 643 | |
| 644 | static void EmitRecordID(unsigned ID, const char *Name, |
| 645 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 646 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 647 | Record.clear(); |
| 648 | Record.push_back(ID); |
| 649 | while (*Name) |
| 650 | Record.push_back(*Name++); |
| 651 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 655 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 656 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 657 | RECORD(STMT_STOP); |
| 658 | RECORD(STMT_NULL_PTR); |
| 659 | RECORD(STMT_NULL); |
| 660 | RECORD(STMT_COMPOUND); |
| 661 | RECORD(STMT_CASE); |
| 662 | RECORD(STMT_DEFAULT); |
| 663 | RECORD(STMT_LABEL); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 664 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 665 | RECORD(STMT_IF); |
| 666 | RECORD(STMT_SWITCH); |
| 667 | RECORD(STMT_WHILE); |
| 668 | RECORD(STMT_DO); |
| 669 | RECORD(STMT_FOR); |
| 670 | RECORD(STMT_GOTO); |
| 671 | RECORD(STMT_INDIRECT_GOTO); |
| 672 | RECORD(STMT_CONTINUE); |
| 673 | RECORD(STMT_BREAK); |
| 674 | RECORD(STMT_RETURN); |
| 675 | RECORD(STMT_DECL); |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 676 | RECORD(STMT_GCCASM); |
Chad Rosier | cd518a0 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 677 | RECORD(STMT_MSASM); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 678 | RECORD(EXPR_PREDEFINED); |
| 679 | RECORD(EXPR_DECL_REF); |
| 680 | RECORD(EXPR_INTEGER_LITERAL); |
| 681 | RECORD(EXPR_FLOATING_LITERAL); |
| 682 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 683 | RECORD(EXPR_STRING_LITERAL); |
| 684 | RECORD(EXPR_CHARACTER_LITERAL); |
| 685 | RECORD(EXPR_PAREN); |
| 686 | RECORD(EXPR_UNARY_OPERATOR); |
| 687 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 688 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 689 | RECORD(EXPR_CALL); |
| 690 | RECORD(EXPR_MEMBER); |
| 691 | RECORD(EXPR_BINARY_OPERATOR); |
| 692 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 693 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 694 | RECORD(EXPR_IMPLICIT_CAST); |
| 695 | RECORD(EXPR_CSTYLE_CAST); |
| 696 | RECORD(EXPR_COMPOUND_LITERAL); |
| 697 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 698 | RECORD(EXPR_INIT_LIST); |
| 699 | RECORD(EXPR_DESIGNATED_INIT); |
| 700 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 701 | RECORD(EXPR_VA_ARG); |
| 702 | RECORD(EXPR_ADDR_LABEL); |
| 703 | RECORD(EXPR_STMT); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 704 | RECORD(EXPR_CHOOSE); |
| 705 | RECORD(EXPR_GNU_NULL); |
| 706 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 707 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 708 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 709 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 710 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 711 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 712 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 713 | RECORD(EXPR_OBJC_ENCODE); |
| 714 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 715 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 716 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 717 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 718 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 719 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 720 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 721 | RECORD(STMT_OBJC_CATCH); |
| 722 | RECORD(STMT_OBJC_FINALLY); |
| 723 | RECORD(STMT_OBJC_AT_TRY); |
| 724 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 725 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 726 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 727 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 728 | RECORD(EXPR_CXX_CONSTRUCT); |
| 729 | RECORD(EXPR_CXX_STATIC_CAST); |
| 730 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 731 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 732 | RECORD(EXPR_CXX_CONST_CAST); |
| 733 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 734 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 735 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 736 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 737 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 738 | RECORD(EXPR_CXX_TYPEID_TYPE); |
| 739 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 740 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 741 | RECORD(EXPR_CXX_THIS); |
| 742 | RECORD(EXPR_CXX_THROW); |
| 743 | RECORD(EXPR_CXX_DEFAULT_ARG); |
| 744 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 745 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 746 | RECORD(EXPR_CXX_NEW); |
| 747 | RECORD(EXPR_CXX_DELETE); |
| 748 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 749 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 750 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 751 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 752 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 753 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 754 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
| 755 | RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); |
| 756 | RECORD(EXPR_CXX_NOEXCEPT); |
| 757 | RECORD(EXPR_OPAQUE_VALUE); |
| 758 | RECORD(EXPR_BINARY_TYPE_TRAIT); |
| 759 | RECORD(EXPR_PACK_EXPANSION); |
| 760 | RECORD(EXPR_SIZEOF_PACK); |
| 761 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 762 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 763 | #undef RECORD |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 764 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 765 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 766 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 767 | RecordData Record; |
| 768 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 770 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 771 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 772 | |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 773 | // Control Block. |
| 774 | BLOCK(CONTROL_BLOCK); |
| 775 | RECORD(METADATA); |
| 776 | RECORD(IMPORTS); |
| 777 | RECORD(LANGUAGE_OPTIONS); |
| 778 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 779 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 780 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 992d917 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 781 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 782 | RECORD(INPUT_FILE_OFFSETS); |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 783 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 784 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 785 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 786 | RECORD(PREPROCESSOR_OPTIONS); |
| 787 | |
Douglas Gregor | c337fef | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 788 | BLOCK(INPUT_FILES_BLOCK); |
| 789 | RECORD(INPUT_FILE); |
| 790 | |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 791 | // AST Top-Level Block. |
| 792 | BLOCK(AST_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 793 | RECORD(TYPE_OFFSET); |
| 794 | RECORD(DECL_OFFSET); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 795 | RECORD(IDENTIFIER_OFFSET); |
| 796 | RECORD(IDENTIFIER_TABLE); |
| 797 | RECORD(EXTERNAL_DEFINITIONS); |
| 798 | RECORD(SPECIAL_TYPES); |
| 799 | RECORD(STATISTICS); |
| 800 | RECORD(TENTATIVE_DEFINITIONS); |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 801 | RECORD(UNUSED_FILESCOPED_DECLS); |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 802 | RECORD(LOCALLY_SCOPED_EXTERN_C_DECLS); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 803 | RECORD(SELECTOR_OFFSETS); |
| 804 | RECORD(METHOD_POOL); |
| 805 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 806 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 807 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 808 | RECORD(EXT_VECTOR_DECLS); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 809 | RECORD(PPD_ENTITIES_OFFSETS); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 810 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 811 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 812 | RECORD(LOCAL_REDECLARATIONS_MAP); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 813 | RECORD(SEMA_DECL_REFS); |
| 814 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 815 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 816 | RECORD(DECL_REPLACEMENTS); |
| 817 | RECORD(UPDATE_VISIBLE); |
| 818 | RECORD(DECL_UPDATE_OFFSETS); |
| 819 | RECORD(DECL_UPDATES); |
| 820 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 821 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 822 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 823 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 824 | RECORD(FP_PRAGMA_OPTIONS); |
| 825 | RECORD(OPENCL_EXTENSIONS); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 826 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 827 | RECORD(KNOWN_NAMESPACES); |
Nick Lewycky | cd0655b | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 828 | RECORD(UNDEFINED_BUT_USED); |
Douglas Gregor | 837593f | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 829 | RECORD(MODULE_OFFSET_MAP); |
| 830 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 831 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | a126651 | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 832 | RECORD(FILE_SORTED_DECLS); |
| 833 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 834 | RECORD(MERGED_DECLARATIONS); |
| 835 | RECORD(LOCAL_REDECLARATIONS); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 836 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 837 | RECORD(MACRO_OFFSET); |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 838 | RECORD(MACRO_TABLE); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 839 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 840 | // SourceManager Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 841 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 842 | RECORD(SM_SLOC_FILE_ENTRY); |
| 843 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 844 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 845 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 847 | // Preprocessor Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 848 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 849 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 850 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 851 | RECORD(PP_TOKEN); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 852 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 853 | // Decls and Types block. |
| 854 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 855 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 856 | RECORD(TYPE_COMPLEX); |
| 857 | RECORD(TYPE_POINTER); |
| 858 | RECORD(TYPE_BLOCK_POINTER); |
| 859 | RECORD(TYPE_LVALUE_REFERENCE); |
| 860 | RECORD(TYPE_RVALUE_REFERENCE); |
| 861 | RECORD(TYPE_MEMBER_POINTER); |
| 862 | RECORD(TYPE_CONSTANT_ARRAY); |
| 863 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 864 | RECORD(TYPE_VARIABLE_ARRAY); |
| 865 | RECORD(TYPE_VECTOR); |
| 866 | RECORD(TYPE_EXT_VECTOR); |
| 867 | RECORD(TYPE_FUNCTION_PROTO); |
| 868 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 869 | RECORD(TYPE_TYPEDEF); |
| 870 | RECORD(TYPE_TYPEOF_EXPR); |
| 871 | RECORD(TYPE_TYPEOF); |
| 872 | RECORD(TYPE_RECORD); |
| 873 | RECORD(TYPE_ENUM); |
| 874 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | a53d2cb | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 875 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 876 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 877 | RECORD(TYPE_DECLTYPE); |
| 878 | RECORD(TYPE_ELABORATED); |
| 879 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 880 | RECORD(TYPE_UNRESOLVED_USING); |
| 881 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 882 | RECORD(TYPE_OBJC_OBJECT); |
| 883 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 884 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 885 | RECORD(TYPE_DEPENDENT_NAME); |
| 886 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 887 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 888 | RECORD(TYPE_PAREN); |
| 889 | RECORD(TYPE_PACK_EXPANSION); |
| 890 | RECORD(TYPE_ATTRIBUTED); |
| 891 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 892 | RECORD(TYPE_ATOMIC); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 893 | RECORD(DECL_TYPEDEF); |
| 894 | RECORD(DECL_ENUM); |
| 895 | RECORD(DECL_RECORD); |
| 896 | RECORD(DECL_ENUM_CONSTANT); |
| 897 | RECORD(DECL_FUNCTION); |
| 898 | RECORD(DECL_OBJC_METHOD); |
| 899 | RECORD(DECL_OBJC_INTERFACE); |
| 900 | RECORD(DECL_OBJC_PROTOCOL); |
| 901 | RECORD(DECL_OBJC_IVAR); |
| 902 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 903 | RECORD(DECL_OBJC_CATEGORY); |
| 904 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 905 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 906 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 907 | RECORD(DECL_OBJC_PROPERTY); |
| 908 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 909 | RECORD(DECL_FIELD); |
| 910 | RECORD(DECL_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 911 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 912 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 913 | RECORD(DECL_FILE_SCOPE_ASM); |
| 914 | RECORD(DECL_BLOCK); |
| 915 | RECORD(DECL_CONTEXT_LEXICAL); |
| 916 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 917 | RECORD(DECL_NAMESPACE); |
| 918 | RECORD(DECL_NAMESPACE_ALIAS); |
| 919 | RECORD(DECL_USING); |
| 920 | RECORD(DECL_USING_SHADOW); |
| 921 | RECORD(DECL_USING_DIRECTIVE); |
| 922 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 923 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 924 | RECORD(DECL_LINKAGE_SPEC); |
| 925 | RECORD(DECL_CXX_RECORD); |
| 926 | RECORD(DECL_CXX_METHOD); |
| 927 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 928 | RECORD(DECL_CXX_DESTRUCTOR); |
| 929 | RECORD(DECL_CXX_CONVERSION); |
| 930 | RECORD(DECL_ACCESS_SPEC); |
| 931 | RECORD(DECL_FRIEND); |
| 932 | RECORD(DECL_FRIEND_TEMPLATE); |
| 933 | RECORD(DECL_CLASS_TEMPLATE); |
| 934 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 935 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
| 936 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 937 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 938 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 939 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 940 | RECORD(DECL_STATIC_ASSERT); |
| 941 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 942 | RECORD(DECL_INDIRECTFIELD); |
| 943 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 944 | |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 945 | // Statements and Exprs can occur in the Decls and Types block. |
| 946 | AddStmtsExprs(Stream, Record); |
| 947 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 948 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 949 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 950 | RECORD(PPD_MACRO_DEFINITION); |
| 951 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 952 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 953 | #undef RECORD |
| 954 | #undef BLOCK |
| 955 | Stream.ExitBlock(); |
| 956 | } |
| 957 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 958 | /// \brief Adjusts the given filename to only write out the portion of the |
| 959 | /// filename that is not part of the system root directory. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | /// |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 961 | /// \param Filename the file name to adjust. |
| 962 | /// |
| 963 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 964 | /// the returned filename will be adjusted by this system root. |
| 965 | /// |
| 966 | /// \returns either the original filename (if it needs no adjustment) or the |
| 967 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 968 | static const char * |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 969 | adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 970 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 972 | if (isysroot.empty()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 973 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 974 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 975 | // Verify that the filename and the system root have the same prefix. |
| 976 | unsigned Pos = 0; |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 977 | for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 978 | if (Filename[Pos] != isysroot[Pos]) |
| 979 | return Filename; // Prefixes don't match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 981 | // We hit the end of the filename before we hit the end of the system root. |
| 982 | if (!Filename[Pos]) |
| 983 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 984 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 985 | // If the file name has a '/' at the current position, skip over the '/'. |
| 986 | // We distinguish sysroot-based includes from absolute includes by the |
| 987 | // absence of '/' at the beginning of sysroot-based includes. |
| 988 | if (Filename[Pos] == '/') |
| 989 | ++Pos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 991 | return Filename + Pos; |
| 992 | } |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 993 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 994 | /// \brief Write the control block. |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 995 | void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, |
| 996 | StringRef isysroot, |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 997 | const std::string &OutputFile) { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 998 | using namespace llvm; |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 999 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
| 1000 | RecordData Record; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1001 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1002 | // Metadata |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1003 | BitCodeAbbrev *MetadataAbbrev = new BitCodeAbbrev(); |
| 1004 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1005 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1006 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1007 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1008 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1009 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
| 1010 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1011 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1012 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
| 1013 | Record.push_back(METADATA); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1014 | Record.push_back(VERSION_MAJOR); |
| 1015 | Record.push_back(VERSION_MINOR); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1016 | Record.push_back(CLANG_VERSION_MAJOR); |
| 1017 | Record.push_back(CLANG_VERSION_MINOR); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1018 | Record.push_back(!isysroot.empty()); |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 1019 | Record.push_back(ASTHasCompilerErrors); |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1020 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1021 | getClangFullRepositoryVersion()); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1022 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1023 | // Imports |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1024 | if (Chain) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1025 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1026 | SmallVector<char, 128> ModulePaths; |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1027 | Record.clear(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1028 | |
| 1029 | for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end(); |
| 1030 | M != MEnd; ++M) { |
| 1031 | // Skip modules that weren't directly imported. |
| 1032 | if (!(*M)->isDirectlyImported()) |
| 1033 | continue; |
| 1034 | |
| 1035 | Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding |
Argyrios Kyrtzidis | 958bcaf | 2012-11-15 18:57:22 +0000 | [diff] [blame] | 1036 | AddSourceLocation((*M)->ImportLoc, Record); |
Douglas Gregor | 677e15f | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 1037 | Record.push_back((*M)->File->getSize()); |
| 1038 | Record.push_back((*M)->File->getModificationTime()); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1039 | // FIXME: This writes the absolute path for AST files we depend on. |
| 1040 | const std::string &FileName = (*M)->FileName; |
| 1041 | Record.push_back(FileName.size()); |
| 1042 | Record.append(FileName.begin(), FileName.end()); |
| 1043 | } |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1044 | Stream.EmitRecord(IMPORTS, Record); |
| 1045 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1047 | // Language options. |
| 1048 | Record.clear(); |
| 1049 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1050 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1051 | Record.push_back(LangOpts.Name); |
| 1052 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1053 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
| 1054 | #include "clang/Basic/LangOptions.def" |
Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1055 | #define SANITIZER(NAME, ID) Record.push_back(LangOpts.Sanitize.ID); |
| 1056 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1057 | |
| 1058 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1059 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
| 1060 | |
| 1061 | Record.push_back(LangOpts.CurrentModule.size()); |
| 1062 | Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end()); |
Dmitri Gribenko | 6ebf091 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1063 | |
| 1064 | // Comment options. |
| 1065 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
| 1066 | for (CommentOptions::BlockCommandNamesTy::const_iterator |
| 1067 | I = LangOpts.CommentOpts.BlockCommandNames.begin(), |
| 1068 | IEnd = LangOpts.CommentOpts.BlockCommandNames.end(); |
| 1069 | I != IEnd; ++I) { |
| 1070 | AddString(*I, Record); |
| 1071 | } |
| 1072 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1073 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1074 | |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1075 | // Target options. |
| 1076 | Record.clear(); |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1077 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1078 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1079 | AddString(TargetOpts.Triple, Record); |
| 1080 | AddString(TargetOpts.CPU, Record); |
| 1081 | AddString(TargetOpts.ABI, Record); |
| 1082 | AddString(TargetOpts.CXXABI, Record); |
| 1083 | AddString(TargetOpts.LinkerVersion, Record); |
| 1084 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1085 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1086 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1087 | } |
| 1088 | Record.push_back(TargetOpts.Features.size()); |
| 1089 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1090 | AddString(TargetOpts.Features[I], Record); |
| 1091 | } |
| 1092 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1093 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1094 | // Diagnostic options. |
| 1095 | Record.clear(); |
| 1096 | const DiagnosticOptions &DiagOpts |
| 1097 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1098 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1099 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1100 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1101 | #include "clang/Basic/DiagnosticOptions.def" |
| 1102 | Record.push_back(DiagOpts.Warnings.size()); |
| 1103 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1104 | AddString(DiagOpts.Warnings[I], Record); |
| 1105 | // Note: we don't serialize the log or serialization file names, because they |
| 1106 | // are generally transient files and will almost always be overridden. |
| 1107 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1108 | |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1109 | // File system options. |
| 1110 | Record.clear(); |
| 1111 | const FileSystemOptions &FSOpts |
| 1112 | = Context.getSourceManager().getFileManager().getFileSystemOptions(); |
| 1113 | AddString(FSOpts.WorkingDir, Record); |
| 1114 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1115 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1116 | // Header search options. |
| 1117 | Record.clear(); |
| 1118 | const HeaderSearchOptions &HSOpts |
| 1119 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1120 | AddString(HSOpts.Sysroot, Record); |
| 1121 | |
| 1122 | // Include entries. |
| 1123 | Record.push_back(HSOpts.UserEntries.size()); |
| 1124 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1125 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1126 | AddString(Entry.Path, Record); |
| 1127 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1128 | Record.push_back(Entry.IsFramework); |
| 1129 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | // System header prefixes. |
| 1133 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1134 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1135 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1136 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1137 | } |
| 1138 | |
| 1139 | AddString(HSOpts.ResourceDir, Record); |
| 1140 | AddString(HSOpts.ModuleCachePath, Record); |
| 1141 | Record.push_back(HSOpts.DisableModuleHash); |
| 1142 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1143 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1144 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1145 | Record.push_back(HSOpts.UseLibcxx); |
| 1146 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1147 | |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1148 | // Preprocessor options. |
| 1149 | Record.clear(); |
| 1150 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1151 | |
| 1152 | // Macro definitions. |
| 1153 | Record.push_back(PPOpts.Macros.size()); |
| 1154 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1155 | AddString(PPOpts.Macros[I].first, Record); |
| 1156 | Record.push_back(PPOpts.Macros[I].second); |
| 1157 | } |
| 1158 | |
| 1159 | // Includes |
| 1160 | Record.push_back(PPOpts.Includes.size()); |
| 1161 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1162 | AddString(PPOpts.Includes[I], Record); |
| 1163 | |
| 1164 | // Macro includes |
| 1165 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1166 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1167 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1168 | |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1169 | Record.push_back(PPOpts.UsePredefines); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1170 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1171 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1172 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1173 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1174 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1175 | // Original file name and file ID |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1176 | SourceManager &SM = Context.getSourceManager(); |
| 1177 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 1178 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1179 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1180 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1181 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1182 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1183 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1184 | SmallString<128> MainFilePath(MainFile->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1185 | |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1186 | llvm::sys::fs::make_absolute(MainFilePath); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1187 | |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1188 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1189 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1190 | isysroot); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1191 | Record.clear(); |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1192 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1193 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1194 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1195 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1196 | |
Argyrios Kyrtzidis | 992d917 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1197 | Record.clear(); |
| 1198 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1199 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1200 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1201 | // Original PCH directory |
| 1202 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1203 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1204 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1205 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1206 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1207 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1208 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1209 | |
| 1210 | llvm::sys::fs::make_absolute(OutputPath); |
| 1211 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1212 | |
| 1213 | RecordData Record; |
| 1214 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1215 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1216 | } |
| 1217 | |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1218 | WriteInputFiles(Context.SourceMgr, |
| 1219 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
| 1220 | isysroot); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1221 | Stream.ExitBlock(); |
| 1222 | } |
| 1223 | |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1224 | namespace { |
| 1225 | /// \brief An input file. |
| 1226 | struct InputFileEntry { |
| 1227 | const FileEntry *File; |
| 1228 | bool IsSystemFile; |
| 1229 | bool BufferOverridden; |
| 1230 | }; |
| 1231 | } |
| 1232 | |
| 1233 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1234 | HeaderSearchOptions &HSOpts, |
| 1235 | StringRef isysroot) { |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1236 | using namespace llvm; |
| 1237 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
| 1238 | RecordData Record; |
| 1239 | |
| 1240 | // Create input-file abbreviation. |
| 1241 | BitCodeAbbrev *IFAbbrev = new BitCodeAbbrev(); |
| 1242 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1243 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1244 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1245 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1246 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1247 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1248 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1249 | |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1250 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1251 | // system one or not. System files go at the back, users files at the front. |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1252 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1253 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1254 | // Get this source location entry. |
| 1255 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | bacc2c5 | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1256 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1257 | |
| 1258 | // We only care about file entries that were not overridden. |
| 1259 | if (!SLoc->isFile()) |
| 1260 | continue; |
| 1261 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1262 | if (!Cache->OrigEntry) |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1263 | continue; |
| 1264 | |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1265 | InputFileEntry Entry; |
| 1266 | Entry.File = Cache->OrigEntry; |
| 1267 | Entry.IsSystemFile = Cache->IsSystemFile; |
| 1268 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1269 | if (Cache->IsSystemFile) |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1270 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1271 | else |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1272 | SortedFiles.push_front(Entry); |
| 1273 | } |
| 1274 | |
| 1275 | // If we have an isysroot for a Darwin SDK, include its SDKSettings.plist in |
| 1276 | // the set of (non-system) input files. This is simple heuristic for |
| 1277 | // detecting whether the system headers may have changed, because it is too |
| 1278 | // expensive to stat() all of the system headers. |
| 1279 | FileManager &FileMgr = SourceMgr.getFileManager(); |
Douglas Gregor | 2bf383d | 2013-03-20 16:59:53 +0000 | [diff] [blame] | 1280 | if (!HSOpts.Sysroot.empty() && !Chain) { |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1281 | llvm::SmallString<128> SDKSettingsFileName(HSOpts.Sysroot); |
| 1282 | llvm::sys::path::append(SDKSettingsFileName, "SDKSettings.plist"); |
| 1283 | if (const FileEntry *SDKSettingsFile = FileMgr.getFile(SDKSettingsFileName)) { |
| 1284 | InputFileEntry Entry = { SDKSettingsFile, false, false }; |
| 1285 | SortedFiles.push_front(Entry); |
| 1286 | } |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | unsigned UserFilesNum = 0; |
| 1290 | // Write out all of the input files. |
| 1291 | std::vector<uint32_t> InputFileOffsets; |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1292 | for (std::deque<InputFileEntry>::iterator |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1293 | I = SortedFiles.begin(), E = SortedFiles.end(); I != E; ++I) { |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1294 | const InputFileEntry &Entry = *I; |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1295 | |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1296 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | a89b618 | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1297 | if (InputFileID != 0) |
| 1298 | continue; // already recorded this file. |
| 1299 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1300 | // Record this entry's offset. |
| 1301 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | a89b618 | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1302 | |
| 1303 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1304 | |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1305 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1306 | ++UserFilesNum; |
| 1307 | |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1308 | Record.clear(); |
| 1309 | Record.push_back(INPUT_FILE); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1310 | Record.push_back(InputFileOffsets.size()); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1311 | |
| 1312 | // Emit size/modification time for this file. |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1313 | Record.push_back(Entry.File->getSize()); |
| 1314 | Record.push_back(Entry.File->getModificationTime()); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1315 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1316 | // Whether this file was overridden. |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1317 | Record.push_back(Entry.BufferOverridden); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1318 | |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1319 | // Turn the file name into an absolute path, if it isn't already. |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1320 | const char *Filename = Entry.File->getName(); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1321 | SmallString<128> FilePath(Filename); |
| 1322 | |
| 1323 | // Ask the file manager to fixup the relative path for us. This will |
| 1324 | // honor the working directory. |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1325 | FileMgr.FixupRelativePath(FilePath); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1326 | |
| 1327 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1328 | // call to FixupRelativePath should always return an absolute path. |
| 1329 | llvm::sys::fs::make_absolute(FilePath); |
| 1330 | Filename = FilePath.c_str(); |
| 1331 | |
| 1332 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1333 | |
| 1334 | Stream.EmitRecordWithBlob(IFAbbrevCode, Record, Filename); |
| 1335 | } |
Douglas Gregor | 4a18c3b | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1336 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1337 | Stream.ExitBlock(); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1338 | |
| 1339 | // Create input file offsets abbreviation. |
| 1340 | BitCodeAbbrev *OffsetsAbbrev = new BitCodeAbbrev(); |
| 1341 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1342 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1343 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1344 | // input files |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1345 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
| 1346 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); |
| 1347 | |
| 1348 | // Write input file offsets. |
| 1349 | Record.clear(); |
| 1350 | Record.push_back(INPUT_FILE_OFFSETS); |
| 1351 | Record.push_back(InputFileOffsets.size()); |
Argyrios Kyrtzidis | 398253a | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1352 | Record.push_back(UserFilesNum); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1353 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, data(InputFileOffsets)); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1356 | //===----------------------------------------------------------------------===// |
| 1357 | // Source Manager Serialization |
| 1358 | //===----------------------------------------------------------------------===// |
| 1359 | |
| 1360 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1361 | /// file. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1362 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1363 | using namespace llvm; |
| 1364 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1365 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1366 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1367 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1368 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1369 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1370 | // FileEntry fields. |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1371 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1372 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1373 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1374 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
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. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1380 | static unsigned CreateSLocBufferAbbrev(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_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1384 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1385 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1386 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1387 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1388 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1389 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1393 | /// buffer's blob. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1394 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1395 | using namespace llvm; |
| 1396 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1397 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1398 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
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 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1402 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1403 | /// expansion. |
| 1404 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1405 | using namespace llvm; |
| 1406 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1407 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1408 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1409 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1410 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1411 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1412 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1413 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1416 | namespace { |
| 1417 | // Trait used for the on-disk hash table of header search information. |
| 1418 | class HeaderFileInfoTrait { |
| 1419 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 55ea75b | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1420 | const HeaderSearch &HS; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1421 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1422 | // Keep track of the framework names we've used during serialization. |
| 1423 | SmallVector<char, 128> FrameworkStringData; |
| 1424 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1425 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1426 | public: |
Argyrios Kyrtzidis | 55ea75b | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1427 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
| 1428 | : Writer(Writer), HS(HS) { } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1429 | |
Argyrios Kyrtzidis | ed3802e | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1430 | struct key_type { |
| 1431 | const FileEntry *FE; |
| 1432 | const char *Filename; |
| 1433 | }; |
| 1434 | typedef const key_type &key_type_ref; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1435 | |
| 1436 | typedef HeaderFileInfo data_type; |
| 1437 | typedef const data_type &data_type_ref; |
| 1438 | |
Argyrios Kyrtzidis | ed3802e | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1439 | static unsigned ComputeHash(key_type_ref key) { |
| 1440 | // The hash is based only on size/time of the file, so that the reader can |
| 1441 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1442 | // change the form of the name. However, complete path is still the key. |
| 1443 | return llvm::hash_combine(key.FE->getSize(), |
| 1444 | key.FE->getModificationTime()); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | ed3802e | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1448 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
| 1449 | unsigned KeyLen = strlen(key.Filename) + 1 + 8 + 8; |
| 1450 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1451 | unsigned DataLen = 1 + 2 + 4 + 4; |
Argyrios Kyrtzidis | 55ea75b | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1452 | if (Data.isModuleHeader) |
| 1453 | DataLen += 4; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1454 | clang::io::Emit8(Out, DataLen); |
Argyrios Kyrtzidis | ed3802e | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1455 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Argyrios Kyrtzidis | ed3802e | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1458 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
| 1459 | clang::io::Emit64(Out, key.FE->getSize()); |
| 1460 | KeyLen -= 8; |
| 1461 | clang::io::Emit64(Out, key.FE->getModificationTime()); |
| 1462 | KeyLen -= 8; |
| 1463 | Out.write(key.Filename, KeyLen); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
Argyrios Kyrtzidis | 55ea75b | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1466 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1467 | data_type_ref Data, unsigned DataLen) { |
| 1468 | using namespace clang::io; |
| 1469 | uint64_t Start = Out.tell(); (void)Start; |
| 1470 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1471 | unsigned char Flags = (Data.isImport << 5) |
| 1472 | | (Data.isPragmaOnce << 4) |
| 1473 | | (Data.DirInfo << 2) |
| 1474 | | (Data.Resolved << 1) |
| 1475 | | Data.IndexHeaderMapHeader; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1476 | Emit8(Out, (uint8_t)Flags); |
| 1477 | Emit16(Out, (uint16_t) Data.NumIncludes); |
| 1478 | |
| 1479 | if (!Data.ControllingMacro) |
| 1480 | Emit32(Out, (uint32_t)Data.ControllingMacroID); |
| 1481 | else |
| 1482 | Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1483 | |
| 1484 | unsigned Offset = 0; |
| 1485 | if (!Data.Framework.empty()) { |
| 1486 | // If this header refers into a framework, save the framework name. |
| 1487 | llvm::StringMap<unsigned>::iterator Pos |
| 1488 | = FrameworkNameOffset.find(Data.Framework); |
| 1489 | if (Pos == FrameworkNameOffset.end()) { |
| 1490 | Offset = FrameworkStringData.size() + 1; |
| 1491 | FrameworkStringData.append(Data.Framework.begin(), |
| 1492 | Data.Framework.end()); |
| 1493 | FrameworkStringData.push_back(0); |
| 1494 | |
| 1495 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1496 | } else |
| 1497 | Offset = Pos->second; |
| 1498 | } |
| 1499 | Emit32(Out, Offset); |
Argyrios Kyrtzidis | 55ea75b | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1500 | |
| 1501 | if (Data.isModuleHeader) { |
| 1502 | Module *Mod = HS.findModuleForHeader(key.FE); |
| 1503 | Emit32(Out, Writer.getExistingSubmoduleID(Mod)); |
| 1504 | } |
| 1505 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1506 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1507 | } |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1508 | |
| 1509 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1510 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1511 | }; |
| 1512 | } // end anonymous namespace |
| 1513 | |
| 1514 | /// \brief Write the header search block for the list of files that |
| 1515 | /// |
| 1516 | /// \param HS The header search structure to save. |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1517 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1518 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1519 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1520 | |
| 1521 | if (FilesByUID.size() > HS.header_file_size()) |
| 1522 | FilesByUID.resize(HS.header_file_size()); |
| 1523 | |
Argyrios Kyrtzidis | 55ea75b | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1524 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1525 | OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1526 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1527 | unsigned NumHeaderSearchEntries = 0; |
| 1528 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1529 | const FileEntry *File = FilesByUID[UID]; |
| 1530 | if (!File) |
| 1531 | continue; |
| 1532 | |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1533 | // Use HeaderSearch's getFileInfo to make sure we get the HeaderFileInfo |
| 1534 | // from the external source if it was not provided already. |
| 1535 | const HeaderFileInfo &HFI = HS.getFileInfo(File); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1536 | if (HFI.External && Chain) |
| 1537 | continue; |
| 1538 | |
| 1539 | // Turn the file name into an absolute path, if it isn't already. |
| 1540 | const char *Filename = File->getName(); |
| 1541 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1542 | |
| 1543 | // If we performed any translation on the file name at all, we need to |
| 1544 | // save this string, since the generator will refer to it later. |
| 1545 | if (Filename != File->getName()) { |
| 1546 | Filename = strdup(Filename); |
| 1547 | SavedStrings.push_back(Filename); |
| 1548 | } |
| 1549 | |
Argyrios Kyrtzidis | ed3802e | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1550 | HeaderFileInfoTrait::key_type key = { File, Filename }; |
| 1551 | Generator.insert(key, HFI, GeneratorTrait); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1552 | ++NumHeaderSearchEntries; |
| 1553 | } |
| 1554 | |
| 1555 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1556 | SmallString<4096> TableData; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1557 | uint32_t BucketOffset; |
| 1558 | { |
| 1559 | llvm::raw_svector_ostream Out(TableData); |
| 1560 | // Make sure that no bucket is at offset 0 |
| 1561 | clang::io::Emit32(Out, 0); |
| 1562 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1563 | } |
| 1564 | |
| 1565 | // Create a blob abbreviation |
| 1566 | using namespace llvm; |
| 1567 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1568 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1569 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1570 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1571 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1572 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1573 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1574 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1575 | // Write the header search table |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1576 | RecordData Record; |
| 1577 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1578 | Record.push_back(BucketOffset); |
| 1579 | Record.push_back(NumHeaderSearchEntries); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1580 | Record.push_back(TableData.size()); |
| 1581 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1582 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); |
| 1583 | |
| 1584 | // Free all of the strings we had to duplicate. |
| 1585 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | 6444483 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1586 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1589 | /// \brief Writes the block containing the serialized form of the |
| 1590 | /// source manager. |
| 1591 | /// |
| 1592 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1593 | /// blob), indexed based on the file name, so that we only create |
| 1594 | /// entries for files that we actually need. In the common case (no |
| 1595 | /// errors), we probably won't have to create file entries for any of |
| 1596 | /// the files in the AST. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1597 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1598 | const Preprocessor &PP, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1599 | StringRef isysroot) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1600 | RecordData Record; |
| 1601 | |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1602 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1603 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1604 | |
| 1605 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | 828e18c | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1606 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1607 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1608 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1609 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1610 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1611 | // Write out the source location entry table. We skip the first |
| 1612 | // entry, which is always the same dummy entry. |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1613 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1614 | RecordData PreloadSLocs; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1615 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1616 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1617 | I != N; ++I) { |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1618 | // Get this source location entry. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1619 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1620 | FileID FID = FileID::get(I); |
| 1621 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1622 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1623 | // Record the offset of this source-location entry. |
| 1624 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1625 | |
| 1626 | // Figure out which record code to use. |
| 1627 | unsigned Code; |
| 1628 | if (SLoc->isFile()) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1629 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1630 | if (Cache->OrigEntry) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1631 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1632 | } else |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1633 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1634 | } else |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1635 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1636 | Record.clear(); |
| 1637 | Record.push_back(Code); |
| 1638 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1639 | // Starting offset of this entry within this module, so skip the dummy. |
| 1640 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1641 | if (SLoc->isFile()) { |
| 1642 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1643 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1644 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1645 | Record.push_back(File.hasLineDirectives()); |
| 1646 | |
| 1647 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1648 | if (Content->OrigEntry) { |
| 1649 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1650 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1651 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1652 | // The source location entry is a file. Emit input file ID. |
| 1653 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 1654 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1655 | |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1656 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1657 | |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1658 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1659 | if (FDI != FileDeclIDs.end()) { |
| 1660 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1661 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1662 | } else { |
| 1663 | Record.push_back(0); |
| 1664 | Record.push_back(0); |
| 1665 | } |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1666 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1667 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1668 | |
| 1669 | if (Content->BufferOverridden) { |
| 1670 | Record.clear(); |
| 1671 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
| 1672 | const llvm::MemoryBuffer *Buffer |
| 1673 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1674 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
| 1675 | StringRef(Buffer->getBufferStart(), |
| 1676 | Buffer->getBufferSize() + 1)); |
| 1677 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1678 | } else { |
| 1679 | // The source location entry is a buffer. The blob associated |
| 1680 | // with this entry contains the contents of the buffer. |
| 1681 | |
| 1682 | // We add one to the size so that we capture the trailing NULL |
| 1683 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1684 | // the reader side). |
Douglas Gregor | 36c35ba | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1685 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1686 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1687 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1688 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1689 | StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1690 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1691 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1692 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1693 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1694 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1695 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1696 | if (strcmp(Name, "<built-in>") == 0) { |
| 1697 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1698 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1699 | } |
| 1700 | } else { |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1701 | // The source location entry is a macro expansion. |
Chandler Carruth | 1728762 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1702 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 78df836 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1703 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1704 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | d21683c | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1705 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1706 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1707 | |
| 1708 | // Compute the token length for this macro expansion. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1709 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1710 | if (I + 1 != N) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1711 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1712 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1713 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1714 | } |
| 1715 | } |
| 1716 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1717 | Stream.ExitBlock(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1718 | |
| 1719 | if (SLocEntryOffsets.empty()) |
| 1720 | return; |
| 1721 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1722 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1723 | // table is used for lazily loading source-location information. |
| 1724 | using namespace llvm; |
| 1725 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1726 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1727 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1728 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1729 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1730 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1731 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1732 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1733 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1734 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1735 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1736 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1737 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1738 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1739 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1740 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1741 | |
| 1742 | // Write the line table. It depends on remapping working, so it must come |
| 1743 | // after the source location offsets. |
| 1744 | if (SourceMgr.hasLineTable()) { |
| 1745 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1746 | |
| 1747 | Record.clear(); |
| 1748 | // Emit the file names |
| 1749 | Record.push_back(LineTable.getNumFilenames()); |
| 1750 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1751 | // Emit the file name |
| 1752 | const char *Filename = LineTable.getFilename(I); |
| 1753 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1754 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1755 | Record.push_back(FilenameLen); |
| 1756 | if (FilenameLen) |
| 1757 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1758 | } |
| 1759 | |
| 1760 | // Emit the line entries |
| 1761 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1762 | L != LEnd; ++L) { |
| 1763 | // Only emit entries for local files. |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1764 | if (L->first.ID < 0) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1765 | continue; |
| 1766 | |
| 1767 | // Emit the file ID |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1768 | Record.push_back(L->first.ID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1769 | |
| 1770 | // Emit the line entries |
| 1771 | Record.push_back(L->second.size()); |
| 1772 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1773 | LEEnd = L->second.end(); |
| 1774 | LE != LEEnd; ++LE) { |
| 1775 | Record.push_back(LE->FileOffset); |
| 1776 | Record.push_back(LE->LineNo); |
| 1777 | Record.push_back(LE->FilenameID); |
| 1778 | Record.push_back((unsigned)LE->FileKind); |
| 1779 | Record.push_back(LE->IncludeOffset); |
| 1780 | } |
| 1781 | } |
| 1782 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1783 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1786 | //===----------------------------------------------------------------------===// |
| 1787 | // Preprocessor Serialization |
| 1788 | //===----------------------------------------------------------------------===// |
| 1789 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1790 | namespace { |
| 1791 | class ASTMacroTableTrait { |
| 1792 | public: |
| 1793 | typedef IdentID key_type; |
| 1794 | typedef key_type key_type_ref; |
| 1795 | |
| 1796 | struct Data { |
| 1797 | uint32_t MacroDirectivesOffset; |
| 1798 | }; |
| 1799 | |
| 1800 | typedef Data data_type; |
| 1801 | typedef const data_type &data_type_ref; |
| 1802 | |
| 1803 | static unsigned ComputeHash(IdentID IdID) { |
| 1804 | return llvm::hash_value(IdID); |
| 1805 | } |
| 1806 | |
| 1807 | std::pair<unsigned,unsigned> |
| 1808 | static EmitKeyDataLength(raw_ostream& Out, |
| 1809 | key_type_ref Key, data_type_ref Data) { |
| 1810 | unsigned KeyLen = 4; // IdentID. |
| 1811 | unsigned DataLen = 4; // MacroDirectivesOffset. |
| 1812 | return std::make_pair(KeyLen, DataLen); |
| 1813 | } |
| 1814 | |
| 1815 | static void EmitKey(raw_ostream& Out, key_type_ref Key, unsigned KeyLen) { |
| 1816 | clang::io::Emit32(Out, Key); |
| 1817 | } |
| 1818 | |
| 1819 | static void EmitData(raw_ostream& Out, key_type_ref Key, data_type_ref Data, |
| 1820 | unsigned) { |
| 1821 | clang::io::Emit32(Out, Data.MacroDirectivesOffset); |
| 1822 | } |
| 1823 | }; |
| 1824 | } // end anonymous namespace |
| 1825 | |
| 1826 | static int compareMacroDirectives(const void *XPtr, const void *YPtr) { |
| 1827 | const std::pair<const IdentifierInfo *, MacroDirective *> &X = |
| 1828 | *(const std::pair<const IdentifierInfo *, MacroDirective *>*)XPtr; |
| 1829 | const std::pair<const IdentifierInfo *, MacroDirective *> &Y = |
| 1830 | *(const std::pair<const IdentifierInfo *, MacroDirective *>*)YPtr; |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1831 | return X.first->getName().compare(Y.first->getName()); |
| 1832 | } |
| 1833 | |
Argyrios Kyrtzidis | 9cc3ed4 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 1834 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 1835 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1836 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 1837 | if (MI->isBuiltinMacro()) |
| 1838 | return true; |
Argyrios Kyrtzidis | 9cc3ed4 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 1839 | |
| 1840 | if (IsModule) { |
| 1841 | SourceLocation Loc = MD->getLocation(); |
| 1842 | if (Loc.isInvalid()) |
| 1843 | return true; |
| 1844 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 1845 | return true; |
| 1846 | } |
| 1847 | |
| 1848 | return false; |
| 1849 | } |
| 1850 | |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1851 | /// \brief Writes the block containing the serialized form of the |
| 1852 | /// preprocessor. |
| 1853 | /// |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1854 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1855 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 1856 | if (PPRec) |
| 1857 | WritePreprocessorDetail(*PPRec); |
| 1858 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1859 | RecordData Record; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1860 | |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1861 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1862 | if (PP.getCounterValue() != 0) { |
| 1863 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1864 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1865 | Record.clear(); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | // Enter the preprocessor block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1869 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1870 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1871 | // 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] | 1872 | // FIXME: use diagnostics subsystem for localization etc. |
| 1873 | if (PP.SawDateOrTime()) |
| 1874 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1876 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1877 | // Loop over all the macro directives that are live at the end of the file, |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1878 | // emitting each to the PP section. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1879 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1880 | // Construct the list of macro directives that need to be serialized. |
Argyrios Kyrtzidis | 9818a1d | 2013-02-20 00:54:57 +0000 | [diff] [blame] | 1881 | SmallVector<std::pair<const IdentifierInfo *, MacroDirective *>, 2> |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1882 | MacroDirectives; |
| 1883 | for (Preprocessor::macro_iterator |
| 1884 | I = PP.macro_begin(/*IncludeExternalMacros=*/false), |
| 1885 | E = PP.macro_end(/*IncludeExternalMacros=*/false); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1886 | I != E; ++I) { |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1887 | MacroDirectives.push_back(std::make_pair(I->first, I->second)); |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1888 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1889 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1890 | // Sort the set of macro definitions that need to be serialized by the |
| 1891 | // name of the macro, to provide a stable ordering. |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1892 | llvm::array_pod_sort(MacroDirectives.begin(), MacroDirectives.end(), |
| 1893 | &compareMacroDirectives); |
| 1894 | |
| 1895 | OnDiskChainedHashTableGenerator<ASTMacroTableTrait> Generator; |
| 1896 | |
| 1897 | // Emit the macro directives as a list and associate the offset with the |
| 1898 | // identifier they belong to. |
| 1899 | for (unsigned I = 0, N = MacroDirectives.size(); I != N; ++I) { |
| 1900 | const IdentifierInfo *Name = MacroDirectives[I].first; |
| 1901 | uint64_t MacroDirectiveOffset = Stream.GetCurrentBitNo(); |
| 1902 | MacroDirective *MD = MacroDirectives[I].second; |
| 1903 | |
| 1904 | // If the macro or identifier need no updates, don't write the macro history |
| 1905 | // for this one. |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1906 | // FIXME: Chain the macro history instead of re-writing it. |
| 1907 | if (MD->isFromPCH() && |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1908 | Name->isFromAST() && !Name->hasChangedSinceDeserialization()) |
| 1909 | continue; |
| 1910 | |
| 1911 | // Emit the macro directives in reverse source order. |
| 1912 | for (; MD; MD = MD->getPrevious()) { |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1913 | if (MD->isHidden()) |
| 1914 | continue; |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1915 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
| 1916 | continue; |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1917 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1918 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1919 | Record.push_back(MD->getKind()); |
| 1920 | if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
| 1921 | MacroID InfoID = getMacroRef(DefMD->getInfo(), Name); |
| 1922 | Record.push_back(InfoID); |
| 1923 | Record.push_back(DefMD->isImported()); |
| 1924 | Record.push_back(DefMD->isAmbiguous()); |
| 1925 | |
| 1926 | } else if (VisibilityMacroDirective * |
| 1927 | VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
| 1928 | Record.push_back(VisMD->isPublic()); |
| 1929 | } |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1930 | } |
| 1931 | if (Record.empty()) |
| 1932 | continue; |
| 1933 | |
| 1934 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 1935 | Record.clear(); |
| 1936 | |
| 1937 | IdentMacroDirectivesOffsetMap[Name] = MacroDirectiveOffset; |
| 1938 | |
| 1939 | IdentID NameID = getIdentifierRef(Name); |
| 1940 | ASTMacroTableTrait::Data data; |
| 1941 | data.MacroDirectivesOffset = MacroDirectiveOffset; |
| 1942 | Generator.insert(NameID, data); |
| 1943 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1944 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1945 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 1946 | /// the local macro ID |
| 1947 | /// |
| 1948 | /// For each identifier that is associated with a macro, this map |
| 1949 | /// provides the offset into the bitstream where that macro is |
| 1950 | /// defined. |
| 1951 | std::vector<uint32_t> MacroOffsets; |
| 1952 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1953 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 1954 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 1955 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 1956 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | ee9b0ba | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 1957 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1958 | if (ID < FirstMacroID) { |
| 1959 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 1960 | continue; |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1961 | } |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1962 | |
| 1963 | // Record the local offset of this macro. |
| 1964 | unsigned Index = ID - FirstMacroID; |
| 1965 | if (Index == MacroOffsets.size()) |
| 1966 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1967 | else { |
| 1968 | if (Index > MacroOffsets.size()) |
| 1969 | MacroOffsets.resize(Index + 1); |
| 1970 | |
| 1971 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 1972 | } |
| 1973 | |
| 1974 | AddIdentifierRef(Name, Record); |
| 1975 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
| 1976 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 1977 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 1978 | Record.push_back(MI->isUsed()); |
| 1979 | unsigned Code; |
| 1980 | if (MI->isObjectLike()) { |
| 1981 | Code = PP_MACRO_OBJECT_LIKE; |
| 1982 | } else { |
| 1983 | Code = PP_MACRO_FUNCTION_LIKE; |
| 1984 | |
| 1985 | Record.push_back(MI->isC99Varargs()); |
| 1986 | Record.push_back(MI->isGNUVarargs()); |
| 1987 | Record.push_back(MI->hasCommaPasting()); |
| 1988 | Record.push_back(MI->getNumArgs()); |
| 1989 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1990 | I != E; ++I) |
| 1991 | AddIdentifierRef(*I, Record); |
| 1992 | } |
| 1993 | |
| 1994 | // If we have a detailed preprocessing record, record the macro definition |
| 1995 | // ID that corresponds to this macro. |
| 1996 | if (PPRec) |
| 1997 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 1998 | |
| 1999 | Stream.EmitRecord(Code, Record); |
| 2000 | Record.clear(); |
| 2001 | |
| 2002 | // Emit the tokens array. |
| 2003 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2004 | // Note that we know that the preprocessor does not have any annotation |
| 2005 | // tokens in it because they are created by the parser, and thus can't |
| 2006 | // be in a macro definition. |
| 2007 | const Token &Tok = MI->getReplacementToken(TokNo); |
| 2008 | |
| 2009 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 2010 | Record.push_back(Tok.getLength()); |
| 2011 | |
| 2012 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 2013 | // if it is needed. |
| 2014 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 2015 | // FIXME: Should translate token kind to a stable encoding. |
| 2016 | Record.push_back(Tok.getKind()); |
| 2017 | // FIXME: Should translate token flags to a stable encoding. |
| 2018 | Record.push_back(Tok.getFlags()); |
| 2019 | |
| 2020 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2021 | Record.clear(); |
| 2022 | } |
| 2023 | ++NumMacros; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2024 | } |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2025 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2026 | Stream.ExitBlock(); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2027 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2028 | // Create the on-disk hash table in a buffer. |
| 2029 | SmallString<4096> MacroTable; |
| 2030 | uint32_t BucketOffset; |
| 2031 | { |
| 2032 | llvm::raw_svector_ostream Out(MacroTable); |
| 2033 | // Make sure that no bucket is at offset 0 |
| 2034 | clang::io::Emit32(Out, 0); |
| 2035 | BucketOffset = Generator.Emit(Out); |
| 2036 | } |
| 2037 | |
| 2038 | // Write the macro table |
| 2039 | using namespace llvm; |
| 2040 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2041 | Abbrev->Add(BitCodeAbbrevOp(MACRO_TABLE)); |
| 2042 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 2043 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2044 | unsigned MacroTableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2045 | |
| 2046 | Record.push_back(MACRO_TABLE); |
| 2047 | Record.push_back(BucketOffset); |
| 2048 | Stream.EmitRecordWithBlob(MacroTableAbbrev, Record, MacroTable.str()); |
| 2049 | Record.clear(); |
| 2050 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2051 | // Write the offsets table for macro IDs. |
| 2052 | using namespace llvm; |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2053 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2054 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2055 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2056 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2057 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2058 | |
| 2059 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2060 | Record.clear(); |
| 2061 | Record.push_back(MACRO_OFFSET); |
| 2062 | Record.push_back(MacroOffsets.size()); |
| 2063 | Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS); |
| 2064 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, |
| 2065 | data(MacroOffsets)); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | b6441ef | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2069 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2070 | return; |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2071 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2072 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2073 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2074 | // Enter the preprocessor block. |
| 2075 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2076 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2077 | // If the preprocessor has a preprocessing record, emit it. |
| 2078 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2079 | using namespace llvm; |
| 2080 | |
| 2081 | // Set up the abbreviation for |
| 2082 | unsigned InclusionAbbrev = 0; |
| 2083 | { |
| 2084 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2085 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2086 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2087 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2088 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2089 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2090 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2091 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2092 | } |
| 2093 | |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2094 | unsigned FirstPreprocessorEntityID |
| 2095 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2096 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2097 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2098 | RecordData Record; |
Argyrios Kyrtzidis | b6441ef | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2099 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2100 | EEnd = PPRec.local_end(); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2101 | E != EEnd; |
| 2102 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2103 | Record.clear(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2104 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2105 | PreprocessedEntityOffsets.push_back(PPEntityOffset((*E)->getSourceRange(), |
| 2106 | Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2107 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2108 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2109 | // Record this macro definition's ID. |
| 2110 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2111 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2112 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2113 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2114 | continue; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2115 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2116 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 2117 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 8f7c540 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2118 | Record.push_back(ME->isBuiltinMacro()); |
| 2119 | if (ME->isBuiltinMacro()) |
| 2120 | AddIdentifierRef(ME->getName(), Record); |
| 2121 | else |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2122 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2123 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2124 | continue; |
| 2125 | } |
| 2126 | |
| 2127 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 2128 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2129 | Record.push_back(ID->getFileName().size()); |
| 2130 | Record.push_back(ID->wasInQuotes()); |
| 2131 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2132 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2133 | SmallString<64> Buffer; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2134 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2135 | // Check that the FileEntry is not null because it was not resolved and |
| 2136 | // we create a PCH even with compiler errors. |
| 2137 | if (ID->getFile()) |
| 2138 | Buffer += ID->getFile()->getName(); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2139 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 2140 | continue; |
| 2141 | } |
| 2142 | |
| 2143 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2144 | } |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2145 | Stream.ExitBlock(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2146 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2147 | // Write the offsets table for the preprocessing record. |
| 2148 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2149 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2150 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2151 | // Write the offsets table for identifier IDs. |
| 2152 | using namespace llvm; |
| 2153 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2154 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2155 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2156 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2157 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2158 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2159 | Record.clear(); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2160 | Record.push_back(PPD_ENTITIES_OFFSETS); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2161 | Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2162 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
| 2163 | data(PreprocessedEntityOffsets)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2164 | } |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2167 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2168 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2169 | if (Known != SubmoduleIDs.end()) |
| 2170 | return Known->second; |
| 2171 | |
| 2172 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2173 | } |
| 2174 | |
Argyrios Kyrtzidis | 55ea75b | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2175 | unsigned ASTWriter::getExistingSubmoduleID(Module *Mod) const { |
| 2176 | if (!Mod) |
| 2177 | return 0; |
| 2178 | |
| 2179 | llvm::DenseMap<Module *, unsigned>::const_iterator |
| 2180 | Known = SubmoduleIDs.find(Mod); |
| 2181 | if (Known != SubmoduleIDs.end()) |
| 2182 | return Known->second; |
| 2183 | |
| 2184 | return 0; |
| 2185 | } |
| 2186 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2187 | /// \brief Compute the number of modules within the given tree (including the |
| 2188 | /// given module). |
| 2189 | static unsigned getNumberOfModules(Module *Mod) { |
| 2190 | unsigned ChildModules = 0; |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2191 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2192 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2193 | Sub != SubEnd; ++Sub) |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2194 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2195 | |
| 2196 | return ChildModules + 1; |
| 2197 | } |
| 2198 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2199 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 4bc8738d | 2011-12-05 16:35:23 +0000 | [diff] [blame] | 2200 | // Determine the dependencies of our module and each of it's submodules. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2201 | // FIXME: This feels like it belongs somewhere else, but there are no |
| 2202 | // other consumers of this information. |
| 2203 | SourceManager &SrcMgr = PP->getSourceManager(); |
| 2204 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
| 2205 | for (ASTContext::import_iterator I = Context->local_import_begin(), |
| 2206 | IEnd = Context->local_import_end(); |
| 2207 | I != IEnd; ++I) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2208 | if (Module *ImportedFrom |
| 2209 | = ModMap.inferModuleFromLocation(FullSourceLoc(I->getLocation(), |
| 2210 | SrcMgr))) { |
| 2211 | ImportedFrom->Imports.push_back(I->getImportedModule()); |
| 2212 | } |
| 2213 | } |
| 2214 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2215 | // Enter the submodule description block. |
| 2216 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
| 2217 | |
| 2218 | // Write the abbreviations needed for the submodules block. |
| 2219 | using namespace llvm; |
| 2220 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2221 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2222 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2223 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2224 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2225 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2226 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2227 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2228 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2229 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 63a7268 | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2230 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2231 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2232 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2233 | |
| 2234 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2235 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2236 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2237 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2238 | |
| 2239 | Abbrev = new BitCodeAbbrev(); |
| 2240 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2241 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2242 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2243 | |
| 2244 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2245 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2246 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2247 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2248 | |
| 2249 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2250 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2251 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2252 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2253 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2254 | Abbrev = new BitCodeAbbrev(); |
| 2255 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
| 2256 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
| 2257 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2258 | |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2259 | Abbrev = new BitCodeAbbrev(); |
| 2260 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2261 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2262 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2263 | |
Douglas Gregor | b6cbe51 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2264 | Abbrev = new BitCodeAbbrev(); |
| 2265 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2266 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2267 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2268 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2269 | |
Douglas Gregor | 63a7268 | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2270 | Abbrev = new BitCodeAbbrev(); |
| 2271 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2272 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2273 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2274 | |
Douglas Gregor | 906d66a | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2275 | Abbrev = new BitCodeAbbrev(); |
| 2276 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2277 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2278 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
| 2279 | unsigned ConflictAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2280 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2281 | // Write the submodule metadata block. |
| 2282 | RecordData Record; |
| 2283 | Record.push_back(getNumberOfModules(WritingModule)); |
| 2284 | Record.push_back(FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS); |
| 2285 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2286 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2287 | // Write all of the submodules. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2288 | std::queue<Module *> Q; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2289 | Q.push(WritingModule); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2290 | while (!Q.empty()) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2291 | Module *Mod = Q.front(); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2292 | Q.pop(); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2293 | unsigned ID = getSubmoduleID(Mod); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2294 | |
| 2295 | // Emit the definition of the block. |
| 2296 | Record.clear(); |
| 2297 | Record.push_back(SUBMODULE_DEFINITION); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2298 | Record.push_back(ID); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2299 | if (Mod->Parent) { |
| 2300 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
| 2301 | Record.push_back(SubmoduleIDs[Mod->Parent]); |
| 2302 | } else { |
| 2303 | Record.push_back(0); |
| 2304 | } |
| 2305 | Record.push_back(Mod->IsFramework); |
| 2306 | Record.push_back(Mod->IsExplicit); |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2307 | Record.push_back(Mod->IsSystem); |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2308 | Record.push_back(Mod->InferSubmodules); |
| 2309 | Record.push_back(Mod->InferExplicitSubmodules); |
| 2310 | Record.push_back(Mod->InferExportWildcard); |
Douglas Gregor | 63a7268 | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2311 | Record.push_back(Mod->ConfigMacrosExhaustive); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2312 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2313 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2314 | // Emit the requirements. |
| 2315 | for (unsigned I = 0, N = Mod->Requires.size(); I != N; ++I) { |
| 2316 | Record.clear(); |
| 2317 | Record.push_back(SUBMODULE_REQUIRES); |
| 2318 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, |
| 2319 | Mod->Requires[I].data(), |
| 2320 | Mod->Requires[I].size()); |
| 2321 | } |
| 2322 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2323 | // Emit the umbrella header, if there is one. |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 2324 | if (const FileEntry *UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2325 | Record.clear(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2326 | Record.push_back(SUBMODULE_UMBRELLA_HEADER); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2327 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 2328 | UmbrellaHeader->getName()); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2329 | } else if (const DirectoryEntry *UmbrellaDir = Mod->getUmbrellaDir()) { |
| 2330 | Record.clear(); |
| 2331 | Record.push_back(SUBMODULE_UMBRELLA_DIR); |
| 2332 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
| 2333 | UmbrellaDir->getName()); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | // Emit the headers. |
| 2337 | for (unsigned I = 0, N = Mod->Headers.size(); I != N; ++I) { |
| 2338 | Record.clear(); |
| 2339 | Record.push_back(SUBMODULE_HEADER); |
| 2340 | Stream.EmitRecordWithBlob(HeaderAbbrev, Record, |
| 2341 | Mod->Headers[I]->getName()); |
| 2342 | } |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2343 | // Emit the excluded headers. |
| 2344 | for (unsigned I = 0, N = Mod->ExcludedHeaders.size(); I != N; ++I) { |
| 2345 | Record.clear(); |
| 2346 | Record.push_back(SUBMODULE_EXCLUDED_HEADER); |
| 2347 | Stream.EmitRecordWithBlob(ExcludedHeaderAbbrev, Record, |
| 2348 | Mod->ExcludedHeaders[I]->getName()); |
| 2349 | } |
Argyrios Kyrtzidis | c1d2239 | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 2350 | ArrayRef<const FileEntry *> |
| 2351 | TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
| 2352 | for (unsigned I = 0, N = TopHeaders.size(); I != N; ++I) { |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2353 | Record.clear(); |
| 2354 | Record.push_back(SUBMODULE_TOPHEADER); |
| 2355 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, |
Argyrios Kyrtzidis | c1d2239 | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 2356 | TopHeaders[I]->getName()); |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2357 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2358 | |
| 2359 | // Emit the imports. |
| 2360 | if (!Mod->Imports.empty()) { |
| 2361 | Record.clear(); |
| 2362 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
Douglas Gregor | bab9f4a | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2363 | unsigned ImportedID = getSubmoduleID(Mod->Imports[I]); |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2364 | assert(ImportedID && "Unknown submodule!"); |
| 2365 | Record.push_back(ImportedID); |
| 2366 | } |
| 2367 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2368 | } |
| 2369 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2370 | // Emit the exports. |
| 2371 | if (!Mod->Exports.empty()) { |
| 2372 | Record.clear(); |
| 2373 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
Douglas Gregor | bab9f4a | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2374 | if (Module *Exported = Mod->Exports[I].getPointer()) { |
| 2375 | unsigned ExportedID = SubmoduleIDs[Exported]; |
| 2376 | assert(ExportedID > 0 && "Unknown submodule ID?"); |
| 2377 | Record.push_back(ExportedID); |
| 2378 | } else { |
| 2379 | Record.push_back(0); |
| 2380 | } |
| 2381 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2382 | Record.push_back(Mod->Exports[I].getInt()); |
| 2383 | } |
| 2384 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2385 | } |
Douglas Gregor | b6cbe51 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2386 | |
| 2387 | // Emit the link libraries. |
| 2388 | for (unsigned I = 0, N = Mod->LinkLibraries.size(); I != N; ++I) { |
| 2389 | Record.clear(); |
| 2390 | Record.push_back(SUBMODULE_LINK_LIBRARY); |
| 2391 | Record.push_back(Mod->LinkLibraries[I].IsFramework); |
| 2392 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, |
| 2393 | Mod->LinkLibraries[I].Library); |
| 2394 | } |
| 2395 | |
Douglas Gregor | 906d66a | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2396 | // Emit the conflicts. |
| 2397 | for (unsigned I = 0, N = Mod->Conflicts.size(); I != N; ++I) { |
| 2398 | Record.clear(); |
| 2399 | Record.push_back(SUBMODULE_CONFLICT); |
| 2400 | unsigned OtherID = getSubmoduleID(Mod->Conflicts[I].Other); |
| 2401 | assert(OtherID && "Unknown submodule!"); |
| 2402 | Record.push_back(OtherID); |
| 2403 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, |
| 2404 | Mod->Conflicts[I].Message); |
| 2405 | } |
| 2406 | |
Douglas Gregor | 63a7268 | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2407 | // Emit the configuration macros. |
| 2408 | for (unsigned I = 0, N = Mod->ConfigMacros.size(); I != N; ++I) { |
| 2409 | Record.clear(); |
| 2410 | Record.push_back(SUBMODULE_CONFIG_MACRO); |
| 2411 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, |
| 2412 | Mod->ConfigMacros[I]); |
| 2413 | } |
| 2414 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2415 | // Queue up the submodules of this module. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2416 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2417 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2418 | Sub != SubEnd; ++Sub) |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2419 | Q.push(*Sub); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | Stream.ExitBlock(); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2423 | |
| 2424 | assert((NextSubmoduleID - FirstSubmoduleID |
| 2425 | == getNumberOfModules(WritingModule)) && "Wrong # of submodules"); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2428 | serialization::SubmoduleID |
| 2429 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2430 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2431 | return 0; // No submodule |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2432 | |
| 2433 | // Find the module that owns this location. |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2434 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2435 | Module *OwningMod |
| 2436 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2437 | if (!OwningMod) |
| 2438 | return 0; |
| 2439 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2440 | // Check whether this submodule is part of our own module. |
| 2441 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2442 | return 0; |
| 2443 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2444 | return getSubmoduleID(OwningMod); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
Argyrios Kyrtzidis | ea744ab | 2013-03-27 17:17:23 +0000 | [diff] [blame^] | 2447 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2448 | bool isModule) { |
| 2449 | // Make sure set diagnostic pragmas don't affect the translation unit that |
| 2450 | // imports the module. |
| 2451 | // FIXME: Make diagnostic pragma sections work properly with modules. |
| 2452 | if (isModule) |
| 2453 | return; |
| 2454 | |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2455 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2456 | DiagStateIDMap; |
| 2457 | unsigned CurrID = 0; |
| 2458 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2459 | RecordData Record; |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2460 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2461 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2462 | I != E; ++I) { |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2463 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2464 | if (point.Loc.isInvalid()) |
| 2465 | continue; |
| 2466 | |
| 2467 | Record.push_back(point.Loc.getRawEncoding()); |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2468 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2469 | Record.push_back(DiagStateID); |
| 2470 | |
| 2471 | if (DiagStateID == 0) { |
| 2472 | DiagStateID = ++CurrID; |
| 2473 | for (DiagnosticsEngine::DiagState::const_iterator |
| 2474 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
| 2475 | if (I->second.isPragma()) { |
| 2476 | Record.push_back(I->first); |
| 2477 | Record.push_back(I->second.getMapping()); |
| 2478 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2479 | } |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2480 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2481 | // location. |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2482 | } |
| 2483 | } |
| 2484 | |
Argyrios Kyrtzidis | 60f7684 | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2485 | if (!Record.empty()) |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2486 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2489 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2490 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2491 | return; |
| 2492 | |
| 2493 | RecordData Record; |
| 2494 | |
| 2495 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2496 | using namespace llvm; |
| 2497 | |
| 2498 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2499 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2500 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2501 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2502 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2503 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2504 | // Write the base specifier offsets table. |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2505 | Record.clear(); |
| 2506 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 2507 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 2508 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2509 | data(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2512 | //===----------------------------------------------------------------------===// |
| 2513 | // Type Serialization |
| 2514 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2515 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2516 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2517 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2518 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2519 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2520 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2521 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2522 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | 55f48de | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2523 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2524 | // Record the offset for this type. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2525 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2526 | if (TypeOffsets.size() == Index) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2527 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2528 | else if (TypeOffsets.size() < Index) { |
| 2529 | TypeOffsets.resize(Index + 1); |
| 2530 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | RecordData Record; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2535 | // Emit the type's representation. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2536 | ASTTypeWriter W(*this, Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2537 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2538 | if (T.hasLocalNonFastQualifiers()) { |
| 2539 | Qualifiers Qs = T.getLocalQualifiers(); |
| 2540 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2541 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2542 | W.Code = TYPE_EXT_QUAL; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2543 | } else { |
| 2544 | switch (T->getTypeClass()) { |
| 2545 | // For all of the concrete, non-dependent types, call the |
| 2546 | // appropriate visitor function. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2547 | #define TYPE(Class, Base) \ |
Mike Stump | b716633 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 2548 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2549 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2550 | #include "clang/AST/TypeNodes.def" |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2551 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | // Emit the serialized record. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2555 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2556 | |
| 2557 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2558 | FlushStmts(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2559 | } |
| 2560 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2561 | //===----------------------------------------------------------------------===// |
| 2562 | // Declaration Serialization |
| 2563 | //===----------------------------------------------------------------------===// |
| 2564 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2565 | /// \brief Write the block containing all of the declaration IDs |
| 2566 | /// lexically declared within the given DeclContext. |
| 2567 | /// |
| 2568 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2569 | /// bistream, or 0 if no block was written. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2570 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2571 | DeclContext *DC) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2572 | if (DC->decls_empty()) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2573 | return 0; |
| 2574 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2575 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2576 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2577 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2578 | SmallVector<KindDeclIDPair, 64> Decls; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2579 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 2580 | D != DEnd; ++D) |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2581 | Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2582 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2583 | ++NumLexicalDeclContexts; |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2584 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2585 | return Offset; |
| 2586 | } |
| 2587 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2588 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2589 | using namespace llvm; |
| 2590 | RecordData Record; |
| 2591 | |
| 2592 | // Write the type offsets array |
| 2593 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2594 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2595 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2596 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2597 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2598 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2599 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2600 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2601 | Record.push_back(TypeOffsets.size()); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2602 | Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2603 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2604 | |
| 2605 | // Write the declaration offsets array |
| 2606 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2607 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2608 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2609 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2610 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2611 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2612 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2613 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2614 | Record.push_back(DeclOffsets.size()); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2615 | Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2616 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2619 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2620 | using namespace llvm; |
| 2621 | RecordData Record; |
| 2622 | |
| 2623 | // Join the vectors of DeclIDs from all files. |
| 2624 | SmallVector<DeclID, 256> FileSortedIDs; |
| 2625 | for (FileDeclIDsTy::iterator |
| 2626 | FI = FileDeclIDs.begin(), FE = FileDeclIDs.end(); FI != FE; ++FI) { |
| 2627 | DeclIDInFileInfo &Info = *FI->second; |
| 2628 | Info.FirstDeclIndex = FileSortedIDs.size(); |
| 2629 | for (LocDeclIDsTy::iterator |
| 2630 | DI = Info.DeclIDs.begin(), DE = Info.DeclIDs.end(); DI != DE; ++DI) |
| 2631 | FileSortedIDs.push_back(DI->second); |
| 2632 | } |
| 2633 | |
| 2634 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2635 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2636 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2637 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2638 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 2639 | Record.push_back(FILE_SORTED_DECLS); |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2640 | Record.push_back(FileSortedIDs.size()); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2641 | Stream.EmitRecordWithBlob(AbbrevCode, Record, data(FileSortedIDs)); |
| 2642 | } |
| 2643 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2644 | void ASTWriter::WriteComments() { |
| 2645 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2646 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2647 | RecordData Record; |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2648 | for (ArrayRef<RawComment *>::iterator I = RawComments.begin(), |
| 2649 | E = RawComments.end(); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2650 | I != E; ++I) { |
| 2651 | Record.clear(); |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2652 | AddSourceRange((*I)->getSourceRange(), Record); |
| 2653 | Record.push_back((*I)->getKind()); |
| 2654 | Record.push_back((*I)->isTrailingComment()); |
| 2655 | Record.push_back((*I)->isAlmostTrailingComment()); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2656 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2657 | } |
| 2658 | Stream.ExitBlock(); |
| 2659 | } |
| 2660 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2661 | //===----------------------------------------------------------------------===// |
| 2662 | // Global Method Pool and Selector Serialization |
| 2663 | //===----------------------------------------------------------------------===// |
| 2664 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2665 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2666 | // 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] | 2667 | class ASTMethodPoolTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2668 | ASTWriter &Writer; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2669 | |
| 2670 | public: |
| 2671 | typedef Selector key_type; |
| 2672 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2673 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2674 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2675 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2676 | ObjCMethodList Instance, Factory; |
| 2677 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2678 | typedef const data_type& data_type_ref; |
| 2679 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2680 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2681 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2682 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2683 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2684 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2685 | |
| 2686 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2687 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2688 | data_type_ref Methods) { |
| 2689 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 2690 | clang::io::Emit16(Out, KeyLen); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2691 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2692 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2693 | Method = Method->Next) |
| 2694 | if (Method->Method) |
| 2695 | DataLen += 4; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2696 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2697 | Method = Method->Next) |
| 2698 | if (Method->Method) |
| 2699 | DataLen += 4; |
| 2700 | clang::io::Emit16(Out, DataLen); |
| 2701 | return std::make_pair(KeyLen, DataLen); |
| 2702 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2703 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2704 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2705 | uint64_t Start = Out.tell(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2706 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2707 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2708 | unsigned N = Sel.getNumArgs(); |
| 2709 | clang::io::Emit16(Out, N); |
| 2710 | if (N == 0) |
| 2711 | N = 1; |
| 2712 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2713 | clang::io::Emit32(Out, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2714 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 2715 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2716 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2717 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2718 | data_type_ref Methods, unsigned DataLen) { |
| 2719 | uint64_t Start = Out.tell(); (void)Start; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2720 | clang::io::Emit32(Out, Methods.ID); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2721 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2722 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2723 | Method = Method->Next) |
| 2724 | if (Method->Method) |
| 2725 | ++NumInstanceMethods; |
| 2726 | |
| 2727 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2728 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2729 | Method = Method->Next) |
| 2730 | if (Method->Method) |
| 2731 | ++NumFactoryMethods; |
| 2732 | |
| 2733 | clang::io::Emit16(Out, NumInstanceMethods); |
| 2734 | clang::io::Emit16(Out, NumFactoryMethods); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2735 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2736 | Method = Method->Next) |
| 2737 | if (Method->Method) |
| 2738 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2739 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2740 | Method = Method->Next) |
| 2741 | if (Method->Method) |
| 2742 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2743 | |
| 2744 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2745 | } |
| 2746 | }; |
| 2747 | } // end anonymous namespace |
| 2748 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2749 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2750 | /// |
| 2751 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2752 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2753 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2754 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2755 | using namespace llvm; |
| 2756 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2757 | // Do we have to do anything at all? |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2758 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2759 | return; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2760 | unsigned NumTableEntries = 0; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2761 | // 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] | 2762 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2763 | OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2764 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2765 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2766 | // Create the on-disk hash table representation. We walk through every |
| 2767 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2768 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2769 | for (llvm::DenseMap<Selector, SelectorID>::iterator |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2770 | I = SelectorIDs.begin(), E = SelectorIDs.end(); |
| 2771 | I != E; ++I) { |
| 2772 | Selector S = I->first; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2773 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2774 | ASTMethodPoolTrait::data_type Data = { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2775 | I->second, |
| 2776 | ObjCMethodList(), |
| 2777 | ObjCMethodList() |
| 2778 | }; |
| 2779 | if (F != SemaRef.MethodPool.end()) { |
| 2780 | Data.Instance = F->second.first; |
| 2781 | Data.Factory = F->second.second; |
| 2782 | } |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2783 | // 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] | 2784 | // changed. |
| 2785 | if (Chain && I->second < FirstSelectorID) { |
| 2786 | // Selector already exists. Did it change? |
| 2787 | bool changed = false; |
| 2788 | for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; |
| 2789 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2790 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2791 | changed = true; |
| 2792 | } |
| 2793 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; |
| 2794 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2795 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2796 | changed = true; |
| 2797 | } |
| 2798 | if (!changed) |
| 2799 | continue; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2800 | } else if (Data.Instance.Method || Data.Factory.Method) { |
| 2801 | // A new method pool entry. |
| 2802 | ++NumTableEntries; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2803 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2804 | Generator.insert(S, Data, Trait); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2807 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2808 | SmallString<4096> MethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2809 | uint32_t BucketOffset; |
| 2810 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2811 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2812 | llvm::raw_svector_ostream Out(MethodPool); |
| 2813 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2814 | clang::io::Emit32(Out, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2815 | BucketOffset = Generator.Emit(Out, Trait); |
| 2816 | } |
| 2817 | |
| 2818 | // Create a blob abbreviation |
| 2819 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2820 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2821 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2822 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2823 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2824 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2825 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2826 | // Write the method pool |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2827 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2828 | Record.push_back(METHOD_POOL); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2829 | Record.push_back(BucketOffset); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2830 | Record.push_back(NumTableEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2831 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2832 | |
| 2833 | // Create a blob abbreviation for the selector table offsets. |
| 2834 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2835 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2836 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2837 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2838 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2839 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2840 | |
| 2841 | // Write the selector offsets table. |
| 2842 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2843 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2844 | Record.push_back(SelectorOffsets.size()); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2845 | Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2846 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2847 | data(SelectorOffsets)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2848 | } |
| 2849 | } |
| 2850 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2851 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2852 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2853 | using namespace llvm; |
| 2854 | if (SemaRef.ReferencedSelectors.empty()) |
| 2855 | return; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2856 | |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2857 | RecordData Record; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2858 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2859 | // 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] | 2860 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 2861 | // headers, probably not worth it. It's not a correctness issue. |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2862 | for (DenseMap<Selector, SourceLocation>::iterator S = |
| 2863 | SemaRef.ReferencedSelectors.begin(), |
| 2864 | E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { |
| 2865 | Selector Sel = (*S).first; |
| 2866 | SourceLocation Loc = (*S).second; |
| 2867 | AddSelectorRef(Sel, Record); |
| 2868 | AddSourceLocation(Loc, Record); |
| 2869 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2870 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2871 | } |
| 2872 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2873 | //===----------------------------------------------------------------------===// |
| 2874 | // Identifier Table Serialization |
| 2875 | //===----------------------------------------------------------------------===// |
| 2876 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2877 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2878 | class ASTIdentifierTableTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2879 | ASTWriter &Writer; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2880 | Preprocessor &PP; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2881 | IdentifierResolver &IdResolver; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2882 | bool IsModule; |
| 2883 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2884 | /// \brief Determines whether this is an "interesting" identifier |
| 2885 | /// that needs a full IdentifierInfo structure written into the hash |
| 2886 | /// table. |
Argyrios Kyrtzidis | 9818a1d | 2013-02-20 00:54:57 +0000 | [diff] [blame] | 2887 | bool isInterestingIdentifier(IdentifierInfo *II, MacroDirective *&Macro) { |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2888 | if (II->isPoisoned() || |
| 2889 | II->isExtensionToken() || |
| 2890 | II->getObjCOrBuiltinID() || |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2891 | II->hasRevertedTokenIDToIdentifier() || |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2892 | II->getFETokenInfo<void>()) |
| 2893 | return true; |
| 2894 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2895 | return hadMacroDefinition(II, Macro); |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2896 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2897 | |
Argyrios Kyrtzidis | 9818a1d | 2013-02-20 00:54:57 +0000 | [diff] [blame] | 2898 | bool hadMacroDefinition(IdentifierInfo *II, MacroDirective *&Macro) { |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2899 | if (!II->hadMacroDefinition()) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2900 | return false; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2901 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2902 | if (Macro || (Macro = PP.getMacroDirectiveHistory(II))) { |
| 2903 | if (!IsModule) |
| 2904 | return !shouldIgnoreMacro(Macro, IsModule, PP); |
| 2905 | SubmoduleID ModID; |
| 2906 | if (getFirstPublicSubmoduleMacro(Macro, ModID)) |
| 2907 | return true; |
| 2908 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2909 | |
| 2910 | return false; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2913 | DefMacroDirective *getFirstPublicSubmoduleMacro(MacroDirective *MD, |
| 2914 | SubmoduleID &ModID) { |
| 2915 | ModID = 0; |
| 2916 | if (DefMacroDirective *DefMD = getPublicSubmoduleMacro(MD, ModID)) |
| 2917 | if (!shouldIgnoreMacro(DefMD, IsModule, PP)) |
| 2918 | return DefMD; |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2919 | return 0; |
| 2920 | } |
| 2921 | |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2922 | DefMacroDirective *getNextPublicSubmoduleMacro(DefMacroDirective *MD, |
| 2923 | SubmoduleID &ModID) { |
| 2924 | if (DefMacroDirective * |
| 2925 | DefMD = getPublicSubmoduleMacro(MD->getPrevious(), ModID)) |
| 2926 | if (!shouldIgnoreMacro(DefMD, IsModule, PP)) |
| 2927 | return DefMD; |
| 2928 | return 0; |
| 2929 | } |
| 2930 | |
| 2931 | /// \brief Traverses the macro directives history and returns the latest |
| 2932 | /// macro that is public and not undefined in the same submodule. |
| 2933 | /// A macro that is defined in submodule A and undefined in submodule B, |
| 2934 | /// will still be considered as defined/exported from submodule A. |
| 2935 | DefMacroDirective *getPublicSubmoduleMacro(MacroDirective *MD, |
| 2936 | SubmoduleID &ModID) { |
| 2937 | if (!MD) |
| 2938 | return 0; |
| 2939 | |
| 2940 | bool isUndefined = false; |
| 2941 | Optional<bool> isPublic; |
| 2942 | for (; MD; MD = MD->getPrevious()) { |
| 2943 | if (MD->isHidden()) |
| 2944 | continue; |
| 2945 | |
| 2946 | SubmoduleID ThisModID = getSubmoduleID(MD); |
| 2947 | if (ThisModID == 0) { |
| 2948 | isUndefined = false; |
| 2949 | isPublic = Optional<bool>(); |
| 2950 | continue; |
| 2951 | } |
| 2952 | if (ThisModID != ModID){ |
| 2953 | ModID = ThisModID; |
| 2954 | isUndefined = false; |
| 2955 | isPublic = Optional<bool>(); |
| 2956 | } |
| 2957 | |
| 2958 | if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
| 2959 | if (!isUndefined && (!isPublic.hasValue() || isPublic.getValue())) |
| 2960 | return DefMD; |
| 2961 | continue; |
| 2962 | } |
| 2963 | |
| 2964 | if (isa<UndefMacroDirective>(MD)) { |
| 2965 | isUndefined = true; |
| 2966 | continue; |
| 2967 | } |
| 2968 | |
| 2969 | VisibilityMacroDirective *VisMD = cast<VisibilityMacroDirective>(MD); |
| 2970 | if (!isPublic.hasValue()) |
| 2971 | isPublic = VisMD->isPublic(); |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2972 | } |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2973 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2974 | return 0; |
| 2975 | } |
| 2976 | |
| 2977 | SubmoduleID getSubmoduleID(MacroDirective *MD) { |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2978 | if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
| 2979 | MacroInfo *MI = DefMD->getInfo(); |
| 2980 | if (unsigned ID = MI->getOwningModuleID()) |
| 2981 | return ID; |
| 2982 | return Writer.inferSubmoduleIDFromLocation(MI->getDefinitionLoc()); |
| 2983 | } |
| 2984 | return Writer.inferSubmoduleIDFromLocation(MD->getLocation()); |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2985 | } |
| 2986 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2987 | public: |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2988 | typedef IdentifierInfo* key_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2989 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2990 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2991 | typedef IdentID data_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2992 | typedef data_type data_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2993 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2994 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
| 2995 | IdentifierResolver &IdResolver, bool IsModule) |
| 2996 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule) { } |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2997 | |
| 2998 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 2999 | return llvm::HashString(II->getName()); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3000 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3001 | |
| 3002 | std::pair<unsigned,unsigned> |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3003 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3004 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3005 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Argyrios Kyrtzidis | 9818a1d | 2013-02-20 00:54:57 +0000 | [diff] [blame] | 3006 | MacroDirective *Macro = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3007 | if (isInterestingIdentifier(II, Macro)) { |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3008 | DataLen += 2; // 2 bytes for builtin ID |
| 3009 | DataLen += 2; // 2 bytes for flags |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 3010 | if (hadMacroDefinition(II, Macro)) { |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3011 | DataLen += 4; // MacroDirectives offset. |
| 3012 | if (IsModule) { |
| 3013 | SubmoduleID ModID; |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 3014 | for (DefMacroDirective * |
| 3015 | DefMD = getFirstPublicSubmoduleMacro(Macro, ModID); |
| 3016 | DefMD; DefMD = getNextPublicSubmoduleMacro(DefMD, ModID)) { |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3017 | DataLen += 4; // MacroInfo ID. |
| 3018 | } |
| 3019 | DataLen += 4; |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 3020 | } |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 3021 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3022 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3023 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3024 | DEnd = IdResolver.end(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3025 | D != DEnd; ++D) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3026 | DataLen += sizeof(DeclID); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3027 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3028 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3029 | // We emit the key length after the data length so that every |
| 3030 | // string is preceded by a 16-bit length. This matches the PTH |
| 3031 | // format for storing identifiers. |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 3032 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3033 | return std::make_pair(KeyLen, DataLen); |
| 3034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3035 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3036 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3037 | unsigned KeyLen) { |
| 3038 | // Record the location of the key data. This is used when generating |
| 3039 | // the mapping from persistent IDs to strings. |
| 3040 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3041 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3043 | |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3044 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3045 | IdentID ID, unsigned) { |
Argyrios Kyrtzidis | 9818a1d | 2013-02-20 00:54:57 +0000 | [diff] [blame] | 3046 | MacroDirective *Macro = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3047 | if (!isInterestingIdentifier(II, Macro)) { |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3048 | clang::io::Emit32(Out, ID << 1); |
| 3049 | return; |
| 3050 | } |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3051 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3052 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3053 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3054 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
| 3055 | clang::io::Emit16(Out, Bits); |
| 3056 | Bits = 0; |
| 3057 | bool HadMacroDefinition = hadMacroDefinition(II, Macro); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3058 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3059 | Bits = (Bits << 1) | unsigned(IsModule); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3060 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3061 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3062 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3063 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3064 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3065 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3066 | if (HadMacroDefinition) { |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3067 | clang::io::Emit32(Out, Writer.getMacroDirectivesOffset(II)); |
| 3068 | if (IsModule) { |
| 3069 | // Write the IDs of macros coming from different submodules. |
| 3070 | SubmoduleID ModID; |
Argyrios Kyrtzidis | c56fff7 | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 3071 | for (DefMacroDirective * |
| 3072 | DefMD = getFirstPublicSubmoduleMacro(Macro, ModID); |
| 3073 | DefMD; DefMD = getNextPublicSubmoduleMacro(DefMD, ModID)) { |
| 3074 | MacroID InfoID = Writer.getMacroID(DefMD->getInfo()); |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3075 | assert(InfoID); |
| 3076 | clang::io::Emit32(Out, InfoID); |
| 3077 | } |
| 3078 | clang::io::Emit32(Out, 0); |
Argyrios Kyrtzidis | dc1088f | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 3079 | } |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 3080 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3081 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3082 | // Emit the declaration IDs in reverse order, because the |
| 3083 | // IdentifierResolver provides the declarations as they would be |
| 3084 | // visible (e.g., the function "stat" would come before the struct |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3085 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3086 | // (so we need to see the struct "status" before the function "status"). |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3087 | // Only emit declarations that aren't from a chained PCH, though. |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3088 | SmallVector<Decl *, 16> Decls(IdResolver.begin(II), |
| 3089 | IdResolver.end()); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3090 | for (SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3091 | DEnd = Decls.rend(); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3092 | D != DEnd; ++D) |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3093 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3094 | } |
| 3095 | }; |
| 3096 | } // end anonymous namespace |
| 3097 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3098 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3099 | /// |
| 3100 | /// The identifier table consists of a blob containing string data |
| 3101 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3102 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3103 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3104 | IdentifierResolver &IdResolver, |
| 3105 | bool IsModule) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3106 | using namespace llvm; |
| 3107 | |
| 3108 | // Create and write out the blob that contains the identifier |
| 3109 | // strings. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3110 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3111 | OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3112 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3113 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3114 | // Look for any identifiers that were named while processing the |
| 3115 | // headers, but are otherwise not needed. We add these to the hash |
| 3116 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3117 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3118 | // file. |
| 3119 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 3120 | IDEnd = PP.getIdentifierTable().end(); |
| 3121 | ID != IDEnd; ++ID) |
| 3122 | getIdentifierRef(ID->second); |
| 3123 | |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3124 | // Create the on-disk hash table representation. We only store offsets |
| 3125 | // for identifiers that appear here for the first time. |
| 3126 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3127 | for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3128 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 3129 | ID != IDEnd; ++ID) { |
| 3130 | assert(ID->first && "NULL identifier in identifier table"); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3131 | if (!Chain || !ID->first->isFromAST() || |
| 3132 | ID->first->hasChangedSinceDeserialization()) |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3133 | Generator.insert(const_cast<IdentifierInfo *>(ID->first), ID->second, |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3134 | Trait); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3135 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3136 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3137 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3138 | SmallString<4096> IdentifierTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3139 | uint32_t BucketOffset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3140 | { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3141 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3142 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3143 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3144 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3145 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | // Create a blob abbreviation |
| 3149 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3150 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3151 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3152 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3153 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3154 | |
| 3155 | // Write the identifier table |
| 3156 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3157 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3158 | Record.push_back(BucketOffset); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 3159 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3163 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3164 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3165 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3166 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3167 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3168 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3169 | |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3170 | #ifndef NDEBUG |
| 3171 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3172 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3173 | #endif |
| 3174 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3175 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3176 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3177 | Record.push_back(IdentifierOffsets.size()); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3178 | Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3179 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 3180 | data(IdentifierOffsets)); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3183 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3184 | // DeclContext's Name Lookup Table Serialization |
| 3185 | //===----------------------------------------------------------------------===// |
| 3186 | |
| 3187 | namespace { |
| 3188 | // Trait used for the on-disk hash table used in the method pool. |
| 3189 | class ASTDeclContextNameLookupTrait { |
| 3190 | ASTWriter &Writer; |
| 3191 | |
| 3192 | public: |
| 3193 | typedef DeclarationName key_type; |
| 3194 | typedef key_type key_type_ref; |
| 3195 | |
| 3196 | typedef DeclContext::lookup_result data_type; |
| 3197 | typedef const data_type& data_type_ref; |
| 3198 | |
| 3199 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3200 | |
| 3201 | unsigned ComputeHash(DeclarationName Name) { |
| 3202 | llvm::FoldingSetNodeID ID; |
| 3203 | ID.AddInteger(Name.getNameKind()); |
| 3204 | |
| 3205 | switch (Name.getNameKind()) { |
| 3206 | case DeclarationName::Identifier: |
| 3207 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 3208 | break; |
| 3209 | case DeclarationName::ObjCZeroArgSelector: |
| 3210 | case DeclarationName::ObjCOneArgSelector: |
| 3211 | case DeclarationName::ObjCMultiArgSelector: |
| 3212 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 3213 | break; |
| 3214 | case DeclarationName::CXXConstructorName: |
| 3215 | case DeclarationName::CXXDestructorName: |
| 3216 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3217 | break; |
| 3218 | case DeclarationName::CXXOperatorName: |
| 3219 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 3220 | break; |
| 3221 | case DeclarationName::CXXLiteralOperatorName: |
| 3222 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 3223 | case DeclarationName::CXXUsingDirective: |
| 3224 | break; |
| 3225 | } |
| 3226 | |
| 3227 | return ID.ComputeHash(); |
| 3228 | } |
| 3229 | |
| 3230 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3231 | EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3232 | data_type_ref Lookup) { |
| 3233 | unsigned KeyLen = 1; |
| 3234 | switch (Name.getNameKind()) { |
| 3235 | case DeclarationName::Identifier: |
| 3236 | case DeclarationName::ObjCZeroArgSelector: |
| 3237 | case DeclarationName::ObjCOneArgSelector: |
| 3238 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3239 | case DeclarationName::CXXLiteralOperatorName: |
| 3240 | KeyLen += 4; |
| 3241 | break; |
| 3242 | case DeclarationName::CXXOperatorName: |
| 3243 | KeyLen += 1; |
| 3244 | break; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3245 | case DeclarationName::CXXConstructorName: |
| 3246 | case DeclarationName::CXXDestructorName: |
| 3247 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3248 | case DeclarationName::CXXUsingDirective: |
| 3249 | break; |
| 3250 | } |
| 3251 | clang::io::Emit16(Out, KeyLen); |
| 3252 | |
| 3253 | // 2 bytes for num of decls and 4 for each DeclID. |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3254 | unsigned DataLen = 2 + 4 * Lookup.size(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3255 | clang::io::Emit16(Out, DataLen); |
| 3256 | |
| 3257 | return std::make_pair(KeyLen, DataLen); |
| 3258 | } |
| 3259 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3260 | void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3261 | using namespace clang::io; |
| 3262 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3263 | Emit8(Out, Name.getNameKind()); |
| 3264 | switch (Name.getNameKind()) { |
| 3265 | case DeclarationName::Identifier: |
| 3266 | Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3267 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3268 | case DeclarationName::ObjCZeroArgSelector: |
| 3269 | case DeclarationName::ObjCOneArgSelector: |
| 3270 | case DeclarationName::ObjCMultiArgSelector: |
| 3271 | Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3272 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3273 | case DeclarationName::CXXOperatorName: |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3274 | assert(Name.getCXXOverloadedOperator() < NUM_OVERLOADED_OPERATORS && |
| 3275 | "Invalid operator?"); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3276 | Emit8(Out, Name.getCXXOverloadedOperator()); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3277 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3278 | case DeclarationName::CXXLiteralOperatorName: |
| 3279 | Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3280 | return; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3281 | case DeclarationName::CXXConstructorName: |
| 3282 | case DeclarationName::CXXDestructorName: |
| 3283 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3284 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3285 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3286 | } |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3287 | |
| 3288 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3289 | } |
| 3290 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3291 | void EmitData(raw_ostream& Out, key_type_ref, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3292 | data_type Lookup, unsigned DataLen) { |
| 3293 | uint64_t Start = Out.tell(); (void)Start; |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3294 | clang::io::Emit16(Out, Lookup.size()); |
| 3295 | for (DeclContext::lookup_iterator I = Lookup.begin(), E = Lookup.end(); |
| 3296 | I != E; ++I) |
| 3297 | clang::io::Emit32(Out, Writer.GetDeclRef(*I)); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3298 | |
| 3299 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3300 | } |
| 3301 | }; |
| 3302 | } // end anonymous namespace |
| 3303 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3304 | /// \brief Write the block containing all of the declaration IDs |
| 3305 | /// visible from the given DeclContext. |
| 3306 | /// |
| 3307 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3308 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3309 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3310 | DeclContext *DC) { |
| 3311 | if (DC->getPrimaryContext() != DC) |
| 3312 | return 0; |
| 3313 | |
| 3314 | // Since there is no name lookup into functions or methods, don't bother to |
| 3315 | // build a visible-declarations table for these entities. |
| 3316 | if (DC->isFunctionOrMethod()) |
| 3317 | return 0; |
| 3318 | |
| 3319 | // If not in C++, we perform name lookup for the translation unit via the |
| 3320 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 3321 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 3322 | // 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] | 3323 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3324 | return 0; |
| 3325 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3326 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3327 | // although we have two very different code paths, the serialized |
| 3328 | // representation is the same for both cases: a declaration name, |
| 3329 | // followed by a size, followed by references to the visible |
| 3330 | // declarations that have that name. |
| 3331 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | c5d3e80 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3332 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3333 | if (!Map || Map->empty()) |
| 3334 | return 0; |
| 3335 | |
| 3336 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 3337 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3338 | |
| 3339 | // Create the on-disk hash table representation. |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3340 | DeclarationName ConversionName; |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3341 | SmallVector<NamedDecl *, 4> ConversionDecls; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3342 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 3343 | D != DEnd; ++D) { |
| 3344 | DeclarationName Name = D->first; |
| 3345 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3346 | if (!Result.empty()) { |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3347 | if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 3348 | // Hash all conversion function names to the same name. The actual |
| 3349 | // type information in conversion function name is not used in the |
| 3350 | // key (since such type information is not stable across different |
| 3351 | // modules), so the intended effect is to coalesce all of the conversion |
| 3352 | // functions under a single key. |
| 3353 | if (!ConversionName) |
| 3354 | ConversionName = Name; |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3355 | ConversionDecls.append(Result.begin(), Result.end()); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3356 | continue; |
| 3357 | } |
| 3358 | |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 3359 | Generator.insert(Name, Result, Trait); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3360 | } |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 3363 | // Add the conversion functions |
| 3364 | if (!ConversionDecls.empty()) { |
| 3365 | Generator.insert(ConversionName, |
| 3366 | DeclContext::lookup_result(ConversionDecls.begin(), |
| 3367 | ConversionDecls.end()), |
| 3368 | Trait); |
| 3369 | } |
| 3370 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3371 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3372 | SmallString<4096> LookupTable; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3373 | uint32_t BucketOffset; |
| 3374 | { |
| 3375 | llvm::raw_svector_ostream Out(LookupTable); |
| 3376 | // Make sure that no bucket is at offset 0 |
| 3377 | clang::io::Emit32(Out, 0); |
| 3378 | BucketOffset = Generator.Emit(Out, Trait); |
| 3379 | } |
| 3380 | |
| 3381 | // Write the lookup table |
| 3382 | RecordData Record; |
| 3383 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 3384 | Record.push_back(BucketOffset); |
| 3385 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
| 3386 | LookupTable.str()); |
| 3387 | |
| 3388 | Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); |
| 3389 | ++NumVisibleDeclContexts; |
| 3390 | return Offset; |
| 3391 | } |
| 3392 | |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3393 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3394 | /// |
| 3395 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3396 | /// 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] | 3397 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3398 | /// enumeration members (in C++11). |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3399 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3400 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 3401 | if (!Map || Map->empty()) |
| 3402 | return; |
| 3403 | |
| 3404 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 3405 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3406 | |
| 3407 | // Create the hash table. |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3408 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 3409 | D != DEnd; ++D) { |
| 3410 | DeclarationName Name = D->first; |
| 3411 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3412 | // For any name that appears in this table, the results are complete, i.e. |
| 3413 | // they overwrite results from previous PCHs. Merging is always a mess. |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3414 | if (!Result.empty()) |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 3415 | Generator.insert(Name, Result, Trait); |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3419 | SmallString<4096> LookupTable; |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3420 | uint32_t BucketOffset; |
| 3421 | { |
| 3422 | llvm::raw_svector_ostream Out(LookupTable); |
| 3423 | // Make sure that no bucket is at offset 0 |
| 3424 | clang::io::Emit32(Out, 0); |
| 3425 | BucketOffset = Generator.Emit(Out, Trait); |
| 3426 | } |
| 3427 | |
| 3428 | // Write the lookup table |
| 3429 | RecordData Record; |
| 3430 | Record.push_back(UPDATE_VISIBLE); |
| 3431 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 3432 | Record.push_back(BucketOffset); |
| 3433 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); |
| 3434 | } |
| 3435 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3436 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3437 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 3438 | RecordData Record; |
| 3439 | Record.push_back(Opts.fp_contract); |
| 3440 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3441 | } |
| 3442 | |
| 3443 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3444 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3445 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3446 | return; |
| 3447 | |
| 3448 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3449 | RecordData Record; |
| 3450 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3451 | #include "clang/Basic/OpenCLExtensions.def" |
| 3452 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3453 | } |
| 3454 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3455 | void ASTWriter::WriteRedeclarations() { |
| 3456 | RecordData LocalRedeclChains; |
| 3457 | SmallVector<serialization::LocalRedeclarationsInfo, 2> LocalRedeclsMap; |
| 3458 | |
| 3459 | for (unsigned I = 0, N = Redeclarations.size(); I != N; ++I) { |
| 3460 | Decl *First = Redeclarations[I]; |
| 3461 | assert(First->getPreviousDecl() == 0 && "Not the first declaration?"); |
| 3462 | |
| 3463 | Decl *MostRecent = First->getMostRecentDecl(); |
| 3464 | |
| 3465 | // If we only have a single declaration, there is no point in storing |
| 3466 | // a redeclaration chain. |
| 3467 | if (First == MostRecent) |
| 3468 | continue; |
| 3469 | |
| 3470 | unsigned Offset = LocalRedeclChains.size(); |
| 3471 | unsigned Size = 0; |
| 3472 | LocalRedeclChains.push_back(0); // Placeholder for the size. |
| 3473 | |
| 3474 | // Collect the set of local redeclarations of this declaration. |
Douglas Gregor | aa94590 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3475 | for (Decl *Prev = MostRecent; Prev != First; |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3476 | Prev = Prev->getPreviousDecl()) { |
| 3477 | if (!Prev->isFromASTFile()) { |
| 3478 | AddDeclRef(Prev, LocalRedeclChains); |
| 3479 | ++Size; |
| 3480 | } |
| 3481 | } |
Douglas Gregor | aa94590 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3482 | |
| 3483 | if (!First->isFromASTFile() && Chain) { |
| 3484 | Decl *FirstFromAST = MostRecent; |
| 3485 | for (Decl *Prev = MostRecent; Prev; Prev = Prev->getPreviousDecl()) { |
| 3486 | if (Prev->isFromASTFile()) |
| 3487 | FirstFromAST = Prev; |
| 3488 | } |
| 3489 | |
| 3490 | Chain->MergedDecls[FirstFromAST].push_back(getDeclID(First)); |
| 3491 | } |
| 3492 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3493 | LocalRedeclChains[Offset] = Size; |
| 3494 | |
| 3495 | // Reverse the set of local redeclarations, so that we store them in |
| 3496 | // order (since we found them in reverse order). |
| 3497 | std::reverse(LocalRedeclChains.end() - Size, LocalRedeclChains.end()); |
| 3498 | |
Douglas Gregor | aa94590 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3499 | // Add the mapping from the first ID from the AST to the set of local |
| 3500 | // declarations. |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3501 | LocalRedeclarationsInfo Info = { getDeclID(First), Offset }; |
| 3502 | LocalRedeclsMap.push_back(Info); |
| 3503 | |
| 3504 | assert(N == Redeclarations.size() && |
| 3505 | "Deserialized a declaration we shouldn't have"); |
| 3506 | } |
| 3507 | |
| 3508 | if (LocalRedeclChains.empty()) |
| 3509 | return; |
| 3510 | |
| 3511 | // Sort the local redeclarations map by the first declaration ID, |
| 3512 | // since the reader will be performing binary searches on this information. |
| 3513 | llvm::array_pod_sort(LocalRedeclsMap.begin(), LocalRedeclsMap.end()); |
| 3514 | |
| 3515 | // Emit the local redeclarations map. |
| 3516 | using namespace llvm; |
| 3517 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3518 | Abbrev->Add(BitCodeAbbrevOp(LOCAL_REDECLARATIONS_MAP)); |
| 3519 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3520 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3521 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3522 | |
| 3523 | RecordData Record; |
| 3524 | Record.push_back(LOCAL_REDECLARATIONS_MAP); |
| 3525 | Record.push_back(LocalRedeclsMap.size()); |
| 3526 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3527 | reinterpret_cast<char*>(LocalRedeclsMap.data()), |
| 3528 | LocalRedeclsMap.size() * sizeof(LocalRedeclarationsInfo)); |
| 3529 | |
| 3530 | // Emit the redeclaration chains. |
| 3531 | Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedeclChains); |
| 3532 | } |
| 3533 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3534 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3535 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3536 | RecordData Categories; |
| 3537 | |
| 3538 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3539 | unsigned Size = 0; |
| 3540 | unsigned StartIndex = Categories.size(); |
| 3541 | |
| 3542 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3543 | |
| 3544 | // Allocate space for the size. |
| 3545 | Categories.push_back(0); |
| 3546 | |
| 3547 | // Add the categories. |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3548 | for (ObjCInterfaceDecl::known_categories_iterator |
| 3549 | Cat = Class->known_categories_begin(), |
| 3550 | CatEnd = Class->known_categories_end(); |
| 3551 | Cat != CatEnd; ++Cat, ++Size) { |
| 3552 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 3553 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | // Update the size. |
| 3557 | Categories[StartIndex] = Size; |
| 3558 | |
| 3559 | // Record this interface -> category map. |
| 3560 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3561 | CategoriesMap.push_back(CatInfo); |
| 3562 | } |
| 3563 | |
| 3564 | // Sort the categories map by the definition ID, since the reader will be |
| 3565 | // performing binary searches on this information. |
| 3566 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3567 | |
| 3568 | // Emit the categories map. |
| 3569 | using namespace llvm; |
| 3570 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3571 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3572 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3573 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3574 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3575 | |
| 3576 | RecordData Record; |
| 3577 | Record.push_back(OBJC_CATEGORIES_MAP); |
| 3578 | Record.push_back(CategoriesMap.size()); |
| 3579 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3580 | reinterpret_cast<char*>(CategoriesMap.data()), |
| 3581 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
| 3582 | |
| 3583 | // Emit the category lists. |
| 3584 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3585 | } |
| 3586 | |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3587 | void ASTWriter::WriteMergedDecls() { |
| 3588 | if (!Chain || Chain->MergedDecls.empty()) |
| 3589 | return; |
| 3590 | |
| 3591 | RecordData Record; |
| 3592 | for (ASTReader::MergedDeclsMap::iterator I = Chain->MergedDecls.begin(), |
| 3593 | IEnd = Chain->MergedDecls.end(); |
| 3594 | I != IEnd; ++I) { |
Douglas Gregor | b6b60c1 | 2012-01-05 22:27:05 +0000 | [diff] [blame] | 3595 | DeclID CanonID = I->first->isFromASTFile()? I->first->getGlobalID() |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3596 | : getDeclID(I->first); |
| 3597 | assert(CanonID && "Merged declaration not known?"); |
| 3598 | |
| 3599 | Record.push_back(CanonID); |
| 3600 | Record.push_back(I->second.size()); |
| 3601 | Record.append(I->second.begin(), I->second.end()); |
| 3602 | } |
| 3603 | Stream.EmitRecord(MERGED_DECLARATIONS, Record); |
| 3604 | } |
| 3605 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3606 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3607 | // General Serialization Routines |
| 3608 | //===----------------------------------------------------------------------===// |
| 3609 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3610 | /// \brief Write a record containing the given attributes. |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3611 | void ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, |
| 3612 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4eb9fc0 | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3613 | Record.push_back(Attrs.size()); |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3614 | for (ArrayRef<const Attr *>::iterator i = Attrs.begin(), |
| 3615 | e = Attrs.end(); i != e; ++i){ |
| 3616 | const Attr *A = *i; |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3617 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 768d6ca | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 3618 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3619 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3620 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3621 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3622 | } |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3623 | } |
| 3624 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3625 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3626 | Record.push_back(Str.size()); |
| 3627 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 3628 | } |
| 3629 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3630 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 3631 | RecordDataImpl &Record) { |
| 3632 | Record.push_back(Version.getMajor()); |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3633 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3634 | Record.push_back(*Minor + 1); |
| 3635 | else |
| 3636 | Record.push_back(0); |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3637 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3638 | Record.push_back(*Subminor + 1); |
| 3639 | else |
| 3640 | Record.push_back(0); |
| 3641 | } |
| 3642 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3643 | /// \brief Note that the identifier II occurs at the given offset |
| 3644 | /// within the identifier table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3645 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3646 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3647 | // 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] | 3648 | // up earlier in the chain and thus don't need an offset. |
| 3649 | if (ID >= FirstIdentID) |
| 3650 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3653 | /// \brief Note that the selector Sel occurs at the given offset |
| 3654 | /// within the method pool/selector table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3655 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3656 | unsigned ID = SelectorIDs[Sel]; |
| 3657 | assert(ID && "Unknown selector"); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3658 | // Don't record offsets for selectors that are also available in a different |
| 3659 | // file. |
| 3660 | if (ID < FirstSelectorID) |
| 3661 | return; |
| 3662 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3663 | } |
| 3664 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3665 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3666 | : Stream(Stream), Context(0), PP(0), Chain(0), WritingModule(0), |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3667 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 3668 | ASTHasCompilerErrors(false), |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3669 | FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3670 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3671 | FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), |
| 3672 | FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID), |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3673 | FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
| 3674 | NextSubmoduleID(FirstSubmoduleID), |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3675 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3676 | CollectedStmts(&StmtsToEmit), |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3677 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3678 | NumVisibleDeclContexts(0), |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3679 | NextCXXBaseSpecifiersID(1), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3680 | DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3681 | DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), |
| 3682 | DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), |
| 3683 | DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3684 | DeclTypedefAbbrev(0), |
| 3685 | DeclVarAbbrev(0), DeclFieldAbbrev(0), |
| 3686 | DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3687 | { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3688 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3689 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3690 | ASTWriter::~ASTWriter() { |
| 3691 | for (FileDeclIDsTy::iterator |
| 3692 | I = FileDeclIDs.begin(), E = FileDeclIDs.end(); I != E; ++I) |
| 3693 | delete I->second; |
| 3694 | } |
| 3695 | |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 3696 | void ASTWriter::WriteAST(Sema &SemaRef, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 3697 | const std::string &OutputFile, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3698 | Module *WritingModule, StringRef isysroot, |
| 3699 | bool hasErrors) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3700 | WritingAST = true; |
| 3701 | |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3702 | ASTHasCompilerErrors = hasErrors; |
| 3703 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3704 | // Emit the file header. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3705 | Stream.Emit((unsigned)'C', 8); |
| 3706 | Stream.Emit((unsigned)'P', 8); |
| 3707 | Stream.Emit((unsigned)'C', 8); |
| 3708 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3709 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 3710 | WriteBlockInfoBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3711 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3712 | Context = &SemaRef.Context; |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3713 | PP = &SemaRef.PP; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3714 | this->WritingModule = WritingModule; |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 3715 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3716 | Context = 0; |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3717 | PP = 0; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3718 | this->WritingModule = 0; |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3719 | |
| 3720 | WritingAST = false; |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3721 | } |
| 3722 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3723 | template<typename Vector> |
| 3724 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 3725 | ASTWriter::RecordData &Record) { |
| 3726 | for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end(); |
| 3727 | I != E; ++I) { |
| 3728 | Writer.AddDeclRef(*I, Record); |
| 3729 | } |
| 3730 | } |
| 3731 | |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 3732 | void ASTWriter::WriteASTCore(Sema &SemaRef, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3733 | StringRef isysroot, |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3734 | const std::string &OutputFile, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3735 | Module *WritingModule) { |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3736 | using namespace llvm; |
| 3737 | |
Argyrios Kyrtzidis | 975d353 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 3738 | bool isModule = WritingModule != 0; |
| 3739 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3740 | // Make sure that the AST reader knows to finalize itself. |
| 3741 | if (Chain) |
| 3742 | Chain->finalizeForWriting(); |
| 3743 | |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3744 | ASTContext &Context = SemaRef.Context; |
| 3745 | Preprocessor &PP = SemaRef.PP; |
| 3746 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3747 | // Set up predefined declaration IDs. |
| 3748 | DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 3749 | if (Context.ObjCIdDecl) |
| 3750 | DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID; |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 3751 | if (Context.ObjCSelDecl) |
| 3752 | DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 3753 | if (Context.ObjCClassDecl) |
| 3754 | DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 3755 | if (Context.ObjCProtocolClassDecl) |
| 3756 | DeclIDs[Context.ObjCProtocolClassDecl] = PREDEF_DECL_OBJC_PROTOCOL_ID; |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 3757 | if (Context.Int128Decl) |
| 3758 | DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; |
| 3759 | if (Context.UInt128Decl) |
| 3760 | DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 3761 | if (Context.ObjCInstanceTypeDecl) |
| 3762 | DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID; |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 3763 | if (Context.BuiltinVaListDecl) |
| 3764 | DeclIDs[Context.getBuiltinVaListDecl()] = PREDEF_DECL_BUILTIN_VA_LIST_ID; |
| 3765 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3766 | if (!Chain) { |
| 3767 | // Make sure that we emit IdentifierInfos (and any attached |
| 3768 | // declarations) for builtins. We don't need to do this when we're |
| 3769 | // emitting chained PCH files, because all of the builtins will be |
| 3770 | // in the original PCH file. |
| 3771 | // FIXME: Modules won't like this at all. |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3772 | IdentifierTable &Table = PP.getIdentifierTable(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3773 | SmallVector<const char *, 32> BuiltinNames; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3774 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3775 | Context.getLangOpts().NoBuiltin); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3776 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 3777 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 3778 | } |
| 3779 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3780 | // If there are any out-of-date identifiers, bring them up to date. |
| 3781 | if (ExternalPreprocessorSource *ExtSource = PP.getExternalSource()) { |
Douglas Gregor | 589dae7 | 2013-01-07 16:56:53 +0000 | [diff] [blame] | 3782 | // Find out-of-date identifiers. |
| 3783 | SmallVector<IdentifierInfo *, 4> OutOfDate; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3784 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 3785 | IDEnd = PP.getIdentifierTable().end(); |
Douglas Gregor | 589dae7 | 2013-01-07 16:56:53 +0000 | [diff] [blame] | 3786 | ID != IDEnd; ++ID) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3787 | if (ID->second->isOutOfDate()) |
Douglas Gregor | 589dae7 | 2013-01-07 16:56:53 +0000 | [diff] [blame] | 3788 | OutOfDate.push_back(ID->second); |
| 3789 | } |
| 3790 | |
| 3791 | // Update the out-of-date identifiers. |
| 3792 | for (unsigned I = 0, N = OutOfDate.size(); I != N; ++I) { |
| 3793 | ExtSource->updateOutOfDateIdentifier(*OutOfDate[I]); |
| 3794 | } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3797 | // 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] | 3798 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3799 | // headers. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3800 | RecordData TentativeDefinitions; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3801 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 3802 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3803 | // Build a record containing all of the file scoped decls in this file. |
| 3804 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | faf01f0 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 3805 | if (!isModule) |
| 3806 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 3807 | UnusedFileScopedDecls); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3808 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3809 | // Build a record containing all of the delegating constructors we still need |
| 3810 | // to resolve. |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3811 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | 975d353 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 3812 | if (!isModule) |
| 3813 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3814 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3815 | // Write the set of weak, undeclared identifiers. We always write the |
| 3816 | // entire table, since later PCH files in a PCH chain are only interested in |
| 3817 | // the results at the end of the chain. |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3818 | RecordData WeakUndeclaredIdentifiers; |
| 3819 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 3820 | for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3821 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 3822 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 3823 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 3824 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 3825 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 3826 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 3827 | } |
| 3828 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3829 | |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3830 | // Build a record containing all of the locally-scoped extern "C" |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3831 | // declarations in this header file. Generally, this record will be |
| 3832 | // empty. |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3833 | RecordData LocallyScopedExternCDecls; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3834 | // 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] | 3835 | // nondeterminstic! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3837 | TD = SemaRef.LocallyScopedExternCDecls.begin(), |
| 3838 | TDEnd = SemaRef.LocallyScopedExternCDecls.end(); |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3839 | TD != TDEnd; ++TD) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3840 | if (!TD->second->isFromASTFile()) |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 3841 | AddDeclRef(TD->second, LocallyScopedExternCDecls); |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3844 | // Build a record containing all of the ext_vector declarations. |
| 3845 | RecordData ExtVectorDecls; |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 3846 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3847 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3848 | // Build a record containing all of the VTable uses information. |
| 3849 | RecordData VTableUses; |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3850 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3851 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 3852 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 3853 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 3854 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 3855 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | // Build a record containing all of dynamic classes declarations. |
| 3859 | RecordData DynamicClasses; |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 3860 | AddLazyVectorDecls(*this, SemaRef.DynamicClasses, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3861 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3862 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3863 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3864 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3865 | I = SemaRef.PendingInstantiations.begin(), |
| 3866 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 3867 | AddDeclRef(I->first, PendingInstantiations); |
| 3868 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3869 | } |
| 3870 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 3871 | "There are local ones at end of translation unit!"); |
| 3872 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3873 | // Build a record containing some declaration references. |
| 3874 | RecordData SemaDeclRefs; |
| 3875 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 3876 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 3877 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 3878 | } |
| 3879 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3880 | RecordData CUDASpecialDeclRefs; |
| 3881 | if (Context.getcudaConfigureCallDecl()) { |
| 3882 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 3883 | } |
| 3884 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3885 | // Build a record containing all of the known namespaces. |
| 3886 | RecordData KnownNamespaces; |
Nick Lewycky | 01a4114 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3887 | for (llvm::MapVector<NamespaceDecl*, bool>::iterator |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3888 | I = SemaRef.KnownNamespaces.begin(), |
| 3889 | IEnd = SemaRef.KnownNamespaces.end(); |
| 3890 | I != IEnd; ++I) { |
| 3891 | if (!I->second) |
| 3892 | AddDeclRef(I->first, KnownNamespaces); |
| 3893 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3894 | |
Nick Lewycky | cd0655b | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3895 | // Build a record of all used, undefined objects that require definitions. |
| 3896 | RecordData UndefinedButUsed; |
Nick Lewycky | 995e26b | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 3897 | |
| 3898 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | cd0655b | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3899 | SemaRef.getUndefinedButUsed(Undefined); |
Nick Lewycky | 995e26b | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 3900 | for (SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> >::iterator |
| 3901 | I = Undefined.begin(), E = Undefined.end(); I != E; ++I) { |
Nick Lewycky | cd0655b | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3902 | AddDeclRef(I->first, UndefinedButUsed); |
| 3903 | AddSourceLocation(I->second, UndefinedButUsed); |
Nick Lewycky | 01a4114 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3904 | } |
| 3905 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3906 | // Write the control block |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3907 | WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3908 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3909 | // Write the remaining AST contents. |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3910 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3911 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3912 | |
Argyrios Kyrtzidis | 5e24f2d | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 3913 | // This is so that older clang versions, before the introduction |
| 3914 | // of the control block, can read and reject the newer PCH format. |
| 3915 | Record.clear(); |
| 3916 | Record.push_back(VERSION_MAJOR); |
| 3917 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 3918 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3919 | // Create a lexical update block containing all of the declarations in the |
| 3920 | // translation unit that do not come from other AST files. |
| 3921 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
| 3922 | SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
| 3923 | for (DeclContext::decl_iterator I = TU->noload_decls_begin(), |
| 3924 | E = TU->noload_decls_end(); |
| 3925 | I != E; ++I) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3926 | if (!(*I)->isFromASTFile()) |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3927 | NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 3931 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 3932 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3933 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 3934 | Record.clear(); |
| 3935 | Record.push_back(TU_UPDATE_LEXICAL); |
| 3936 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 3937 | data(NewGlobalDecls)); |
| 3938 | |
| 3939 | // And a visible updates block for the translation unit. |
| 3940 | Abv = new llvm::BitCodeAbbrev(); |
| 3941 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 3942 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3943 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 3944 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3945 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 3946 | WriteDeclContextVisibleUpdate(TU); |
| 3947 | |
| 3948 | // If the translation unit has an anonymous namespace, and we don't already |
| 3949 | // have an update block for it, write it as an update block. |
| 3950 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 3951 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
| 3952 | if (Record.empty()) { |
| 3953 | Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3954 | Record.push_back(reinterpret_cast<uint64_t>(NS)); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3955 | } |
| 3956 | } |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3957 | |
| 3958 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 3959 | // an AST file, are registered for serialization. |
| 3960 | for (SmallVector<const Decl *, 16>::iterator |
| 3961 | I = UpdatingVisibleDecls.begin(), |
| 3962 | E = UpdatingVisibleDecls.end(); I != E; ++I) { |
| 3963 | GetDeclRef(*I); |
| 3964 | } |
| 3965 | |
Argyrios Kyrtzidis | 67bc4ba | 2011-11-14 04:52:24 +0000 | [diff] [blame] | 3966 | // Resolve any declaration pointers within the declaration updates block. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3967 | ResolveDeclUpdatesBlocks(); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3968 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3969 | // Form the record of special types. |
| 3970 | RecordData SpecialTypes; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3971 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3972 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 3973 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 3974 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 3975 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 3976 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3977 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 3978 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3980 | // Keep writing types and declarations until all types and |
| 3981 | // declarations have been written. |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3982 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3983 | WriteDeclsBlockAbbrevs(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3984 | for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), |
| 3985 | E = DeclsToRewrite.end(); |
| 3986 | I != E; ++I) |
| 3987 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3988 | while (!DeclTypesToEmit.empty()) { |
| 3989 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 3990 | DeclTypesToEmit.pop(); |
| 3991 | if (DOT.isType()) |
| 3992 | WriteType(DOT.getType()); |
| 3993 | else |
| 3994 | WriteDecl(Context, DOT.getDecl()); |
| 3995 | } |
| 3996 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3997 | |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3998 | DoneWritingDeclsAndTypes = true; |
| 3999 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4000 | WriteFileDeclIDsMap(); |
| 4001 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 4002 | WriteComments(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4003 | |
| 4004 | if (Chain) { |
| 4005 | // Write the mapping information describing our module dependencies and how |
| 4006 | // each of those modules were mapped into our own offset/ID space, so that |
| 4007 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4008 | // The map consists solely of a blob with the following format: |
| 4009 | // *(module-name-len:i16 module-name:len*i8 |
| 4010 | // source-location-offset:i32 |
| 4011 | // identifier-id:i32 |
| 4012 | // preprocessed-entity-id:i32 |
| 4013 | // macro-definition-id:i32 |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4014 | // submodule-id:i32 |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4015 | // selector-id:i32 |
| 4016 | // declaration-id:i32 |
| 4017 | // c++-base-specifiers-id:i32 |
| 4018 | // type-id:i32) |
| 4019 | // |
| 4020 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 4021 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4022 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 4023 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4024 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4025 | { |
| 4026 | llvm::raw_svector_ostream Out(Buffer); |
| 4027 | for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 4028 | MEnd = Chain->ModuleMgr.end(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4029 | M != MEnd; ++M) { |
| 4030 | StringRef FileName = (*M)->FileName; |
| 4031 | io::Emit16(Out, FileName.size()); |
| 4032 | Out.write(FileName.data(), FileName.size()); |
| 4033 | io::Emit32(Out, (*M)->SLocEntryBaseOffset); |
| 4034 | io::Emit32(Out, (*M)->BaseIdentifierID); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4035 | io::Emit32(Out, (*M)->BaseMacroID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4036 | io::Emit32(Out, (*M)->BasePreprocessedEntityID); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4037 | io::Emit32(Out, (*M)->BaseSubmoduleID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4038 | io::Emit32(Out, (*M)->BaseSelectorID); |
| 4039 | io::Emit32(Out, (*M)->BaseDeclID); |
| 4040 | io::Emit32(Out, (*M)->BaseTypeIndex); |
| 4041 | } |
| 4042 | } |
| 4043 | Record.clear(); |
| 4044 | Record.push_back(MODULE_OFFSET_MAP); |
| 4045 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4046 | Buffer.data(), Buffer.size()); |
| 4047 | } |
Argyrios Kyrtzidis | 975d353 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4048 | WritePreprocessor(PP, isModule); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4049 | WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4050 | WriteSelectors(SemaRef); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4051 | WriteReferencedSelectorsPool(SemaRef); |
Argyrios Kyrtzidis | 975d353 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4052 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4053 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4054 | WriteOpenCLExtensions(SemaRef); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4055 | |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4056 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | ea744ab | 2013-03-27 17:17:23 +0000 | [diff] [blame^] | 4057 | WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4058 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 4059 | WriteCXXBaseSpecifiersOffsets(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4060 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4061 | // If we're emitting a module, write out the submodule information. |
| 4062 | if (WritingModule) |
| 4063 | WriteSubmodules(WritingModule); |
| 4064 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4065 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4066 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4067 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4068 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4069 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4070 | |
| 4071 | // Write the record containing tentative definitions. |
| 4072 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4073 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4074 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4075 | // Write the record containing unused file scoped decls. |
| 4076 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4077 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4078 | |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4079 | // Write the record containing weak undeclared identifiers. |
| 4080 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4081 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4082 | WeakUndeclaredIdentifiers); |
| 4083 | |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 4084 | // Write the record containing locally-scoped extern "C" definitions. |
| 4085 | if (!LocallyScopedExternCDecls.empty()) |
| 4086 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERN_C_DECLS, |
| 4087 | LocallyScopedExternCDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4088 | |
| 4089 | // Write the record containing ext_vector type names. |
| 4090 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4091 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4093 | // Write the record containing VTable uses information. |
| 4094 | if (!VTableUses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4095 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4096 | |
| 4097 | // Write the record containing dynamic classes declarations. |
| 4098 | if (!DynamicClasses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4099 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4100 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4101 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4102 | if (!PendingInstantiations.empty()) |
| 4103 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4104 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4105 | // Write the record containing declaration references of Sema. |
| 4106 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4107 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4108 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4109 | // Write the record containing CUDA-specific declaration references. |
| 4110 | if (!CUDASpecialDeclRefs.empty()) |
| 4111 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4112 | |
| 4113 | // Write the delegating constructors. |
| 4114 | if (!DelegatingCtorDecls.empty()) |
| 4115 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4116 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4117 | // Write the known namespaces. |
| 4118 | if (!KnownNamespaces.empty()) |
| 4119 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 01a4114 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4120 | |
Nick Lewycky | cd0655b | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4121 | // Write the undefined internal functions and variables, and inline functions. |
| 4122 | if (!UndefinedButUsed.empty()) |
| 4123 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4124 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4125 | // Write the visible updates to DeclContexts. |
| 4126 | for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |
| 4127 | I = UpdatedDeclContexts.begin(), |
| 4128 | E = UpdatedDeclContexts.end(); |
| 4129 | I != E; ++I) |
| 4130 | WriteDeclContextVisibleUpdate(*I); |
| 4131 | |
Douglas Gregor | c5e0f9b | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4132 | if (!WritingModule) { |
| 4133 | // Write the submodules that were imported, if any. |
| 4134 | RecordData ImportedModules; |
| 4135 | for (ASTContext::import_iterator I = Context.local_import_begin(), |
| 4136 | IEnd = Context.local_import_end(); |
| 4137 | I != IEnd; ++I) { |
| 4138 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
| 4139 | ImportedModules.push_back(SubmoduleIDs[I->getImportedModule()]); |
| 4140 | } |
| 4141 | if (!ImportedModules.empty()) { |
| 4142 | // Sort module IDs. |
| 4143 | llvm::array_pod_sort(ImportedModules.begin(), ImportedModules.end()); |
| 4144 | |
| 4145 | // Unique module IDs. |
| 4146 | ImportedModules.erase(std::unique(ImportedModules.begin(), |
| 4147 | ImportedModules.end()), |
| 4148 | ImportedModules.end()); |
| 4149 | |
| 4150 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4151 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4152 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4154 | WriteDeclUpdatesBlocks(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4155 | WriteDeclReplacementsBlock(); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 4156 | WriteRedeclarations(); |
Douglas Gregor | aa94590 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 4157 | WriteMergedDecls(); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4158 | WriteObjCCategories(); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4159 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4160 | // Some simple statistics |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4161 | Record.clear(); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4162 | Record.push_back(NumStatements); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 4163 | Record.push_back(NumMacros); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4164 | Record.push_back(NumLexicalDeclContexts); |
| 4165 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4166 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4167 | Stream.ExitBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4168 | } |
| 4169 | |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4170 | /// \brief Go through the declaration update blocks and resolve declaration |
| 4171 | /// pointers into declaration IDs. |
| 4172 | void ASTWriter::ResolveDeclUpdatesBlocks() { |
| 4173 | for (DeclUpdateMap::iterator |
| 4174 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 4175 | const Decl *D = I->first; |
| 4176 | UpdateRecord &URec = I->second; |
| 4177 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 4178 | if (isRewritten(D)) |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4179 | continue; // The decl will be written completely |
| 4180 | |
| 4181 | unsigned Idx = 0, N = URec.size(); |
| 4182 | while (Idx < N) { |
| 4183 | switch ((DeclUpdateKind)URec[Idx++]) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4184 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 4185 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 4186 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
| 4187 | URec[Idx] = GetDeclRef(reinterpret_cast<Decl *>(URec[Idx])); |
| 4188 | ++Idx; |
| 4189 | break; |
| 4190 | |
| 4191 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
| 4192 | ++Idx; |
| 4193 | break; |
| 4194 | } |
| 4195 | } |
| 4196 | } |
| 4197 | } |
| 4198 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 4199 | void ASTWriter::WriteDeclUpdatesBlocks() { |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4200 | if (DeclUpdates.empty()) |
| 4201 | return; |
| 4202 | |
| 4203 | RecordData OffsetsRecord; |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 4204 | Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4205 | for (DeclUpdateMap::iterator |
| 4206 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 4207 | const Decl *D = I->first; |
| 4208 | UpdateRecord &URec = I->second; |
| 4209 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 4210 | if (isRewritten(D)) |
Argyrios Kyrtzidis | ba901b5 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4211 | continue; // The decl will be written completely,no need to store updates. |
| 4212 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4213 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 4214 | Stream.EmitRecord(DECL_UPDATES, URec); |
| 4215 | |
| 4216 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 4217 | OffsetsRecord.push_back(Offset); |
| 4218 | } |
| 4219 | Stream.ExitBlock(); |
| 4220 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); |
| 4221 | } |
| 4222 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 4223 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4224 | if (ReplacedDecls.empty()) |
| 4225 | return; |
| 4226 | |
| 4227 | RecordData Record; |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 4228 | for (SmallVector<ReplacedDeclInfo, 16>::iterator |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4229 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 4230 | Record.push_back(I->ID); |
| 4231 | Record.push_back(I->Offset); |
| 4232 | Record.push_back(I->Loc); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4233 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4234 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4235 | } |
| 4236 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4237 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4238 | Record.push_back(Loc.getRawEncoding()); |
| 4239 | } |
| 4240 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4241 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4242 | AddSourceLocation(Range.getBegin(), Record); |
| 4243 | AddSourceLocation(Range.getEnd(), Record); |
| 4244 | } |
| 4245 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4246 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4247 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4248 | const uint64_t *Words = Value.getRawData(); |
| 4249 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4252 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4253 | Record.push_back(Value.isUnsigned()); |
| 4254 | AddAPInt(Value, Record); |
| 4255 | } |
| 4256 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4257 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4258 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 4259 | } |
| 4260 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4261 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4262 | Record.push_back(getIdentifierRef(II)); |
| 4263 | } |
| 4264 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4265 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4266 | if (II == 0) |
| 4267 | return 0; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4268 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4269 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4270 | if (ID == 0) |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4271 | ID = NextIdentID++; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4272 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4275 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4276 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 4277 | // have been redefined by the header (in which case they are not |
| 4278 | // isBuiltinMacro). |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4279 | if (MI == 0 || MI->isBuiltinMacro()) |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4280 | return 0; |
| 4281 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4282 | MacroID &ID = MacroIDs[MI]; |
| 4283 | if (ID == 0) { |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4284 | ID = NextMacroID++; |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4285 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 4286 | MacroInfosToEmit.push_back(Info); |
| 4287 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4288 | return ID; |
| 4289 | } |
| 4290 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4291 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
| 4292 | if (MI == 0 || MI->isBuiltinMacro()) |
| 4293 | return 0; |
| 4294 | |
| 4295 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 4296 | return MacroIDs[MI]; |
| 4297 | } |
| 4298 | |
| 4299 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
| 4300 | assert(IdentMacroDirectivesOffsetMap[Name] && "not set!"); |
| 4301 | return IdentMacroDirectivesOffsetMap[Name]; |
| 4302 | } |
| 4303 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4304 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4305 | Record.push_back(getSelectorRef(SelRef)); |
| 4306 | } |
| 4307 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4308 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4309 | if (Sel.getAsOpaquePtr() == 0) { |
| 4310 | return 0; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4311 | } |
| 4312 | |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4313 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4314 | if (SID == 0 && Chain) { |
| 4315 | // This might trigger a ReadSelector callback, which will set the ID for |
| 4316 | // this selector. |
| 4317 | Chain->LoadSelector(Sel); |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4318 | SID = SelectorIDs[Sel]; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4319 | } |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4320 | if (SID == 0) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4321 | SID = NextSelectorID++; |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4322 | SelectorIDs[Sel] = SID; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4323 | } |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4324 | return SID; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4325 | } |
| 4326 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4327 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4328 | AddDeclRef(Temp->getDestructor(), Record); |
| 4329 | } |
| 4330 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4331 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
| 4332 | CXXBaseSpecifier const *BasesEnd, |
| 4333 | RecordDataImpl &Record) { |
| 4334 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 4335 | CXXBaseSpecifiersToWrite.push_back( |
| 4336 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 4337 | Bases, BasesEnd)); |
| 4338 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 4339 | } |
| 4340 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4341 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4342 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4343 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4344 | switch (Kind) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4345 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4346 | AddStmt(Arg.getAsExpr()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4347 | break; |
| 4348 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4349 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4350 | break; |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4351 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4352 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4353 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4354 | break; |
| 4355 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4356 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4357 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4358 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4359 | break; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4360 | case TemplateArgument::Null: |
| 4361 | case TemplateArgument::Integral: |
| 4362 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4363 | case TemplateArgument::NullPtr: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4364 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4365 | // FIXME: Is this right? |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4366 | break; |
| 4367 | } |
| 4368 | } |
| 4369 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4370 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4371 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4372 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4373 | |
| 4374 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 4375 | bool InfoHasSameExpr |
| 4376 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 4377 | Record.push_back(InfoHasSameExpr); |
| 4378 | if (InfoHasSameExpr) |
| 4379 | return; // Avoid storing the same expr twice. |
| 4380 | } |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4381 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 4382 | Record); |
| 4383 | } |
| 4384 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4385 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 4386 | RecordDataImpl &Record) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4387 | if (TInfo == 0) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4388 | AddTypeRef(QualType(), Record); |
| 4389 | return; |
| 4390 | } |
| 4391 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4392 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 4393 | } |
| 4394 | |
| 4395 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 4396 | AddTypeRef(TL.getType(), Record); |
| 4397 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4398 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4399 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4400 | TLW.Visit(TL); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4401 | } |
| 4402 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4403 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 7fb3518 | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 4404 | Record.push_back(GetOrCreateTypeID(T)); |
| 4405 | } |
| 4406 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4407 | TypeID ASTWriter::GetOrCreateTypeID( QualType T) { |
| 4408 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4409 | std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); |
| 4410 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4411 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4412 | TypeID ASTWriter::getTypeID(QualType T) const { |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4413 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4414 | std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { |
| 4418 | if (T.isNull()) |
| 4419 | return TypeIdx(); |
| 4420 | assert(!T.getLocalFastQualifiers()); |
| 4421 | |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 4422 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4423 | if (Idx.getIndex() == 0) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4424 | if (DoneWritingDeclsAndTypes) { |
| 4425 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 4426 | return TypeIdx(); |
| 4427 | } |
| 4428 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 4429 | // 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] | 4430 | // into the queue of types to emit. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4431 | Idx = TypeIdx(NextTypeID++); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4432 | DeclTypesToEmit.push(T); |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 4433 | } |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 4434 | return Idx; |
| 4435 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4436 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4437 | TypeIdx ASTWriter::getTypeIdx(QualType T) const { |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 4438 | if (T.isNull()) |
| 4439 | return TypeIdx(); |
| 4440 | assert(!T.getLocalFastQualifiers()); |
| 4441 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4442 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 4443 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 4444 | return I->second; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4447 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4448 | Record.push_back(GetDeclRef(D)); |
| 4449 | } |
| 4450 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4451 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4452 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
| 4453 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4454 | if (D == 0) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4455 | return 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4456 | } |
Douglas Gregor | 1c7946a | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4457 | |
| 4458 | // If D comes from an AST file, its declaration ID is already known and |
| 4459 | // fixed. |
| 4460 | if (D->isFromASTFile()) |
| 4461 | return D->getGlobalID(); |
| 4462 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4463 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4464 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4465 | if (ID == 0) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4466 | if (DoneWritingDeclsAndTypes) { |
| 4467 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 4468 | return 0; |
| 4469 | } |
| 4470 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4471 | // We haven't seen this declaration before. Give it a new ID and |
| 4472 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4473 | ID = NextDeclID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4474 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4477 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4478 | } |
| 4479 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4480 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4481 | if (D == 0) |
| 4482 | return 0; |
| 4483 | |
Douglas Gregor | 1c7946a | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4484 | // If D comes from an AST file, its declaration ID is already known and |
| 4485 | // fixed. |
| 4486 | if (D->isFromASTFile()) |
| 4487 | return D->getGlobalID(); |
| 4488 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4489 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 4490 | return DeclIDs[D]; |
| 4491 | } |
| 4492 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4493 | static inline bool compLocDecl(std::pair<unsigned, serialization::DeclID> L, |
| 4494 | std::pair<unsigned, serialization::DeclID> R) { |
| 4495 | return L.first < R.first; |
| 4496 | } |
| 4497 | |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4498 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4499 | assert(ID); |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4500 | assert(D); |
| 4501 | |
| 4502 | SourceLocation Loc = D->getLocation(); |
| 4503 | if (Loc.isInvalid()) |
| 4504 | return; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4505 | |
| 4506 | // We only keep track of the file-level declarations of each file. |
| 4507 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 4508 | return; |
Argyrios Kyrtzidis | 69015c2 | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 4509 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 4510 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | 8cceefa | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 4511 | if (isa<ParmVarDecl>(D)) |
| 4512 | return; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4513 | |
| 4514 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4515 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4516 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4517 | FileID FID; |
| 4518 | unsigned Offset; |
| 4519 | llvm::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4520 | if (FID.isInvalid()) |
| 4521 | return; |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4522 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4523 | |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4524 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4525 | if (!Info) |
| 4526 | Info = new DeclIDInFileInfo(); |
| 4527 | |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4528 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4529 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 4530 | |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4531 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4532 | Decls.push_back(LocDecl); |
| 4533 | return; |
| 4534 | } |
| 4535 | |
| 4536 | LocDeclIDsTy::iterator |
| 4537 | I = std::upper_bound(Decls.begin(), Decls.end(), LocDecl, compLocDecl); |
| 4538 | |
| 4539 | Decls.insert(I, LocDecl); |
| 4540 | } |
| 4541 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4542 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 4543 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4544 | Record.push_back(Name.getNameKind()); |
| 4545 | switch (Name.getNameKind()) { |
| 4546 | case DeclarationName::Identifier: |
| 4547 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 4548 | break; |
| 4549 | |
| 4550 | case DeclarationName::ObjCZeroArgSelector: |
| 4551 | case DeclarationName::ObjCOneArgSelector: |
| 4552 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4553 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4554 | break; |
| 4555 | |
| 4556 | case DeclarationName::CXXConstructorName: |
| 4557 | case DeclarationName::CXXDestructorName: |
| 4558 | case DeclarationName::CXXConversionFunctionName: |
| 4559 | AddTypeRef(Name.getCXXNameType(), Record); |
| 4560 | break; |
| 4561 | |
| 4562 | case DeclarationName::CXXOperatorName: |
| 4563 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 4564 | break; |
| 4565 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4566 | case DeclarationName::CXXLiteralOperatorName: |
| 4567 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 4568 | break; |
| 4569 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4570 | case DeclarationName::CXXUsingDirective: |
| 4571 | // No extra data to emit |
| 4572 | break; |
| 4573 | } |
| 4574 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4575 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4576 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4577 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4578 | switch (Name.getNameKind()) { |
| 4579 | case DeclarationName::CXXConstructorName: |
| 4580 | case DeclarationName::CXXDestructorName: |
| 4581 | case DeclarationName::CXXConversionFunctionName: |
| 4582 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 4583 | break; |
| 4584 | |
| 4585 | case DeclarationName::CXXOperatorName: |
| 4586 | AddSourceLocation( |
| 4587 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 4588 | Record); |
| 4589 | AddSourceLocation( |
| 4590 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 4591 | Record); |
| 4592 | break; |
| 4593 | |
| 4594 | case DeclarationName::CXXLiteralOperatorName: |
| 4595 | AddSourceLocation( |
| 4596 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 4597 | Record); |
| 4598 | break; |
| 4599 | |
| 4600 | case DeclarationName::Identifier: |
| 4601 | case DeclarationName::ObjCZeroArgSelector: |
| 4602 | case DeclarationName::ObjCOneArgSelector: |
| 4603 | case DeclarationName::ObjCMultiArgSelector: |
| 4604 | case DeclarationName::CXXUsingDirective: |
| 4605 | break; |
| 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4610 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4611 | AddDeclarationName(NameInfo.getName(), Record); |
| 4612 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 4613 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 4614 | } |
| 4615 | |
| 4616 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4617 | RecordDataImpl &Record) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4618 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4619 | Record.push_back(Info.NumTemplParamLists); |
| 4620 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 4621 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 4622 | } |
| 4623 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4624 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4625 | RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4626 | // 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] | 4627 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4628 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4629 | |
| 4630 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 4631 | while (NNS) { |
| 4632 | NestedNames.push_back(NNS); |
| 4633 | NNS = NNS->getPrefix(); |
| 4634 | } |
| 4635 | |
| 4636 | Record.push_back(NestedNames.size()); |
| 4637 | while(!NestedNames.empty()) { |
| 4638 | NNS = NestedNames.pop_back_val(); |
| 4639 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 4640 | Record.push_back(Kind); |
| 4641 | switch (Kind) { |
| 4642 | case NestedNameSpecifier::Identifier: |
| 4643 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 4644 | break; |
| 4645 | |
| 4646 | case NestedNameSpecifier::Namespace: |
| 4647 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 4648 | break; |
| 4649 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4650 | case NestedNameSpecifier::NamespaceAlias: |
| 4651 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 4652 | break; |
| 4653 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4654 | case NestedNameSpecifier::TypeSpec: |
| 4655 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4656 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 4657 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4658 | break; |
| 4659 | |
| 4660 | case NestedNameSpecifier::Global: |
| 4661 | // Don't need to write an associated value. |
| 4662 | break; |
| 4663 | } |
| 4664 | } |
| 4665 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4666 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4667 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 4668 | RecordDataImpl &Record) { |
| 4669 | // 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] | 4670 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4671 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4672 | |
| 4673 | // Push each of the nested-name-specifiers's onto a stack for |
| 4674 | // serialization in reverse order. |
| 4675 | while (NNS) { |
| 4676 | NestedNames.push_back(NNS); |
| 4677 | NNS = NNS.getPrefix(); |
| 4678 | } |
| 4679 | |
| 4680 | Record.push_back(NestedNames.size()); |
| 4681 | while(!NestedNames.empty()) { |
| 4682 | NNS = NestedNames.pop_back_val(); |
| 4683 | NestedNameSpecifier::SpecifierKind Kind |
| 4684 | = NNS.getNestedNameSpecifier()->getKind(); |
| 4685 | Record.push_back(Kind); |
| 4686 | switch (Kind) { |
| 4687 | case NestedNameSpecifier::Identifier: |
| 4688 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 4689 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4690 | break; |
| 4691 | |
| 4692 | case NestedNameSpecifier::Namespace: |
| 4693 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 4694 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4695 | break; |
| 4696 | |
| 4697 | case NestedNameSpecifier::NamespaceAlias: |
| 4698 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 4699 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4700 | break; |
| 4701 | |
| 4702 | case NestedNameSpecifier::TypeSpec: |
| 4703 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4704 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4705 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 4706 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4707 | break; |
| 4708 | |
| 4709 | case NestedNameSpecifier::Global: |
| 4710 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4711 | break; |
| 4712 | } |
| 4713 | } |
| 4714 | } |
| 4715 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4716 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4717 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4718 | Record.push_back(Kind); |
| 4719 | switch (Kind) { |
| 4720 | case TemplateName::Template: |
| 4721 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 4722 | break; |
| 4723 | |
| 4724 | case TemplateName::OverloadedTemplate: { |
| 4725 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 4726 | Record.push_back(OvT->size()); |
| 4727 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 4728 | I != E; ++I) |
| 4729 | AddDeclRef(*I, Record); |
| 4730 | break; |
| 4731 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4732 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4733 | case TemplateName::QualifiedTemplate: { |
| 4734 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 4735 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 4736 | Record.push_back(QualT->hasTemplateKeyword()); |
| 4737 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 4738 | break; |
| 4739 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4740 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4741 | case TemplateName::DependentTemplate: { |
| 4742 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 4743 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 4744 | Record.push_back(DepT->isIdentifier()); |
| 4745 | if (DepT->isIdentifier()) |
| 4746 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 4747 | else |
| 4748 | Record.push_back(DepT->getOperator()); |
| 4749 | break; |
| 4750 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4751 | |
| 4752 | case TemplateName::SubstTemplateTemplateParm: { |
| 4753 | SubstTemplateTemplateParmStorage *subst |
| 4754 | = Name.getAsSubstTemplateTemplateParm(); |
| 4755 | AddDeclRef(subst->getParameter(), Record); |
| 4756 | AddTemplateName(subst->getReplacement(), Record); |
| 4757 | break; |
| 4758 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4759 | |
| 4760 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4761 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 4762 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 4763 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 4764 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 4765 | break; |
| 4766 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4767 | } |
| 4768 | } |
| 4769 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4770 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4771 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4772 | Record.push_back(Arg.getKind()); |
| 4773 | switch (Arg.getKind()) { |
| 4774 | case TemplateArgument::Null: |
| 4775 | break; |
| 4776 | case TemplateArgument::Type: |
| 4777 | AddTypeRef(Arg.getAsType(), Record); |
| 4778 | break; |
| 4779 | case TemplateArgument::Declaration: |
| 4780 | AddDeclRef(Arg.getAsDecl(), Record); |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4781 | Record.push_back(Arg.isDeclForReferenceParam()); |
| 4782 | break; |
| 4783 | case TemplateArgument::NullPtr: |
| 4784 | AddTypeRef(Arg.getNullPtrType(), Record); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4785 | break; |
| 4786 | case TemplateArgument::Integral: |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 4787 | AddAPSInt(Arg.getAsIntegral(), Record); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4788 | AddTypeRef(Arg.getIntegralType(), Record); |
| 4789 | break; |
| 4790 | case TemplateArgument::Template: |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4791 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 4792 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4793 | case TemplateArgument::TemplateExpansion: |
| 4794 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4795 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4796 | Record.push_back(*NumExpansions + 1); |
| 4797 | else |
| 4798 | Record.push_back(0); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4799 | break; |
| 4800 | case TemplateArgument::Expression: |
| 4801 | AddStmt(Arg.getAsExpr()); |
| 4802 | break; |
| 4803 | case TemplateArgument::Pack: |
| 4804 | Record.push_back(Arg.pack_size()); |
| 4805 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 4806 | I != E; ++I) |
| 4807 | AddTemplateArgument(*I, Record); |
| 4808 | break; |
| 4809 | } |
| 4810 | } |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4811 | |
| 4812 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4813 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4814 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4815 | assert(TemplateParams && "No TemplateParams!"); |
| 4816 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 4817 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 4818 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 4819 | Record.push_back(TemplateParams->size()); |
| 4820 | for (TemplateParameterList::const_iterator |
| 4821 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 4822 | P != PEnd; ++P) |
| 4823 | AddDeclRef(*P, Record); |
| 4824 | } |
| 4825 | |
| 4826 | /// \brief Emit a template argument list. |
| 4827 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4828 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4829 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4830 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4831 | Record.push_back(TemplateArgs->size()); |
| 4832 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4833 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 4834 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4835 | |
| 4836 | |
| 4837 | void |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 4838 | ASTWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4839 | Record.push_back(Set.size()); |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 4840 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4841 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 4842 | AddDeclRef(I.getDecl(), Record); |
| 4843 | Record.push_back(I.getAccess()); |
| 4844 | } |
| 4845 | } |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4846 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4847 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4848 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4849 | Record.push_back(Base.isVirtual()); |
| 4850 | Record.push_back(Base.isBaseOfClass()); |
| 4851 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4852 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4853 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4854 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4855 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 4856 | : SourceLocation(), |
| 4857 | Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4858 | } |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4859 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4860 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 4861 | RecordData Record; |
| 4862 | for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { |
| 4863 | Record.clear(); |
| 4864 | |
| 4865 | // Record the offset of this base-specifier set. |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4866 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4867 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 4868 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 4869 | else { |
| 4870 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 4871 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 4872 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 4873 | } |
| 4874 | |
| 4875 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 4876 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 4877 | Record.push_back(BEnd - B); |
| 4878 | for (; B != BEnd; ++B) |
| 4879 | AddCXXBaseSpecifier(*B, Record); |
| 4880 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | acec34b | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 4881 | |
| 4882 | // Flush any expressions that were written as part of the base specifiers. |
| 4883 | FlushStmts(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | CXXBaseSpecifiersToWrite.clear(); |
| 4887 | } |
| 4888 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4889 | void ASTWriter::AddCXXCtorInitializers( |
| 4890 | const CXXCtorInitializer * const *CtorInitializers, |
| 4891 | unsigned NumCtorInitializers, |
| 4892 | RecordDataImpl &Record) { |
| 4893 | Record.push_back(NumCtorInitializers); |
| 4894 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 4895 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4896 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4897 | if (Init->isBaseInitializer()) { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4898 | Record.push_back(CTOR_INITIALIZER_BASE); |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4899 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4900 | Record.push_back(Init->isBaseVirtual()); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4901 | } else if (Init->isDelegatingInitializer()) { |
| 4902 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4903 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4904 | } else if (Init->isMemberInitializer()){ |
| 4905 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 4906 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4907 | } else { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4908 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 4909 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4910 | } |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4911 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4912 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 4913 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4914 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 4915 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 4916 | Record.push_back(Init->isWritten()); |
| 4917 | if (Init->isWritten()) { |
| 4918 | Record.push_back(Init->getSourceOrder()); |
| 4919 | } else { |
| 4920 | Record.push_back(Init->getNumArrayIndices()); |
| 4921 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 4922 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 4923 | } |
| 4924 | } |
| 4925 | } |
| 4926 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4927 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
| 4928 | assert(D->DefinitionData); |
| 4929 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4930 | Record.push_back(Data.IsLambda); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4931 | Record.push_back(Data.UserDeclaredConstructor); |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 4932 | Record.push_back(Data.UserDeclaredSpecialMembers); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4933 | Record.push_back(Data.Aggregate); |
| 4934 | Record.push_back(Data.PlainOldData); |
| 4935 | Record.push_back(Data.Empty); |
| 4936 | Record.push_back(Data.Polymorphic); |
| 4937 | Record.push_back(Data.Abstract); |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 4938 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 4939 | Record.push_back(Data.HasNoNonEmptyBases); |
| 4940 | Record.push_back(Data.HasPrivateFields); |
| 4941 | Record.push_back(Data.HasProtectedFields); |
| 4942 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 4943 | Record.push_back(Data.HasMutableFields); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4944 | Record.push_back(Data.HasOnlyCMembers); |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 4945 | Record.push_back(Data.HasInClassInitializer); |
Richard Smith | d5bc867 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 4946 | Record.push_back(Data.HasUninitializedReferenceMember); |
Richard Smith | bc2a35d | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 4947 | Record.push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 4948 | Record.push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 4949 | Record.push_back(Data.NeedOverloadResolutionForDestructor); |
| 4950 | Record.push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 4951 | Record.push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 4952 | Record.push_back(Data.DefaultedDestructorIsDeleted); |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 4953 | Record.push_back(Data.HasTrivialSpecialMembers); |
| 4954 | Record.push_back(Data.HasIrrelevantDestructor); |
Richard Smith | 6b8bc07 | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 4955 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4956 | Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4957 | Record.push_back(Data.HasConstexprDefaultConstructor); |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 4958 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4959 | Record.push_back(Data.ComputedVisibleConversions); |
Sean Hunt | cdee3fe | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 4960 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 4961 | Record.push_back(Data.DeclaredSpecialMembers); |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 4962 | Record.push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 4963 | Record.push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 4964 | Record.push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 4965 | Record.push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Sebastian Redl | 14c3633 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 4966 | Record.push_back(Data.FailedImplicitMoveConstructor); |
| 4967 | Record.push_back(Data.FailedImplicitMoveAssignment); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4968 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4969 | |
| 4970 | Record.push_back(Data.NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4971 | if (Data.NumBases > 0) |
| 4972 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 4973 | Record); |
| 4974 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4975 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 4976 | Record.push_back(Data.NumVBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4977 | if (Data.NumVBases > 0) |
| 4978 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 4979 | Record); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4980 | |
| 4981 | AddUnresolvedSet(Data.Conversions, Record); |
| 4982 | AddUnresolvedSet(Data.VisibleConversions, Record); |
| 4983 | // Data.Definition is the owning decl, no need to write it. |
| 4984 | AddDeclRef(Data.FirstFriend, Record); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4985 | |
| 4986 | // Add lambda-specific data. |
| 4987 | if (Data.IsLambda) { |
| 4988 | CXXRecordDecl::LambdaDefinitionData &Lambda = D->getLambdaData(); |
Douglas Gregor | f4b7de1 | 2012-02-21 19:11:17 +0000 | [diff] [blame] | 4989 | Record.push_back(Lambda.Dependent); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4990 | Record.push_back(Lambda.NumCaptures); |
| 4991 | Record.push_back(Lambda.NumExplicitCaptures); |
Douglas Gregor | 9e8c92a | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 4992 | Record.push_back(Lambda.ManglingNumber); |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 4993 | AddDeclRef(Lambda.ContextDecl, Record); |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 4994 | AddTypeSourceInfo(Lambda.MethodTyInfo, Record); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4995 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
| 4996 | LambdaExpr::Capture &Capture = Lambda.Captures[I]; |
| 4997 | AddSourceLocation(Capture.getLocation(), Record); |
| 4998 | Record.push_back(Capture.isImplicit()); |
| 4999 | Record.push_back(Capture.getCaptureKind()); // FIXME: stable! |
| 5000 | VarDecl *Var = Capture.capturesVariable()? Capture.getCapturedVar() : 0; |
| 5001 | AddDeclRef(Var, Record); |
| 5002 | AddSourceLocation(Capture.isPackExpansion()? Capture.getEllipsisLoc() |
| 5003 | : SourceLocation(), |
| 5004 | Record); |
| 5005 | } |
| 5006 | } |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5009 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5010 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5011 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5012 | assert(FirstDeclID == NextDeclID && |
| 5013 | FirstTypeID == NextTypeID && |
| 5014 | FirstIdentID == NextIdentID && |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5015 | FirstMacroID == NextMacroID && |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5016 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5017 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5018 | "Setting chain after writing has started."); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5019 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5020 | Chain = Reader; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5021 | |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5022 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5023 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5024 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5025 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5026 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5027 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5028 | NextDeclID = FirstDeclID; |
| 5029 | NextTypeID = FirstTypeID; |
| 5030 | NextIdentID = FirstIdentID; |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5031 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5032 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5033 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5036 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5037 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5038 | IdentID &StoredID = IdentifierIDs[II]; |
| 5039 | if (ID > StoredID) |
| 5040 | StoredID = ID; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5041 | } |
| 5042 | |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5043 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5044 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | 9317ab9 | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5045 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5046 | if (ID > StoredID) |
| 5047 | StoredID = ID; |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5048 | } |
| 5049 | |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5050 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5051 | // Always take the highest-numbered type index. This copes with an interesting |
| 5052 | // 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] | 5053 | // 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] | 5054 | // keep the higher-numbered entry so that we can properly write it out to |
| 5055 | // the AST file. |
| 5056 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 5057 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 5058 | StoredIdx = Idx; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5059 | } |
| 5060 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5061 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 2d1ece8 | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5062 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5063 | SelectorID &StoredID = SelectorIDs[S]; |
| 5064 | if (ID > StoredID) |
| 5065 | StoredID = ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5066 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5067 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5068 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5069 | MacroDefinition *MD) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5070 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5071 | MacroDefinitions[MD] = ID; |
| 5072 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5073 | |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5074 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 5075 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 5076 | SubmoduleIDs[Mod] = ID; |
| 5077 | } |
| 5078 | |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5079 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5080 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5081 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5082 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 5083 | // We are interested when a PCH decl is modified. |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5084 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5085 | // A forward reference was mutated into a definition. Rewrite it. |
| 5086 | // FIXME: This happens during template instantiation, should we |
| 5087 | // have created a new definition decl instead ? |
Argyrios Kyrtzidis | d3d0755 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 5088 | RewriteDecl(RD); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5089 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5090 | } |
| 5091 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5092 | |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5093 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5094 | assert(!WritingAST && "Already writing the AST!"); |
| 5095 | |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5096 | // TU and namespaces are handled elsewhere. |
| 5097 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 5098 | return; |
| 5099 | |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5100 | if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile())) |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5101 | return; // Not a source decl added to a DeclContext from PCH. |
| 5102 | |
Douglas Gregor | 5a04f9f | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5103 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5104 | AddUpdatedDeclContext(DC); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5105 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5106 | } |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5107 | |
| 5108 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5109 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5110 | assert(D->isImplicit()); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5111 | if (!(!D->isFromASTFile() && RD->isFromASTFile())) |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5112 | return; // Not a source member added to a class from PCH. |
| 5113 | if (!isa<CXXMethodDecl>(D)) |
| 5114 | return; // We are interested in lazily declared implicit methods. |
| 5115 | |
| 5116 | // A decl coming from PCH was modified. |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5117 | assert(RD->isCompleteDefinition()); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5118 | UpdateRecord &Record = DeclUpdates[RD]; |
| 5119 | Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5120 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5121 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5122 | |
| 5123 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 5124 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 5125 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5126 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 5127 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5128 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5129 | return; // Not a source specialization added to a template from PCH. |
| 5130 | |
| 5131 | UpdateRecord &Record = DeclUpdates[TD]; |
| 5132 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5133 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5134 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 5135 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 5136 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 5137 | const FunctionDecl *D) { |
| 5138 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5139 | assert(!WritingAST && "Already writing the AST!"); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 5140 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5141 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 5142 | return; // Not a source specialization added to a template from PCH. |
| 5143 | |
| 5144 | UpdateRecord &Record = DeclUpdates[TD]; |
| 5145 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5146 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 5147 | } |
| 5148 | |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5149 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5150 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5151 | if (!D->isFromASTFile()) |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5152 | return; // Declaration not imported from PCH. |
| 5153 | |
| 5154 | // Implicit decl from a PCH was defined. |
| 5155 | // FIXME: Should implicit definition be a separate FunctionDecl? |
| 5156 | RewriteDecl(D); |
| 5157 | } |
| 5158 | |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5159 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5160 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5161 | if (!D->isFromASTFile()) |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5162 | return; |
| 5163 | |
| 5164 | // Since the actual instantiation is delayed, this really means that we need |
| 5165 | // to update the instantiation location. |
| 5166 | UpdateRecord &Record = DeclUpdates[D]; |
| 5167 | Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); |
| 5168 | AddSourceLocation( |
| 5169 | D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); |
| 5170 | } |
| 5171 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5172 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 5173 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5174 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5175 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5176 | return; // Declaration not imported from PCH. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5177 | |
| 5178 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 5179 | ObjCClassesWithCategories.insert( |
| 5180 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5181 | } |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5182 | |
Argyrios Kyrtzidis | 1a43415 | 2011-11-12 21:07:52 +0000 | [diff] [blame] | 5183 | |
Argyrios Kyrtzidis | c80553e | 2011-11-14 04:52:29 +0000 | [diff] [blame] | 5184 | void ASTWriter::AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, |
| 5185 | const ObjCPropertyDecl *OrigProp, |
| 5186 | const ObjCCategoryDecl *ClassExt) { |
| 5187 | const ObjCInterfaceDecl *D = ClassExt->getClassInterface(); |
| 5188 | if (!D) |
| 5189 | return; |
| 5190 | |
| 5191 | assert(!WritingAST && "Already writing the AST!"); |
| 5192 | if (!D->isFromASTFile()) |
| 5193 | return; // Declaration not imported from PCH. |
| 5194 | |
| 5195 | RewriteDecl(D); |
| 5196 | } |