Sebastian Redl | d6522cf | 2010-08-18 23:56:31 +0000 | [diff] [blame] | 1 | //===--- ASTWriter.cpp - AST File Writer ----------------------------------===// |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 10 | // This file defines the ASTWriter class, which writes AST files. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sebastian Redl | 1914c6f | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTWriter.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
Douglas Gregor | ef84c4b | 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 | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclFriend.h" |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclLookups.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 22 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 23 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 24 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeLocVisitor.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 26 | #include "clang/Basic/DiagnosticOptions.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 27 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 28 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 29 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 30 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 31 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 32 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 33 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 34 | #include "clang/Basic/VersionTuple.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 35 | #include "clang/Lex/HeaderSearch.h" |
| 36 | #include "clang/Lex/HeaderSearchOptions.h" |
| 37 | #include "clang/Lex/MacroInfo.h" |
| 38 | #include "clang/Lex/PreprocessingRecord.h" |
| 39 | #include "clang/Lex/Preprocessor.h" |
| 40 | #include "clang/Lex/PreprocessorOptions.h" |
| 41 | #include "clang/Sema/IdentifierResolver.h" |
| 42 | #include "clang/Sema/Sema.h" |
| 43 | #include "clang/Serialization/ASTReader.h" |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 44 | #include "llvm/ADT/APFloat.h" |
| 45 | #include "llvm/ADT/APInt.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/Hashing.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | #include "llvm/Bitcode/BitstreamWriter.h" |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 49 | #include "llvm/Support/EndianStream.h" |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 50 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 51 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 52 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 53 | #include "llvm/Support/Path.h" |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 54 | #include "llvm/Support/Process.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 55 | #include <algorithm> |
Chris Lattner | 225dd6c | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 56 | #include <cstdio> |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 57 | #include <string.h> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 58 | #include <utility> |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 59 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 60 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 61 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 62 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 63 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 64 | if (v.empty()) return StringRef(); |
| 65 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 66 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 67 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 68 | |
| 69 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 70 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 71 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 72 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 75 | //===----------------------------------------------------------------------===// |
| 76 | // Type serialization |
| 77 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 78 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 79 | namespace { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 80 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 81 | ASTWriter &Writer; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 82 | ASTWriter::RecordDataImpl &Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 83 | |
| 84 | public: |
| 85 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 86 | TypeCode Code; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 87 | /// \brief Abbreviation to use for the record, if any. |
| 88 | unsigned AbbrevToUse; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 89 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 90 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 91 | : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 92 | |
| 93 | void VisitArrayType(const ArrayType *T); |
| 94 | void VisitFunctionType(const FunctionType *T); |
| 95 | void VisitTagType(const TagType *T); |
| 96 | |
| 97 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 98 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 99 | #include "clang/AST/TypeNodes.def" |
| 100 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 101 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 102 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 103 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 104 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 107 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 108 | Writer.AddTypeRef(T->getElementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 109 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 112 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 113 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 114 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 117 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
| 118 | Writer.AddTypeRef(T->getOriginalType(), Record); |
| 119 | Code = TYPE_DECAYED; |
| 120 | } |
| 121 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 122 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
| 123 | Writer.AddTypeRef(T->getOriginalType(), Record); |
| 124 | Writer.AddTypeRef(T->getAdjustedType(), Record); |
| 125 | Code = TYPE_ADJUSTED; |
| 126 | } |
| 127 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 128 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 130 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 133 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 134 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
| 135 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 136 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 139 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 140 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 141 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 144 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 146 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 147 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 150 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 151 | Writer.AddTypeRef(T->getElementType(), Record); |
| 152 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 153 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 156 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 157 | VisitArrayType(T); |
| 158 | Writer.AddAPInt(T->getSize(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 159 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 162 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 163 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 164 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 167 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 168 | VisitArrayType(T); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 169 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 170 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 171 | Writer.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 172 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 175 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 176 | Writer.AddTypeRef(T->getElementType(), Record); |
| 177 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 178 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 179 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 182 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 183 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 184 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 187 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 188 | Writer.AddTypeRef(T->getReturnType(), Record); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 189 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 190 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 191 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 192 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 193 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 194 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 195 | Record.push_back(C.getProducesResult()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 196 | |
| 197 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 198 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 201 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 202 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 203 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 206 | static void addExceptionSpec(ASTWriter &Writer, const FunctionProtoType *T, |
| 207 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 208 | Record.push_back(T->getExceptionSpecType()); |
| 209 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 210 | Record.push_back(T->getNumExceptions()); |
| 211 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 212 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 213 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 214 | Writer.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 215 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
| 216 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
| 217 | Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 218 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
| 219 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 220 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 224 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 225 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 226 | Record.push_back(T->isVariadic()); |
| 227 | Record.push_back(T->hasTrailingReturn()); |
| 228 | Record.push_back(T->getTypeQuals()); |
| 229 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
| 230 | addExceptionSpec(Writer, T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 231 | |
| 232 | Record.push_back(T->getNumParams()); |
| 233 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 234 | Writer.AddTypeRef(T->getParamType(I), Record); |
| 235 | |
| 236 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
| 237 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None) |
| 238 | AbbrevToUse = 0; |
| 239 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 240 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 243 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 244 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 245 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 246 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 247 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 248 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 249 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 250 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 251 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 252 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 255 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 256 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 257 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 260 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 261 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 262 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 265 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 266 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 267 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 268 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 271 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 272 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 273 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 274 | Record.push_back(T->getUTTKind()); |
| 275 | Code = TYPE_UNARY_TRANSFORM; |
| 276 | } |
| 277 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 278 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 279 | Writer.AddTypeRef(T->getDeducedType(), Record); |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 280 | Record.push_back(T->isDecltypeAuto()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 281 | if (T->getDeducedType().isNull()) |
| 282 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 283 | Code = TYPE_AUTO; |
| 284 | } |
| 285 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 286 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 287 | Record.push_back(T->isDependentType()); |
Douglas Gregor | f3bccd7 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 288 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 290 | "Cannot serialize in the middle of a type definition"); |
| 291 | } |
| 292 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 293 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 294 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 295 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 298 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 299 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 300 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 301 | } |
| 302 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 303 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 304 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 305 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 306 | Record.push_back(T->getAttrKind()); |
| 307 | Code = TYPE_ATTRIBUTED; |
| 308 | } |
| 309 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 311 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 312 | const SubstTemplateTypeParmType *T) { |
| 313 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 314 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 315 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 319 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 320 | const SubstTemplateTypeParmPackType *T) { |
| 321 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 322 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 323 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 324 | } |
| 325 | |
| 326 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 327 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 328 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 329 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 330 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 331 | Record.push_back(T->getNumArgs()); |
| 332 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 333 | ArgI != ArgE; ++ArgI) |
| 334 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 335 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 336 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 337 | : T->getCanonicalTypeInternal(), |
| 338 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 339 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 343 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 344 | VisitArrayType(T); |
| 345 | Writer.AddStmt(T->getSizeExpr()); |
| 346 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 347 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 351 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 352 | const DependentSizedExtVectorType *T) { |
| 353 | // FIXME: Serialize this type (C++ only) |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 354 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 358 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 359 | Record.push_back(T->getDepth()); |
| 360 | Record.push_back(T->getIndex()); |
| 361 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 362 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 363 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 367 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 368 | Record.push_back(T->getKeyword()); |
| 369 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 370 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 371 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 372 | : T->getCanonicalTypeInternal(), |
| 373 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 374 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 378 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 379 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 380 | Record.push_back(T->getKeyword()); |
| 381 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 382 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 383 | Record.push_back(T->getNumArgs()); |
| 384 | for (DependentTemplateSpecializationType::iterator |
| 385 | I = T->begin(), E = T->end(); I != E; ++I) |
| 386 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 387 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 390 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 391 | Writer.AddTypeRef(T->getPattern(), Record); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 392 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 393 | Record.push_back(*NumExpansions + 1); |
| 394 | else |
| 395 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 396 | Code = TYPE_PACK_EXPANSION; |
| 397 | } |
| 398 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 399 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 400 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 401 | Code = TYPE_PAREN; |
| 402 | } |
| 403 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 404 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 405 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 406 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 407 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 408 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 411 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Douglas Gregor | 9f21889 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 412 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
John McCall | 2408e32 | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 413 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 414 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 417 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | f3bccd7 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 418 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 419 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 422 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 423 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 424 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 425 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 426 | Writer.AddTypeRef(TypeArg, Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 427 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 428 | for (const auto *I : T->quals()) |
| 429 | Writer.AddDeclRef(I, Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 430 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 433 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 434 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 436 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 439 | void |
| 440 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
| 441 | Writer.AddTypeRef(T->getValueType(), Record); |
| 442 | Code = TYPE_ATOMIC; |
| 443 | } |
| 444 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 445 | namespace { |
| 446 | |
| 447 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 448 | ASTWriter &Writer; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 449 | ASTWriter::RecordDataImpl &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 450 | |
| 451 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 452 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 453 | : Writer(Writer), Record(Record) { } |
| 454 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 455 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 456 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 457 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 458 | #include "clang/AST/TypeLocNodes.def" |
| 459 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 460 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 461 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 462 | }; |
| 463 | |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 464 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 465 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 466 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 467 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 468 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 469 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 470 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 471 | if (TL.needsExtraLocalData()) { |
| 472 | Record.push_back(TL.getWrittenTypeSpec()); |
| 473 | Record.push_back(TL.getWrittenSignSpec()); |
| 474 | Record.push_back(TL.getWrittenWidthSpec()); |
| 475 | Record.push_back(TL.hasModeAttr()); |
| 476 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 477 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 478 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 479 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 480 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 481 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 482 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 483 | } |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 484 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 485 | // nothing to do |
| 486 | } |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 487 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 488 | // nothing to do |
| 489 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 490 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 491 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 492 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 493 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 494 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 495 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 496 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 497 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 498 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 499 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 500 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 501 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 502 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 503 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 504 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 505 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 506 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 507 | if (TL.getSizeExpr()) |
| 508 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 509 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 510 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 511 | VisitArrayTypeLoc(TL); |
| 512 | } |
| 513 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 514 | VisitArrayTypeLoc(TL); |
| 515 | } |
| 516 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 517 | VisitArrayTypeLoc(TL); |
| 518 | } |
| 519 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 520 | DependentSizedArrayTypeLoc TL) { |
| 521 | VisitArrayTypeLoc(TL); |
| 522 | } |
| 523 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 524 | DependentSizedExtVectorTypeLoc TL) { |
| 525 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 526 | } |
| 527 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 528 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 529 | } |
| 530 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 531 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 532 | } |
| 533 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 534 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 535 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 536 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 537 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 538 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
| 539 | Writer.AddDeclRef(TL.getParam(i), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 540 | } |
| 541 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 542 | VisitFunctionTypeLoc(TL); |
| 543 | } |
| 544 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 545 | VisitFunctionTypeLoc(TL); |
| 546 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 547 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 548 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 549 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 550 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 551 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 552 | } |
| 553 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 554 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 555 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 556 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 557 | } |
| 558 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 559 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 560 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 561 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 562 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 563 | } |
| 564 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 565 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 566 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 567 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 568 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 569 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 570 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 571 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 572 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 573 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 574 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 575 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 576 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 577 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 578 | } |
| 579 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 580 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 581 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 582 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 583 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 584 | if (TL.hasAttrOperand()) { |
| 585 | SourceRange range = TL.getAttrOperandParensRange(); |
| 586 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 587 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 588 | } |
| 589 | if (TL.hasAttrExprOperand()) { |
| 590 | Expr *operand = TL.getAttrExprOperand(); |
| 591 | Record.push_back(operand ? 1 : 0); |
| 592 | if (operand) Writer.AddStmt(operand); |
| 593 | } else if (TL.hasAttrEnumOperand()) { |
| 594 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 595 | } |
| 596 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 597 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 598 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 599 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 600 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 601 | SubstTemplateTypeParmTypeLoc TL) { |
| 602 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 603 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 604 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 605 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 606 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 607 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 608 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 609 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 610 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 611 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 612 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 613 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 614 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 615 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 616 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 617 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 618 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 619 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 620 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 621 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 622 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 623 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 624 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 625 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 626 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 627 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 628 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 629 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 630 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 631 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 632 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 633 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 634 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 635 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 636 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 637 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 638 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 639 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 640 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 641 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 642 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 643 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 644 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 645 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 646 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 647 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 648 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 649 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 650 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 651 | } |
| 652 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 653 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 654 | Writer.AddSourceLocation(TL.getTypeArgsLAngleLoc(), Record); |
| 655 | Writer.AddSourceLocation(TL.getTypeArgsRAngleLoc(), Record); |
| 656 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
| 657 | Writer.AddTypeSourceInfo(TL.getTypeArgTInfo(i), Record); |
| 658 | Writer.AddSourceLocation(TL.getProtocolLAngleLoc(), Record); |
| 659 | Writer.AddSourceLocation(TL.getProtocolRAngleLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 660 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 661 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 662 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 663 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 664 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 665 | } |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 666 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 667 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 668 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 669 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 670 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 671 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 672 | void ASTWriter::WriteTypeAbbrevs() { |
| 673 | using namespace llvm; |
| 674 | |
| 675 | BitCodeAbbrev *Abv; |
| 676 | |
| 677 | // Abbreviation for TYPE_EXT_QUAL |
| 678 | Abv = new BitCodeAbbrev(); |
| 679 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 680 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 681 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
| 682 | TypeExtQualAbbrev = Stream.EmitAbbrev(Abv); |
| 683 | |
| 684 | // Abbreviation for TYPE_FUNCTION_PROTO |
| 685 | Abv = new BitCodeAbbrev(); |
| 686 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 687 | // FunctionType |
| 688 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 689 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 690 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 691 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 692 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 693 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
| 694 | // FunctionProtoType |
| 695 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 696 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 697 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 698 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 699 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 700 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 701 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 702 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
| 703 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(Abv); |
| 704 | } |
| 705 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 706 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 707 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 708 | //===----------------------------------------------------------------------===// |
| 709 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 710 | static void EmitBlockID(unsigned ID, const char *Name, |
| 711 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 712 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 713 | Record.clear(); |
| 714 | Record.push_back(ID); |
| 715 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 716 | |
| 717 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 718 | if (!Name || Name[0] == 0) |
| 719 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 720 | Record.clear(); |
| 721 | while (*Name) |
| 722 | Record.push_back(*Name++); |
| 723 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 724 | } |
| 725 | |
| 726 | static void EmitRecordID(unsigned ID, const char *Name, |
| 727 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 728 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 729 | Record.clear(); |
| 730 | Record.push_back(ID); |
| 731 | while (*Name) |
| 732 | Record.push_back(*Name++); |
| 733 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 737 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 738 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 739 | RECORD(STMT_STOP); |
| 740 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 741 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 742 | RECORD(STMT_NULL); |
| 743 | RECORD(STMT_COMPOUND); |
| 744 | RECORD(STMT_CASE); |
| 745 | RECORD(STMT_DEFAULT); |
| 746 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 747 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 748 | RECORD(STMT_IF); |
| 749 | RECORD(STMT_SWITCH); |
| 750 | RECORD(STMT_WHILE); |
| 751 | RECORD(STMT_DO); |
| 752 | RECORD(STMT_FOR); |
| 753 | RECORD(STMT_GOTO); |
| 754 | RECORD(STMT_INDIRECT_GOTO); |
| 755 | RECORD(STMT_CONTINUE); |
| 756 | RECORD(STMT_BREAK); |
| 757 | RECORD(STMT_RETURN); |
| 758 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 759 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 760 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 761 | RECORD(EXPR_PREDEFINED); |
| 762 | RECORD(EXPR_DECL_REF); |
| 763 | RECORD(EXPR_INTEGER_LITERAL); |
| 764 | RECORD(EXPR_FLOATING_LITERAL); |
| 765 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 766 | RECORD(EXPR_STRING_LITERAL); |
| 767 | RECORD(EXPR_CHARACTER_LITERAL); |
| 768 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 769 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 770 | RECORD(EXPR_UNARY_OPERATOR); |
| 771 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 772 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 773 | RECORD(EXPR_CALL); |
| 774 | RECORD(EXPR_MEMBER); |
| 775 | RECORD(EXPR_BINARY_OPERATOR); |
| 776 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 777 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 778 | RECORD(EXPR_IMPLICIT_CAST); |
| 779 | RECORD(EXPR_CSTYLE_CAST); |
| 780 | RECORD(EXPR_COMPOUND_LITERAL); |
| 781 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 782 | RECORD(EXPR_INIT_LIST); |
| 783 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 784 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 785 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 786 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 787 | RECORD(EXPR_VA_ARG); |
| 788 | RECORD(EXPR_ADDR_LABEL); |
| 789 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 790 | RECORD(EXPR_CHOOSE); |
| 791 | RECORD(EXPR_GNU_NULL); |
| 792 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 793 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 794 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 795 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 796 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 797 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 798 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 799 | RECORD(EXPR_OBJC_ENCODE); |
| 800 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 801 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 802 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 803 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 804 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 805 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 806 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 807 | RECORD(STMT_OBJC_CATCH); |
| 808 | RECORD(STMT_OBJC_FINALLY); |
| 809 | RECORD(STMT_OBJC_AT_TRY); |
| 810 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 811 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 812 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 813 | RECORD(STMT_CXX_CATCH); |
| 814 | RECORD(STMT_CXX_TRY); |
| 815 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 816 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 817 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 818 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 819 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 820 | RECORD(EXPR_CXX_STATIC_CAST); |
| 821 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 822 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 823 | RECORD(EXPR_CXX_CONST_CAST); |
| 824 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 825 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 826 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 827 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 828 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 829 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 830 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 831 | RECORD(EXPR_CXX_THIS); |
| 832 | RECORD(EXPR_CXX_THROW); |
| 833 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 834 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 835 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 836 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 837 | RECORD(EXPR_CXX_NEW); |
| 838 | RECORD(EXPR_CXX_DELETE); |
| 839 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 840 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 841 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 842 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 843 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 844 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 845 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 846 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 847 | RECORD(EXPR_CXX_NOEXCEPT); |
| 848 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 849 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 850 | RECORD(EXPR_TYPE_TRAIT); |
| 851 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 852 | RECORD(EXPR_PACK_EXPANSION); |
| 853 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 854 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 855 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 856 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 857 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 858 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 859 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 860 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 861 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 862 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 863 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 864 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 865 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 866 | RecordData Record; |
| 867 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 868 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 869 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 870 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 871 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 872 | // Control Block. |
| 873 | BLOCK(CONTROL_BLOCK); |
| 874 | RECORD(METADATA); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 875 | RECORD(SIGNATURE); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 876 | RECORD(MODULE_NAME); |
| 877 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 878 | RECORD(IMPORTS); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 879 | RECORD(KNOWN_MODULE_FILES); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 880 | RECORD(LANGUAGE_OPTIONS); |
| 881 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 882 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 883 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 884 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 885 | RECORD(INPUT_FILE_OFFSETS); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 886 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 887 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 888 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 889 | RECORD(PREPROCESSOR_OPTIONS); |
| 890 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 891 | BLOCK(INPUT_FILES_BLOCK); |
| 892 | RECORD(INPUT_FILE); |
| 893 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 894 | // AST Top-Level Block. |
| 895 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 896 | RECORD(TYPE_OFFSET); |
| 897 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 898 | RECORD(IDENTIFIER_OFFSET); |
| 899 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 900 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 901 | RECORD(SPECIAL_TYPES); |
| 902 | RECORD(STATISTICS); |
| 903 | RECORD(TENTATIVE_DEFINITIONS); |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 904 | RECORD(UNUSED_FILESCOPED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 905 | RECORD(SELECTOR_OFFSETS); |
| 906 | RECORD(METHOD_POOL); |
| 907 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 908 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 909 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 910 | RECORD(EXT_VECTOR_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 911 | RECORD(PPD_ENTITIES_OFFSETS); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 912 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 913 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 914 | RECORD(LOCAL_REDECLARATIONS_MAP); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 915 | RECORD(SEMA_DECL_REFS); |
| 916 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 917 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 918 | RECORD(DECL_REPLACEMENTS); |
| 919 | RECORD(UPDATE_VISIBLE); |
| 920 | RECORD(DECL_UPDATE_OFFSETS); |
| 921 | RECORD(DECL_UPDATES); |
| 922 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 923 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 924 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 925 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 926 | RECORD(FP_PRAGMA_OPTIONS); |
| 927 | RECORD(OPENCL_EXTENSIONS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 928 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 929 | RECORD(KNOWN_NAMESPACES); |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 930 | RECORD(UNDEFINED_BUT_USED); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 931 | RECORD(MODULE_OFFSET_MAP); |
| 932 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 933 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 934 | RECORD(FILE_SORTED_DECLS); |
| 935 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 936 | RECORD(LOCAL_REDECLARATIONS); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 937 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 938 | RECORD(MACRO_OFFSET); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 939 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 940 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 941 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 942 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 943 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 944 | RECORD(SM_SLOC_FILE_ENTRY); |
| 945 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 946 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 947 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 949 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 950 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 951 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 952 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 953 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 954 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 955 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 956 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 957 | // Decls and Types block. |
| 958 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 959 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 960 | RECORD(TYPE_COMPLEX); |
| 961 | RECORD(TYPE_POINTER); |
| 962 | RECORD(TYPE_BLOCK_POINTER); |
| 963 | RECORD(TYPE_LVALUE_REFERENCE); |
| 964 | RECORD(TYPE_RVALUE_REFERENCE); |
| 965 | RECORD(TYPE_MEMBER_POINTER); |
| 966 | RECORD(TYPE_CONSTANT_ARRAY); |
| 967 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 968 | RECORD(TYPE_VARIABLE_ARRAY); |
| 969 | RECORD(TYPE_VECTOR); |
| 970 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 971 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 972 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 973 | RECORD(TYPE_TYPEDEF); |
| 974 | RECORD(TYPE_TYPEOF_EXPR); |
| 975 | RECORD(TYPE_TYPEOF); |
| 976 | RECORD(TYPE_RECORD); |
| 977 | RECORD(TYPE_ENUM); |
| 978 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 979 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 980 | RECORD(TYPE_DECLTYPE); |
| 981 | RECORD(TYPE_ELABORATED); |
| 982 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 983 | RECORD(TYPE_UNRESOLVED_USING); |
| 984 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 985 | RECORD(TYPE_OBJC_OBJECT); |
| 986 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 987 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 988 | RECORD(TYPE_DEPENDENT_NAME); |
| 989 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 990 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 991 | RECORD(TYPE_PAREN); |
| 992 | RECORD(TYPE_PACK_EXPANSION); |
| 993 | RECORD(TYPE_ATTRIBUTED); |
| 994 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 995 | RECORD(TYPE_AUTO); |
| 996 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 997 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 998 | RECORD(TYPE_DECAYED); |
| 999 | RECORD(TYPE_ADJUSTED); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1000 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1001 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1002 | RECORD(DECL_ENUM); |
| 1003 | RECORD(DECL_RECORD); |
| 1004 | RECORD(DECL_ENUM_CONSTANT); |
| 1005 | RECORD(DECL_FUNCTION); |
| 1006 | RECORD(DECL_OBJC_METHOD); |
| 1007 | RECORD(DECL_OBJC_INTERFACE); |
| 1008 | RECORD(DECL_OBJC_PROTOCOL); |
| 1009 | RECORD(DECL_OBJC_IVAR); |
| 1010 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1011 | RECORD(DECL_OBJC_CATEGORY); |
| 1012 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1013 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1014 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1015 | RECORD(DECL_OBJC_PROPERTY); |
| 1016 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1017 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1018 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1019 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1020 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1021 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1022 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1023 | RECORD(DECL_BLOCK); |
| 1024 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1025 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1026 | RECORD(DECL_NAMESPACE); |
| 1027 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1028 | RECORD(DECL_USING); |
| 1029 | RECORD(DECL_USING_SHADOW); |
| 1030 | RECORD(DECL_USING_DIRECTIVE); |
| 1031 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1032 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1033 | RECORD(DECL_LINKAGE_SPEC); |
| 1034 | RECORD(DECL_CXX_RECORD); |
| 1035 | RECORD(DECL_CXX_METHOD); |
| 1036 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 1037 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1038 | RECORD(DECL_CXX_CONVERSION); |
| 1039 | RECORD(DECL_ACCESS_SPEC); |
| 1040 | RECORD(DECL_FRIEND); |
| 1041 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1042 | RECORD(DECL_CLASS_TEMPLATE); |
| 1043 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1044 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1045 | RECORD(DECL_VAR_TEMPLATE); |
| 1046 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1047 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1048 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1049 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1050 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1051 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 1052 | RECORD(DECL_STATIC_ASSERT); |
| 1053 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 1054 | RECORD(DECL_INDIRECTFIELD); |
| 1055 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 1056 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1057 | // Statements and Exprs can occur in the Decls and Types block. |
| 1058 | AddStmtsExprs(Stream, Record); |
| 1059 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1060 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1061 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1062 | RECORD(PPD_MACRO_DEFINITION); |
| 1063 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 1064 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1065 | #undef RECORD |
| 1066 | #undef BLOCK |
| 1067 | Stream.ExitBlock(); |
| 1068 | } |
| 1069 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1070 | /// \brief Prepares a path for being written to an AST file by converting it |
| 1071 | /// to an absolute path and removing nested './'s. |
| 1072 | /// |
| 1073 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1074 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1075 | SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1076 | bool Changed = false; |
| 1077 | |
| 1078 | if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size()))) { |
| 1079 | llvm::sys::fs::make_absolute(Path); |
| 1080 | Changed = true; |
| 1081 | } |
| 1082 | |
| 1083 | return Changed | FileMgr.removeDotPaths(Path); |
| 1084 | } |
| 1085 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1086 | /// \brief Adjusts the given filename to only write out the portion of the |
| 1087 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1089 | /// \param Filename the file name to adjust. |
| 1090 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1091 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1092 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1093 | /// |
| 1094 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1095 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1097 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1098 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1099 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1100 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1101 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1103 | // Verify that the filename and the system root have the same prefix. |
| 1104 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1105 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1106 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1107 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1109 | // We hit the end of the filename before we hit the end of the system root. |
| 1110 | if (!Filename[Pos]) |
| 1111 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1113 | // If there's not a path separator at the end of the base directory nor |
| 1114 | // immediately after it, then this isn't within the base directory. |
| 1115 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1116 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1117 | return Filename; |
| 1118 | } else { |
| 1119 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1120 | // We distinguish relative paths from absolute paths by the |
| 1121 | // absence of '/' at the beginning of relative paths. |
| 1122 | // |
| 1123 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1124 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1125 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1126 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1127 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1128 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1130 | return Filename + Pos; |
| 1131 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1132 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1133 | static ASTFileSignature getSignature() { |
| 1134 | while (1) { |
| 1135 | if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) |
| 1136 | return S; |
| 1137 | // Rely on GetRandomNumber to eventually return non-zero... |
| 1138 | } |
| 1139 | } |
| 1140 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1141 | /// \brief Write the control block. |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1142 | void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, |
| 1143 | StringRef isysroot, |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1144 | const std::string &OutputFile) { |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1145 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1146 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
| 1147 | RecordData Record; |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1148 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1149 | // Metadata |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1150 | BitCodeAbbrev *MetadataAbbrev = new BitCodeAbbrev(); |
| 1151 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1152 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1153 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1154 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1155 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1156 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
| 1157 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1158 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1159 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
| 1160 | Record.push_back(METADATA); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1161 | Record.push_back(VERSION_MAJOR); |
| 1162 | Record.push_back(VERSION_MINOR); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1163 | Record.push_back(CLANG_VERSION_MAJOR); |
| 1164 | Record.push_back(CLANG_VERSION_MINOR); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1165 | assert((!WritingModule || isysroot.empty()) && |
| 1166 | "writing module as a relocatable PCH?"); |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1167 | Record.push_back(!isysroot.empty()); |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 1168 | Record.push_back(ASTHasCompilerErrors); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1169 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1170 | getClangFullRepositoryVersion()); |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1171 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1172 | if (WritingModule) { |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1173 | // For implicit modules we output a signature that we can use to ensure |
| 1174 | // duplicate module builds don't collide in the cache as their output order |
| 1175 | // is non-deterministic. |
| 1176 | // FIXME: Remove this when output is deterministic. |
| 1177 | if (Context.getLangOpts().ImplicitModules) { |
| 1178 | Record.clear(); |
| 1179 | Record.push_back(getSignature()); |
| 1180 | Stream.EmitRecord(SIGNATURE, Record); |
| 1181 | } |
| 1182 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1183 | // Module name |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1184 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1185 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1186 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1187 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1188 | RecordData Record; |
| 1189 | Record.push_back(MODULE_NAME); |
| 1190 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1191 | } |
| 1192 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1193 | if (WritingModule && WritingModule->Directory) { |
| 1194 | // Module directory. |
| 1195 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1196 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1197 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
| 1198 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1199 | RecordData Record; |
| 1200 | Record.push_back(MODULE_DIRECTORY); |
| 1201 | |
| 1202 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1203 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1204 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1205 | |
| 1206 | // Write out all other paths relative to the base directory if possible. |
| 1207 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1208 | } else if (!isysroot.empty()) { |
| 1209 | // Write out paths relative to the sysroot if possible. |
| 1210 | BaseDirectory = isysroot; |
| 1211 | } |
| 1212 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1213 | // Module map file |
| 1214 | if (WritingModule) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1215 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1216 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1217 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 1218 | |
| 1219 | // Primary module map file. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1220 | AddPath(Map.getModuleMapFileForUniquing(WritingModule)->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1221 | |
| 1222 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1223 | if (auto *AdditionalModMaps = |
| 1224 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1225 | Record.push_back(AdditionalModMaps->size()); |
| 1226 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1227 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1228 | } else { |
| 1229 | Record.push_back(0); |
| 1230 | } |
| 1231 | |
| 1232 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1235 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1236 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1237 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1238 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1239 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1240 | for (auto *M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1241 | // Skip modules that weren't directly imported. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1242 | if (!M->isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1243 | continue; |
| 1244 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1245 | Record.push_back((unsigned)M->Kind); // FIXME: Stable encoding |
| 1246 | AddSourceLocation(M->ImportLoc, Record); |
| 1247 | Record.push_back(M->File->getSize()); |
| 1248 | Record.push_back(M->File->getModificationTime()); |
| 1249 | Record.push_back(M->Signature); |
| 1250 | AddPath(M->FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1251 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1252 | Stream.EmitRecord(IMPORTS, Record); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1253 | |
| 1254 | // Also emit a list of known module files that were not imported, |
| 1255 | // but are made available by this module. |
| 1256 | // FIXME: Should we also include a signature here? |
| 1257 | Record.clear(); |
| 1258 | for (auto *E : Mgr.getAdditionalKnownModuleFiles()) |
| 1259 | AddPath(E->getName(), Record); |
| 1260 | if (!Record.empty()) |
| 1261 | Stream.EmitRecord(KNOWN_MODULE_FILES, Record); |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1262 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1264 | // Language options. |
| 1265 | Record.clear(); |
| 1266 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1267 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1268 | Record.push_back(LangOpts.Name); |
| 1269 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1270 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1271 | #include "clang/Basic/LangOptions.def" |
| 1272 | #define SANITIZER(NAME, ID) \ |
| 1273 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1274 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1275 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1276 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1277 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1278 | AddString(Feature, Record); |
| 1279 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1280 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1281 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1282 | |
| 1283 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1284 | |
| 1285 | // Comment options. |
| 1286 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
| 1287 | for (CommentOptions::BlockCommandNamesTy::const_iterator |
| 1288 | I = LangOpts.CommentOpts.BlockCommandNames.begin(), |
| 1289 | IEnd = LangOpts.CommentOpts.BlockCommandNames.end(); |
| 1290 | I != IEnd; ++I) { |
| 1291 | AddString(*I, Record); |
| 1292 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1293 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1295 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1296 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1297 | // Target options. |
| 1298 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1299 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1300 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1301 | AddString(TargetOpts.Triple, Record); |
| 1302 | AddString(TargetOpts.CPU, Record); |
| 1303 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1304 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1305 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1306 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1307 | } |
| 1308 | Record.push_back(TargetOpts.Features.size()); |
| 1309 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1310 | AddString(TargetOpts.Features[I], Record); |
| 1311 | } |
| 1312 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1313 | |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1314 | // Diagnostic options. |
| 1315 | Record.clear(); |
| 1316 | const DiagnosticOptions &DiagOpts |
| 1317 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1318 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1319 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1320 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1321 | #include "clang/Basic/DiagnosticOptions.def" |
| 1322 | Record.push_back(DiagOpts.Warnings.size()); |
| 1323 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1324 | AddString(DiagOpts.Warnings[I], Record); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 1325 | Record.push_back(DiagOpts.Remarks.size()); |
| 1326 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1327 | AddString(DiagOpts.Remarks[I], Record); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1328 | // Note: we don't serialize the log or serialization file names, because they |
| 1329 | // are generally transient files and will almost always be overridden. |
| 1330 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1331 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1332 | // File system options. |
| 1333 | Record.clear(); |
| 1334 | const FileSystemOptions &FSOpts |
| 1335 | = Context.getSourceManager().getFileManager().getFileSystemOptions(); |
| 1336 | AddString(FSOpts.WorkingDir, Record); |
| 1337 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1338 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1339 | // Header search options. |
| 1340 | Record.clear(); |
| 1341 | const HeaderSearchOptions &HSOpts |
| 1342 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1343 | AddString(HSOpts.Sysroot, Record); |
| 1344 | |
| 1345 | // Include entries. |
| 1346 | Record.push_back(HSOpts.UserEntries.size()); |
| 1347 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1348 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1349 | AddString(Entry.Path, Record); |
| 1350 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1351 | Record.push_back(Entry.IsFramework); |
| 1352 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | // System header prefixes. |
| 1356 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1357 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1358 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1359 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1360 | } |
| 1361 | |
| 1362 | AddString(HSOpts.ResourceDir, Record); |
| 1363 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1364 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1365 | Record.push_back(HSOpts.DisableModuleHash); |
| 1366 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1367 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1368 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1369 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1370 | // Write out the specific module cache path that contains the module files. |
| 1371 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1372 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1373 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1374 | // Preprocessor options. |
| 1375 | Record.clear(); |
| 1376 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1377 | |
| 1378 | // Macro definitions. |
| 1379 | Record.push_back(PPOpts.Macros.size()); |
| 1380 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1381 | AddString(PPOpts.Macros[I].first, Record); |
| 1382 | Record.push_back(PPOpts.Macros[I].second); |
| 1383 | } |
| 1384 | |
| 1385 | // Includes |
| 1386 | Record.push_back(PPOpts.Includes.size()); |
| 1387 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1388 | AddString(PPOpts.Includes[I], Record); |
| 1389 | |
| 1390 | // Macro includes |
| 1391 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1392 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1393 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1394 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1395 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1396 | // Detailed record is important since it is used for the module cache hash. |
| 1397 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1398 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1399 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1400 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1401 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1402 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1403 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1404 | SourceManager &SM = Context.getSourceManager(); |
| 1405 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 1406 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1407 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1408 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1409 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1410 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1411 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1412 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1413 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1414 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1415 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1416 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1417 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1418 | Record.clear(); |
| 1419 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1420 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1421 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1422 | // Original PCH directory |
| 1423 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1424 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1425 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1426 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1427 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1428 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1429 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1430 | |
| 1431 | llvm::sys::fs::make_absolute(OutputPath); |
| 1432 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1433 | |
| 1434 | RecordData Record; |
| 1435 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1436 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1437 | } |
| 1438 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1439 | WriteInputFiles(Context.SourceMgr, |
| 1440 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1441 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1442 | Stream.ExitBlock(); |
| 1443 | } |
| 1444 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1445 | namespace { |
| 1446 | /// \brief An input file. |
| 1447 | struct InputFileEntry { |
| 1448 | const FileEntry *File; |
| 1449 | bool IsSystemFile; |
| 1450 | bool BufferOverridden; |
| 1451 | }; |
| 1452 | } |
| 1453 | |
| 1454 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1455 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1456 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1457 | using namespace llvm; |
| 1458 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
| 1459 | RecordData Record; |
| 1460 | |
| 1461 | // Create input-file abbreviation. |
| 1462 | BitCodeAbbrev *IFAbbrev = new BitCodeAbbrev(); |
| 1463 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1464 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1465 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1466 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1467 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1468 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1469 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1470 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1471 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1472 | // system one or not. System files go at the back, users files at the front. |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1473 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1474 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1475 | // Get this source location entry. |
| 1476 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1477 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1478 | |
| 1479 | // We only care about file entries that were not overridden. |
| 1480 | if (!SLoc->isFile()) |
| 1481 | continue; |
| 1482 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1483 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1484 | continue; |
| 1485 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1486 | InputFileEntry Entry; |
| 1487 | Entry.File = Cache->OrigEntry; |
| 1488 | Entry.IsSystemFile = Cache->IsSystemFile; |
| 1489 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1490 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1491 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1492 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1493 | SortedFiles.push_front(Entry); |
| 1494 | } |
| 1495 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1496 | unsigned UserFilesNum = 0; |
| 1497 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1498 | std::vector<uint64_t> InputFileOffsets; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1499 | for (std::deque<InputFileEntry>::iterator |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1500 | I = SortedFiles.begin(), E = SortedFiles.end(); I != E; ++I) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1501 | const InputFileEntry &Entry = *I; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1502 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1503 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1504 | if (InputFileID != 0) |
| 1505 | continue; // already recorded this file. |
| 1506 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1507 | // Record this entry's offset. |
| 1508 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1509 | |
| 1510 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1511 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1512 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1513 | ++UserFilesNum; |
| 1514 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1515 | Record.clear(); |
| 1516 | Record.push_back(INPUT_FILE); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1517 | Record.push_back(InputFileOffsets.size()); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1518 | |
| 1519 | // Emit size/modification time for this file. |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1520 | Record.push_back(Entry.File->getSize()); |
| 1521 | Record.push_back(Entry.File->getModificationTime()); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1522 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1523 | // Whether this file was overridden. |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1524 | Record.push_back(Entry.BufferOverridden); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1525 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1526 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1527 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1528 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1529 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1530 | |
| 1531 | // Create input file offsets abbreviation. |
| 1532 | BitCodeAbbrev *OffsetsAbbrev = new BitCodeAbbrev(); |
| 1533 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1534 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1535 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1536 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1537 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
| 1538 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); |
| 1539 | |
| 1540 | // Write input file offsets. |
| 1541 | Record.clear(); |
| 1542 | Record.push_back(INPUT_FILE_OFFSETS); |
| 1543 | Record.push_back(InputFileOffsets.size()); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1544 | Record.push_back(UserFilesNum); |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1545 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1548 | //===----------------------------------------------------------------------===// |
| 1549 | // Source Manager Serialization |
| 1550 | //===----------------------------------------------------------------------===// |
| 1551 | |
| 1552 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1553 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1554 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1555 | using namespace llvm; |
| 1556 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1557 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1558 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1559 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1560 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1561 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1562 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1563 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1564 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1565 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1566 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1567 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1571 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1572 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1573 | using namespace llvm; |
| 1574 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1575 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1576 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1577 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1578 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1579 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1580 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1581 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1585 | /// buffer's blob. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1586 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1587 | using namespace llvm; |
| 1588 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1589 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1590 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1591 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1594 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1595 | /// expansion. |
| 1596 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1597 | using namespace llvm; |
| 1598 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1599 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1600 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1601 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1602 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1603 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1604 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1605 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1608 | namespace { |
| 1609 | // Trait used for the on-disk hash table of header search information. |
| 1610 | class HeaderFileInfoTrait { |
| 1611 | ASTWriter &Writer; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1612 | const HeaderSearch &HS; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1613 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1614 | // Keep track of the framework names we've used during serialization. |
| 1615 | SmallVector<char, 128> FrameworkStringData; |
| 1616 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1617 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1618 | public: |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1619 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
| 1620 | : Writer(Writer), HS(HS) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1621 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1622 | struct key_type { |
| 1623 | const FileEntry *FE; |
| 1624 | const char *Filename; |
| 1625 | }; |
| 1626 | typedef const key_type &key_type_ref; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1627 | |
| 1628 | typedef HeaderFileInfo data_type; |
| 1629 | typedef const data_type &data_type_ref; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1630 | typedef unsigned hash_value_type; |
| 1631 | typedef unsigned offset_type; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1632 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1633 | static hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1634 | // The hash is based only on size/time of the file, so that the reader can |
| 1635 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1636 | // change the form of the name. However, complete path is still the key. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1637 | // |
| 1638 | // FIXME: Using the mtime here will cause problems for explicit module |
| 1639 | // imports. |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1640 | return llvm::hash_combine(key.FE->getSize(), |
| 1641 | key.FE->getModificationTime()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1645 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1646 | using namespace llvm::support; |
| 1647 | endian::Writer<little> Writer(Out); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1648 | unsigned KeyLen = strlen(key.Filename) + 1 + 8 + 8; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1649 | Writer.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1650 | unsigned DataLen = 1 + 2 + 4 + 4; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1651 | if (Data.isModuleHeader) |
| 1652 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1653 | Writer.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1654 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1657 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1658 | using namespace llvm::support; |
| 1659 | endian::Writer<little> LE(Out); |
| 1660 | LE.write<uint64_t>(key.FE->getSize()); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1661 | KeyLen -= 8; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1662 | LE.write<uint64_t>(key.FE->getModificationTime()); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1663 | KeyLen -= 8; |
| 1664 | Out.write(key.Filename, KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1667 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1668 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1669 | using namespace llvm::support; |
| 1670 | endian::Writer<little> LE(Out); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1671 | uint64_t Start = Out.tell(); (void)Start; |
| 1672 | |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 1673 | unsigned char Flags = (Data.HeaderRole << 6) |
| 1674 | | (Data.isImport << 5) |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1675 | | (Data.isPragmaOnce << 4) |
| 1676 | | (Data.DirInfo << 2) |
| 1677 | | (Data.Resolved << 1) |
| 1678 | | Data.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1679 | LE.write<uint8_t>(Flags); |
| 1680 | LE.write<uint16_t>(Data.NumIncludes); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1681 | |
| 1682 | if (!Data.ControllingMacro) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1683 | LE.write<uint32_t>(Data.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1684 | else |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1685 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1686 | |
| 1687 | unsigned Offset = 0; |
| 1688 | if (!Data.Framework.empty()) { |
| 1689 | // If this header refers into a framework, save the framework name. |
| 1690 | llvm::StringMap<unsigned>::iterator Pos |
| 1691 | = FrameworkNameOffset.find(Data.Framework); |
| 1692 | if (Pos == FrameworkNameOffset.end()) { |
| 1693 | Offset = FrameworkStringData.size() + 1; |
| 1694 | FrameworkStringData.append(Data.Framework.begin(), |
| 1695 | Data.Framework.end()); |
| 1696 | FrameworkStringData.push_back(0); |
| 1697 | |
| 1698 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1699 | } else |
| 1700 | Offset = Pos->second; |
| 1701 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1702 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1703 | |
| 1704 | if (Data.isModuleHeader) { |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 1705 | Module *Mod = HS.findModuleForHeader(key.FE).getModule(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1706 | LE.write<uint32_t>(Writer.getExistingSubmoduleID(Mod)); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1709 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1710 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1711 | |
| 1712 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1713 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1714 | }; |
| 1715 | } // end anonymous namespace |
| 1716 | |
| 1717 | /// \brief Write the header search block for the list of files that |
| 1718 | /// |
| 1719 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1720 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1721 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1722 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1723 | |
| 1724 | if (FilesByUID.size() > HS.header_file_size()) |
| 1725 | FilesByUID.resize(HS.header_file_size()); |
| 1726 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1727 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 1728 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1729 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1730 | unsigned NumHeaderSearchEntries = 0; |
| 1731 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1732 | const FileEntry *File = FilesByUID[UID]; |
| 1733 | if (!File) |
| 1734 | continue; |
| 1735 | |
Argyrios Kyrtzidis | f5ab034 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1736 | // Use HeaderSearch's getFileInfo to make sure we get the HeaderFileInfo |
| 1737 | // from the external source if it was not provided already. |
Ben Langmuir | d285c50 | 2014-03-13 16:46:36 +0000 | [diff] [blame] | 1738 | HeaderFileInfo HFI; |
| 1739 | if (!HS.tryGetFileInfo(File, HFI) || |
| 1740 | (HFI.External && Chain) || |
| 1741 | (HFI.isModuleHeader && !HFI.isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 1742 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1743 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1744 | // Massage the file path into an appropriate form. |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1745 | const char *Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1746 | SmallString<128> FilenameTmp(Filename); |
| 1747 | if (PreparePathForOutput(FilenameTmp)) { |
| 1748 | // If we performed any translation on the file name at all, we need to |
| 1749 | // save this string, since the generator will refer to it later. |
| 1750 | Filename = strdup(FilenameTmp.c_str()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1751 | SavedStrings.push_back(Filename); |
| 1752 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1753 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1754 | HeaderFileInfoTrait::key_type key = { File, Filename }; |
| 1755 | Generator.insert(key, HFI, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1756 | ++NumHeaderSearchEntries; |
| 1757 | } |
| 1758 | |
| 1759 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1760 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1761 | uint32_t BucketOffset; |
| 1762 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1763 | using namespace llvm::support; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1764 | llvm::raw_svector_ostream Out(TableData); |
| 1765 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1766 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1767 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1768 | } |
| 1769 | |
| 1770 | // Create a blob abbreviation |
| 1771 | using namespace llvm; |
| 1772 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1773 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1774 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1775 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1776 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1777 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1778 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1779 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1780 | // Write the header search table |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1781 | RecordData Record; |
| 1782 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1783 | Record.push_back(BucketOffset); |
| 1784 | Record.push_back(NumHeaderSearchEntries); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1785 | Record.push_back(TableData.size()); |
| 1786 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 1787 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1788 | |
| 1789 | // Free all of the strings we had to duplicate. |
| 1790 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1791 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1794 | /// \brief Writes the block containing the serialized form of the |
| 1795 | /// source manager. |
| 1796 | /// |
| 1797 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1798 | /// blob), indexed based on the file name, so that we only create |
| 1799 | /// entries for files that we actually need. In the common case (no |
| 1800 | /// errors), we probably won't have to create file entries for any of |
| 1801 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1802 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1803 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1804 | RecordData Record; |
| 1805 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1806 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1807 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1808 | |
| 1809 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1810 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1811 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1812 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1813 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1814 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1815 | // Write out the source location entry table. We skip the first |
| 1816 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1817 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1818 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1819 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1820 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1821 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1822 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1823 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1824 | FileID FID = FileID::get(I); |
| 1825 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1826 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1827 | // Record the offset of this source-location entry. |
| 1828 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1829 | |
| 1830 | // Figure out which record code to use. |
| 1831 | unsigned Code; |
| 1832 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1833 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1834 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1835 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1836 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1837 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1838 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1839 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1840 | Record.clear(); |
| 1841 | Record.push_back(Code); |
| 1842 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1843 | // Starting offset of this entry within this module, so skip the dummy. |
| 1844 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1845 | if (SLoc->isFile()) { |
| 1846 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1847 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1848 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1849 | Record.push_back(File.hasLineDirectives()); |
| 1850 | |
| 1851 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1852 | if (Content->OrigEntry) { |
| 1853 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1854 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1855 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1856 | // The source location entry is a file. Emit input file ID. |
| 1857 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 1858 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1859 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1860 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1861 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1862 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1863 | if (FDI != FileDeclIDs.end()) { |
| 1864 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1865 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1866 | } else { |
| 1867 | Record.push_back(0); |
| 1868 | Record.push_back(0); |
| 1869 | } |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1870 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1871 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1872 | |
| 1873 | if (Content->BufferOverridden) { |
| 1874 | Record.clear(); |
| 1875 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
| 1876 | const llvm::MemoryBuffer *Buffer |
| 1877 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1878 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
| 1879 | StringRef(Buffer->getBufferStart(), |
| 1880 | Buffer->getBufferSize() + 1)); |
| 1881 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1882 | } else { |
| 1883 | // The source location entry is a buffer. The blob associated |
| 1884 | // with this entry contains the contents of the buffer. |
| 1885 | |
| 1886 | // We add one to the size so that we capture the trailing NULL |
| 1887 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1888 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1889 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1890 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1891 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1892 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1893 | StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1894 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1895 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1896 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1897 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1898 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1899 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1900 | if (strcmp(Name, "<built-in>") == 0) { |
| 1901 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1902 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1903 | } |
| 1904 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1905 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1906 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 73ee5d7 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1907 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1908 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | a1d943a | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1909 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1910 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1911 | |
| 1912 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1913 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1914 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1915 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1916 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1917 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1921 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1922 | |
| 1923 | if (SLocEntryOffsets.empty()) |
| 1924 | return; |
| 1925 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1926 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1927 | // table is used for lazily loading source-location information. |
| 1928 | using namespace llvm; |
| 1929 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1930 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1931 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1932 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1933 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1934 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1935 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1936 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1937 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1938 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1939 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1940 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, bytes(SLocEntryOffsets)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1941 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1942 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1943 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1944 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1945 | |
| 1946 | // Write the line table. It depends on remapping working, so it must come |
| 1947 | // after the source location offsets. |
| 1948 | if (SourceMgr.hasLineTable()) { |
| 1949 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1950 | |
| 1951 | Record.clear(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1952 | // Emit the file names. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1953 | Record.push_back(LineTable.getNumFilenames()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1954 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) |
| 1955 | AddPath(LineTable.getFilename(I), Record); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1956 | |
| 1957 | // Emit the line entries |
| 1958 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1959 | L != LEnd; ++L) { |
| 1960 | // Only emit entries for local files. |
Douglas Gregor | 02c2dbf | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1961 | if (L->first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1962 | continue; |
| 1963 | |
| 1964 | // Emit the file ID |
Douglas Gregor | 02c2dbf | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1965 | Record.push_back(L->first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1966 | |
| 1967 | // Emit the line entries |
| 1968 | Record.push_back(L->second.size()); |
| 1969 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1970 | LEEnd = L->second.end(); |
| 1971 | LE != LEEnd; ++LE) { |
| 1972 | Record.push_back(LE->FileOffset); |
| 1973 | Record.push_back(LE->LineNo); |
| 1974 | Record.push_back(LE->FilenameID); |
| 1975 | Record.push_back((unsigned)LE->FileKind); |
| 1976 | Record.push_back(LE->IncludeOffset); |
| 1977 | } |
| 1978 | } |
| 1979 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1980 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1983 | //===----------------------------------------------------------------------===// |
| 1984 | // Preprocessor Serialization |
| 1985 | //===----------------------------------------------------------------------===// |
| 1986 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 1987 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 1988 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1989 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 1990 | if (MI->isBuiltinMacro()) |
| 1991 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 1992 | |
| 1993 | if (IsModule) { |
| 1994 | SourceLocation Loc = MD->getLocation(); |
| 1995 | if (Loc.isInvalid()) |
| 1996 | return true; |
| 1997 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 1998 | return true; |
| 1999 | } |
| 2000 | |
| 2001 | return false; |
| 2002 | } |
| 2003 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2004 | /// \brief Writes the block containing the serialized form of the |
| 2005 | /// preprocessor. |
| 2006 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2007 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2008 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2009 | if (PPRec) |
| 2010 | WritePreprocessorDetail(*PPRec); |
| 2011 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2012 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2013 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2014 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2015 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2016 | if (PP.getCounterValue() != 0) { |
| 2017 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2018 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2019 | Record.clear(); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2023 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2024 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2025 | // If the AST file contains __DATE__ or __TIME__ emit a warning about this. |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2026 | // FIXME: use diagnostics subsystem for localization etc. |
| 2027 | if (PP.SawDateOrTime()) |
| 2028 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2030 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2031 | // Loop over all the macro directives that are live at the end of the file, |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2032 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2033 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2034 | // Construct the list of identifiers with macro directives that need to be |
| 2035 | // serialized. |
| 2036 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2037 | for (auto &Id : PP.getIdentifierTable()) |
| 2038 | if (Id.second->hadMacroDefinition() && |
| 2039 | (!Id.second->isFromAST() || |
| 2040 | Id.second->hasChangedSinceDeserialization())) |
| 2041 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2042 | // Sort the set of macro definitions that need to be serialized by the |
| 2043 | // name of the macro, to provide a stable ordering. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2044 | std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2045 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2046 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2047 | // Emit the macro directives as a list and associate the offset with the |
| 2048 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2049 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2050 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2051 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2052 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2053 | // Emit the macro directives in reverse source order. |
| 2054 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2055 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2056 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2057 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2058 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2059 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2060 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2061 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2062 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2063 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2064 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2065 | Record.push_back(VisMD->isPublic()); |
| 2066 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2067 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2068 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2069 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2070 | bool EmittedModuleMacros = false; |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2071 | if (IsModule) { |
| 2072 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2073 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2074 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2075 | while (!Worklist.empty()) { |
| 2076 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2077 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2078 | // Emit a record indicating this submodule exports this macro. |
| 2079 | ModuleMacroRecord.push_back( |
| 2080 | getSubmoduleID(Macro->getOwningModule())); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2081 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2082 | for (auto *M : Macro->overrides()) |
| 2083 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2084 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2085 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2086 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2087 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2088 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2089 | for (auto *M : Macro->overrides()) |
| 2090 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2091 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2092 | |
| 2093 | EmittedModuleMacros = true; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2094 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2095 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2096 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2097 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2098 | continue; |
| 2099 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2100 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2101 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2102 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2103 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2104 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2105 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 2106 | /// the local macro ID |
| 2107 | /// |
| 2108 | /// For each identifier that is associated with a macro, this map |
| 2109 | /// provides the offset into the bitstream where that macro is |
| 2110 | /// defined. |
| 2111 | std::vector<uint32_t> MacroOffsets; |
| 2112 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2113 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2114 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2115 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2116 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2117 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2118 | if (ID < FirstMacroID) { |
| 2119 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2120 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2121 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2122 | |
| 2123 | // Record the local offset of this macro. |
| 2124 | unsigned Index = ID - FirstMacroID; |
| 2125 | if (Index == MacroOffsets.size()) |
| 2126 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2127 | else { |
| 2128 | if (Index > MacroOffsets.size()) |
| 2129 | MacroOffsets.resize(Index + 1); |
| 2130 | |
| 2131 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2132 | } |
| 2133 | |
| 2134 | AddIdentifierRef(Name, Record); |
| 2135 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
| 2136 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2137 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2138 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2139 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2140 | unsigned Code; |
| 2141 | if (MI->isObjectLike()) { |
| 2142 | Code = PP_MACRO_OBJECT_LIKE; |
| 2143 | } else { |
| 2144 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2145 | |
| 2146 | Record.push_back(MI->isC99Varargs()); |
| 2147 | Record.push_back(MI->isGNUVarargs()); |
| 2148 | Record.push_back(MI->hasCommaPasting()); |
| 2149 | Record.push_back(MI->getNumArgs()); |
Daniel Marjamaki | e4770da | 2015-05-29 09:15:24 +0000 | [diff] [blame] | 2150 | for (const IdentifierInfo *Arg : MI->args()) |
| 2151 | AddIdentifierRef(Arg, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | // If we have a detailed preprocessing record, record the macro definition |
| 2155 | // ID that corresponds to this macro. |
| 2156 | if (PPRec) |
| 2157 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2158 | |
| 2159 | Stream.EmitRecord(Code, Record); |
| 2160 | Record.clear(); |
| 2161 | |
| 2162 | // Emit the tokens array. |
| 2163 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2164 | // Note that we know that the preprocessor does not have any annotation |
| 2165 | // tokens in it because they are created by the parser, and thus can't |
| 2166 | // be in a macro definition. |
| 2167 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2168 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2169 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2170 | Record.clear(); |
| 2171 | } |
| 2172 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2173 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2174 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2175 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2176 | |
| 2177 | // Write the offsets table for macro IDs. |
| 2178 | using namespace llvm; |
Richard Smith | 13090a2 | 2015-04-10 02:02:24 +0000 | [diff] [blame] | 2179 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2180 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2181 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2182 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2183 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2184 | |
| 2185 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2186 | Record.clear(); |
| 2187 | Record.push_back(MACRO_OFFSET); |
| 2188 | Record.push_back(MacroOffsets.size()); |
| 2189 | Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS); |
| 2190 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2191 | bytes(MacroOffsets)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2195 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2196 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2197 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2198 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2199 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2200 | // Enter the preprocessor block. |
| 2201 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2202 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2203 | // If the preprocessor has a preprocessing record, emit it. |
| 2204 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2205 | using namespace llvm; |
| 2206 | |
| 2207 | // Set up the abbreviation for |
| 2208 | unsigned InclusionAbbrev = 0; |
| 2209 | { |
| 2210 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2211 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2212 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2213 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2214 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2215 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2216 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2217 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2218 | } |
| 2219 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2220 | unsigned FirstPreprocessorEntityID |
| 2221 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2222 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2223 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2224 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2225 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2226 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2227 | E != EEnd; |
| 2228 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2229 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2230 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2231 | PreprocessedEntityOffsets.push_back( |
| 2232 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2233 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2234 | if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2235 | // Record this macro definition's ID. |
| 2236 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2237 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2238 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2239 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2240 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2241 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2242 | |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 2243 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2244 | Record.push_back(ME->isBuiltinMacro()); |
| 2245 | if (ME->isBuiltinMacro()) |
| 2246 | AddIdentifierRef(ME->getName(), Record); |
| 2247 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2248 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2249 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2250 | continue; |
| 2251 | } |
| 2252 | |
| 2253 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 2254 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2255 | Record.push_back(ID->getFileName().size()); |
| 2256 | Record.push_back(ID->wasInQuotes()); |
| 2257 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2258 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2259 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2260 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2261 | // Check that the FileEntry is not null because it was not resolved and |
| 2262 | // we create a PCH even with compiler errors. |
| 2263 | if (ID->getFile()) |
| 2264 | Buffer += ID->getFile()->getName(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2265 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 2266 | continue; |
| 2267 | } |
| 2268 | |
| 2269 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2270 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2271 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2272 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2273 | // Write the offsets table for the preprocessing record. |
| 2274 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2275 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2276 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2277 | // Write the offsets table for identifier IDs. |
| 2278 | using namespace llvm; |
| 2279 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2280 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2281 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2282 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2283 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2284 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2285 | Record.clear(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2286 | Record.push_back(PPD_ENTITIES_OFFSETS); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2287 | Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2288 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2289 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2290 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2293 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2294 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2295 | if (Known != SubmoduleIDs.end()) |
| 2296 | return Known->second; |
| 2297 | |
| 2298 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2299 | } |
| 2300 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2301 | unsigned ASTWriter::getExistingSubmoduleID(Module *Mod) const { |
| 2302 | if (!Mod) |
| 2303 | return 0; |
| 2304 | |
| 2305 | llvm::DenseMap<Module *, unsigned>::const_iterator |
| 2306 | Known = SubmoduleIDs.find(Mod); |
| 2307 | if (Known != SubmoduleIDs.end()) |
| 2308 | return Known->second; |
| 2309 | |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2313 | /// \brief Compute the number of modules within the given tree (including the |
| 2314 | /// given module). |
| 2315 | static unsigned getNumberOfModules(Module *Mod) { |
| 2316 | unsigned ChildModules = 0; |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2317 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2318 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2319 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2320 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2321 | |
| 2322 | return ChildModules + 1; |
| 2323 | } |
| 2324 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2325 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2326 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2327 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2328 | |
| 2329 | // Write the abbreviations needed for the submodules block. |
| 2330 | using namespace llvm; |
| 2331 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2332 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2333 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2334 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2335 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2336 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2337 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2338 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2339 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2340 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2341 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2342 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2343 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2344 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2345 | |
| 2346 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2347 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2348 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2349 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2350 | |
| 2351 | Abbrev = new BitCodeAbbrev(); |
| 2352 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2353 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2354 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2355 | |
| 2356 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2357 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2358 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2359 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2360 | |
| 2361 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2362 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2363 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2364 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2365 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2366 | Abbrev = new BitCodeAbbrev(); |
| 2367 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2368 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2369 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2370 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2371 | |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2372 | Abbrev = new BitCodeAbbrev(); |
| 2373 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2374 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2375 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2376 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2377 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2378 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2379 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2380 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2381 | |
| 2382 | Abbrev = new BitCodeAbbrev(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2383 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2384 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2385 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2386 | |
| 2387 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2388 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2389 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2390 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2391 | |
| 2392 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2393 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2394 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2395 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2396 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2397 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2398 | Abbrev = new BitCodeAbbrev(); |
| 2399 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2400 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2401 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2402 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2403 | Abbrev = new BitCodeAbbrev(); |
| 2404 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2405 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2406 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
| 2407 | unsigned ConflictAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2408 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2409 | // Write the submodule metadata block. |
| 2410 | RecordData Record; |
| 2411 | Record.push_back(getNumberOfModules(WritingModule)); |
| 2412 | Record.push_back(FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS); |
| 2413 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2414 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2415 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2416 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2417 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2418 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2419 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2420 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2421 | unsigned ID = getSubmoduleID(Mod); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2422 | |
| 2423 | // Emit the definition of the block. |
| 2424 | Record.clear(); |
| 2425 | Record.push_back(SUBMODULE_DEFINITION); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2426 | Record.push_back(ID); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2427 | if (Mod->Parent) { |
| 2428 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
| 2429 | Record.push_back(SubmoduleIDs[Mod->Parent]); |
| 2430 | } else { |
| 2431 | Record.push_back(0); |
| 2432 | } |
| 2433 | Record.push_back(Mod->IsFramework); |
| 2434 | Record.push_back(Mod->IsExplicit); |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2435 | Record.push_back(Mod->IsSystem); |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2436 | Record.push_back(Mod->IsExternC); |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2437 | Record.push_back(Mod->InferSubmodules); |
| 2438 | Record.push_back(Mod->InferExplicitSubmodules); |
| 2439 | Record.push_back(Mod->InferExportWildcard); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2440 | Record.push_back(Mod->ConfigMacrosExhaustive); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2441 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2442 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2443 | // Emit the requirements. |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2444 | for (unsigned I = 0, N = Mod->Requirements.size(); I != N; ++I) { |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2445 | Record.clear(); |
| 2446 | Record.push_back(SUBMODULE_REQUIRES); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2447 | Record.push_back(Mod->Requirements[I].second); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2448 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2449 | Mod->Requirements[I].first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2452 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2453 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2454 | Record.clear(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2455 | Record.push_back(SUBMODULE_UMBRELLA_HEADER); |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2456 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2457 | UmbrellaHeader.NameAsWritten); |
| 2458 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2459 | Record.clear(); |
| 2460 | Record.push_back(SUBMODULE_UMBRELLA_DIR); |
| 2461 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2462 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2463 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2464 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2465 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2466 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2467 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2468 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2469 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2470 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2471 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2472 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2473 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2474 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2475 | Module::HK_PrivateTextual}, |
| 2476 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2477 | }; |
| 2478 | for (auto &HL : HeaderLists) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2479 | Record.clear(); |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2480 | Record.push_back(HL.RecordKind); |
| 2481 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2482 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2483 | } |
| 2484 | |
| 2485 | // Emit the top headers. |
| 2486 | { |
| 2487 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
| 2488 | Record.clear(); |
| 2489 | Record.push_back(SUBMODULE_TOPHEADER); |
| 2490 | for (auto *H : TopHeaders) |
| 2491 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2492 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2493 | |
| 2494 | // Emit the imports. |
| 2495 | if (!Mod->Imports.empty()) { |
| 2496 | Record.clear(); |
| 2497 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
Douglas Gregor | 18b5864 | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2498 | unsigned ImportedID = getSubmoduleID(Mod->Imports[I]); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2499 | assert(ImportedID && "Unknown submodule!"); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2500 | Record.push_back(ImportedID); |
| 2501 | } |
| 2502 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2503 | } |
| 2504 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2505 | // Emit the exports. |
| 2506 | if (!Mod->Exports.empty()) { |
| 2507 | Record.clear(); |
| 2508 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
Douglas Gregor | 18b5864 | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2509 | if (Module *Exported = Mod->Exports[I].getPointer()) { |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2510 | unsigned ExportedID = getSubmoduleID(Exported); |
Douglas Gregor | 18b5864 | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2511 | Record.push_back(ExportedID); |
| 2512 | } else { |
| 2513 | Record.push_back(0); |
| 2514 | } |
| 2515 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2516 | Record.push_back(Mod->Exports[I].getInt()); |
| 2517 | } |
| 2518 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2519 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2520 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2521 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2522 | // Might be unnecessary as use declarations are only used to build the |
| 2523 | // module itself. |
| 2524 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2525 | // Emit the link libraries. |
| 2526 | for (unsigned I = 0, N = Mod->LinkLibraries.size(); I != N; ++I) { |
| 2527 | Record.clear(); |
| 2528 | Record.push_back(SUBMODULE_LINK_LIBRARY); |
| 2529 | Record.push_back(Mod->LinkLibraries[I].IsFramework); |
| 2530 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, |
| 2531 | Mod->LinkLibraries[I].Library); |
| 2532 | } |
| 2533 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2534 | // Emit the conflicts. |
| 2535 | for (unsigned I = 0, N = Mod->Conflicts.size(); I != N; ++I) { |
| 2536 | Record.clear(); |
| 2537 | Record.push_back(SUBMODULE_CONFLICT); |
| 2538 | unsigned OtherID = getSubmoduleID(Mod->Conflicts[I].Other); |
| 2539 | assert(OtherID && "Unknown submodule!"); |
| 2540 | Record.push_back(OtherID); |
| 2541 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, |
| 2542 | Mod->Conflicts[I].Message); |
| 2543 | } |
| 2544 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2545 | // Emit the configuration macros. |
| 2546 | for (unsigned I = 0, N = Mod->ConfigMacros.size(); I != N; ++I) { |
| 2547 | Record.clear(); |
| 2548 | Record.push_back(SUBMODULE_CONFIG_MACRO); |
| 2549 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, |
| 2550 | Mod->ConfigMacros[I]); |
| 2551 | } |
| 2552 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2553 | // Queue up the submodules of this module. |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2554 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2555 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2556 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2557 | Q.push(*Sub); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2561 | |
| 2562 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2563 | // did not result in us loading a module file for that submodule. For |
| 2564 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2565 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 2566 | getNumberOfModules(WritingModule)) && |
| 2567 | "Wrong # of submodules; found a reference to a non-local, " |
| 2568 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2569 | } |
| 2570 | |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2571 | serialization::SubmoduleID |
| 2572 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2573 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2574 | return 0; // No submodule |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2575 | |
| 2576 | // Find the module that owns this location. |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2577 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2578 | Module *OwningMod |
| 2579 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2580 | if (!OwningMod) |
| 2581 | return 0; |
| 2582 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2583 | // Check whether this submodule is part of our own module. |
| 2584 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2585 | return 0; |
| 2586 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2587 | return getSubmoduleID(OwningMod); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2590 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2591 | bool isModule) { |
| 2592 | // Make sure set diagnostic pragmas don't affect the translation unit that |
| 2593 | // imports the module. |
| 2594 | // FIXME: Make diagnostic pragma sections work properly with modules. |
| 2595 | if (isModule) |
| 2596 | return; |
| 2597 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2598 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2599 | DiagStateIDMap; |
| 2600 | unsigned CurrID = 0; |
| 2601 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2602 | RecordData Record; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2603 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2604 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2605 | I != E; ++I) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2606 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2607 | if (point.Loc.isInvalid()) |
| 2608 | continue; |
| 2609 | |
| 2610 | Record.push_back(point.Loc.getRawEncoding()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2611 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2612 | Record.push_back(DiagStateID); |
| 2613 | |
| 2614 | if (DiagStateID == 0) { |
| 2615 | DiagStateID = ++CurrID; |
| 2616 | for (DiagnosticsEngine::DiagState::const_iterator |
| 2617 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
| 2618 | if (I->second.isPragma()) { |
| 2619 | Record.push_back(I->first); |
Alp Toker | 46df1c0 | 2014-06-12 10:15:20 +0000 | [diff] [blame] | 2620 | Record.push_back((unsigned)I->second.getSeverity()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2621 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2622 | } |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2623 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2624 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2625 | } |
| 2626 | } |
| 2627 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2628 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2629 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2632 | void ASTWriter::WriteCXXCtorInitializersOffsets() { |
| 2633 | if (CXXCtorInitializersOffsets.empty()) |
| 2634 | return; |
| 2635 | |
| 2636 | RecordData Record; |
| 2637 | |
| 2638 | // Create a blob abbreviation for the C++ ctor initializer offsets. |
| 2639 | using namespace llvm; |
| 2640 | |
| 2641 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2642 | Abbrev->Add(BitCodeAbbrevOp(CXX_CTOR_INITIALIZERS_OFFSETS)); |
| 2643 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2644 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2645 | unsigned CtorInitializersOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2646 | |
| 2647 | // Write the base specifier offsets table. |
| 2648 | Record.clear(); |
| 2649 | Record.push_back(CXX_CTOR_INITIALIZERS_OFFSETS); |
| 2650 | Record.push_back(CXXCtorInitializersOffsets.size()); |
| 2651 | Stream.EmitRecordWithBlob(CtorInitializersOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2652 | bytes(CXXCtorInitializersOffsets)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2653 | } |
| 2654 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2655 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2656 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2657 | return; |
| 2658 | |
| 2659 | RecordData Record; |
| 2660 | |
| 2661 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2662 | using namespace llvm; |
| 2663 | |
| 2664 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2665 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2666 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2667 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2668 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2669 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2670 | // Write the base specifier offsets table. |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2671 | Record.clear(); |
| 2672 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 2673 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 2674 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2675 | bytes(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2678 | //===----------------------------------------------------------------------===// |
| 2679 | // Type Serialization |
| 2680 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2681 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2682 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2683 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | a7fbbb0 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2684 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2685 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2686 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2688 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2689 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2690 | // Record the offset for this type. |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2691 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2692 | if (TypeOffsets.size() == Index) |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2693 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2694 | else if (TypeOffsets.size() < Index) { |
| 2695 | TypeOffsets.resize(Index + 1); |
| 2696 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2700 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2701 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2702 | ASTTypeWriter W(*this, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2703 | W.AbbrevToUse = 0; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2704 | |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2705 | if (T.hasLocalNonFastQualifiers()) { |
| 2706 | Qualifiers Qs = T.getLocalQualifiers(); |
| 2707 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2708 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2709 | W.Code = TYPE_EXT_QUAL; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2710 | W.AbbrevToUse = TypeExtQualAbbrev; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2711 | } else { |
| 2712 | switch (T->getTypeClass()) { |
| 2713 | // For all of the concrete, non-dependent types, call the |
| 2714 | // appropriate visitor function. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2715 | #define TYPE(Class, Base) \ |
Mike Stump | 281d6d7 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 2716 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2717 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2718 | #include "clang/AST/TypeNodes.def" |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2719 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | // Emit the serialized record. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2723 | Stream.EmitRecord(W.Code, Record, W.AbbrevToUse); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2724 | |
| 2725 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2726 | FlushStmts(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2729 | //===----------------------------------------------------------------------===// |
| 2730 | // Declaration Serialization |
| 2731 | //===----------------------------------------------------------------------===// |
| 2732 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2733 | /// \brief Write the block containing all of the declaration IDs |
| 2734 | /// lexically declared within the given DeclContext. |
| 2735 | /// |
| 2736 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2737 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2738 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2739 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2740 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2741 | return 0; |
| 2742 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2743 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2744 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2745 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2746 | SmallVector<KindDeclIDPair, 64> Decls; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2747 | for (const auto *D : DC->decls()) |
| 2748 | Decls.push_back(std::make_pair(D->getKind(), GetDeclRef(D))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2749 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2750 | ++NumLexicalDeclContexts; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2751 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, bytes(Decls)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2752 | return Offset; |
| 2753 | } |
| 2754 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2755 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2756 | using namespace llvm; |
| 2757 | RecordData Record; |
| 2758 | |
| 2759 | // Write the type offsets array |
| 2760 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2761 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2762 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2763 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2764 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2765 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2766 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2767 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2768 | Record.push_back(TypeOffsets.size()); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2769 | Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2770 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2771 | |
| 2772 | // Write the declaration offsets array |
| 2773 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2774 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2775 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2776 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2777 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2778 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2779 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2780 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2781 | Record.push_back(DeclOffsets.size()); |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2782 | Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2783 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2786 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2787 | using namespace llvm; |
| 2788 | RecordData Record; |
| 2789 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2790 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 2791 | FileDeclIDs.begin(), FileDeclIDs.end()); |
| 2792 | std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 2793 | llvm::less_first()); |
| 2794 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2795 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2796 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 2797 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 2798 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 2799 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 2800 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 2801 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2805 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2806 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2807 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2808 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 2809 | Record.push_back(FILE_SORTED_DECLS); |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2810 | Record.push_back(FileGroupedDeclIDs.size()); |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2811 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2814 | void ASTWriter::WriteComments() { |
| 2815 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2816 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2817 | RecordData Record; |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2818 | for (ArrayRef<RawComment *>::iterator I = RawComments.begin(), |
| 2819 | E = RawComments.end(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2820 | I != E; ++I) { |
| 2821 | Record.clear(); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2822 | AddSourceRange((*I)->getSourceRange(), Record); |
| 2823 | Record.push_back((*I)->getKind()); |
| 2824 | Record.push_back((*I)->isTrailingComment()); |
| 2825 | Record.push_back((*I)->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2826 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2827 | } |
| 2828 | Stream.ExitBlock(); |
| 2829 | } |
| 2830 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2831 | //===----------------------------------------------------------------------===// |
| 2832 | // Global Method Pool and Selector Serialization |
| 2833 | //===----------------------------------------------------------------------===// |
| 2834 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2835 | namespace { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2836 | // Trait used for the on-disk hash table used in the method pool. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2837 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2838 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2839 | |
| 2840 | public: |
| 2841 | typedef Selector key_type; |
| 2842 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2843 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2844 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2845 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2846 | ObjCMethodList Instance, Factory; |
| 2847 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2848 | typedef const data_type& data_type_ref; |
| 2849 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2850 | typedef unsigned hash_value_type; |
| 2851 | typedef unsigned offset_type; |
| 2852 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2853 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2854 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2855 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2856 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2857 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2858 | |
| 2859 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2860 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2861 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2862 | using namespace llvm::support; |
| 2863 | endian::Writer<little> LE(Out); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2864 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2865 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2866 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2867 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2868 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2869 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2870 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2871 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2872 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2873 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2874 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2875 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2876 | return std::make_pair(KeyLen, DataLen); |
| 2877 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2878 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2879 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2880 | using namespace llvm::support; |
| 2881 | endian::Writer<little> LE(Out); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2882 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2883 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2884 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2885 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2886 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2887 | if (N == 0) |
| 2888 | N = 1; |
| 2889 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2890 | LE.write<uint32_t>( |
| 2891 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2892 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2893 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2894 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2895 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2896 | using namespace llvm::support; |
| 2897 | endian::Writer<little> LE(Out); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2898 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2899 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2900 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2901 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2902 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2903 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2904 | ++NumInstanceMethods; |
| 2905 | |
| 2906 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2907 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2908 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2909 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2910 | ++NumFactoryMethods; |
| 2911 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2912 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 2913 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2914 | unsigned InstanceHasMoreThanOneDeclBit = |
| 2915 | Methods.Instance.hasMoreThanOneDecl(); |
| 2916 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 2917 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 2918 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2919 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 2920 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2921 | unsigned FactoryHasMoreThanOneDeclBit = |
| 2922 | Methods.Factory.hasMoreThanOneDecl(); |
| 2923 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 2924 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 2925 | FactoryBits; |
| 2926 | LE.write<uint16_t>(FullInstanceBits); |
| 2927 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2928 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2929 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2930 | if (Method->getMethod()) |
| 2931 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2932 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2933 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2934 | if (Method->getMethod()) |
| 2935 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2936 | |
| 2937 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2938 | } |
| 2939 | }; |
| 2940 | } // end anonymous namespace |
| 2941 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2942 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2943 | /// |
| 2944 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2945 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2946 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2947 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2948 | using namespace llvm; |
| 2949 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2950 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2951 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2952 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2953 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2954 | // Create and write out the blob that contains selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2955 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 2956 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2957 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2958 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2959 | // Create the on-disk hash table representation. We walk through every |
| 2960 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2961 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 2962 | for (auto &SelectorAndID : SelectorIDs) { |
| 2963 | Selector S = SelectorAndID.first; |
| 2964 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2965 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2966 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 2967 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2968 | ObjCMethodList(), |
| 2969 | ObjCMethodList() |
| 2970 | }; |
| 2971 | if (F != SemaRef.MethodPool.end()) { |
| 2972 | Data.Instance = F->second.first; |
| 2973 | Data.Factory = F->second.second; |
| 2974 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2975 | // Only write this selector if it's not in an existing AST or something |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2976 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 2977 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2978 | // Selector already exists. Did it change? |
| 2979 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2980 | for (ObjCMethodList *M = &Data.Instance; |
| 2981 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 2982 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2983 | changed = true; |
| 2984 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2985 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2986 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2987 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2988 | changed = true; |
| 2989 | } |
| 2990 | if (!changed) |
| 2991 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2992 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2993 | // A new method pool entry. |
| 2994 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2995 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2996 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2997 | } |
| 2998 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2999 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3000 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3001 | uint32_t BucketOffset; |
| 3002 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3003 | using namespace llvm::support; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3004 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3005 | llvm::raw_svector_ostream Out(MethodPool); |
| 3006 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3007 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3008 | BucketOffset = Generator.Emit(Out, Trait); |
| 3009 | } |
| 3010 | |
| 3011 | // Create a blob abbreviation |
| 3012 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3013 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3014 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3015 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3016 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3017 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3018 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3019 | // Write the method pool |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3020 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3021 | Record.push_back(METHOD_POOL); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3022 | Record.push_back(BucketOffset); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3023 | Record.push_back(NumTableEntries); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3024 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3025 | |
| 3026 | // Create a blob abbreviation for the selector table offsets. |
| 3027 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3028 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3029 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3030 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3031 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3032 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3033 | |
| 3034 | // Write the selector offsets table. |
| 3035 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3036 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3037 | Record.push_back(SelectorOffsets.size()); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3038 | Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3039 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3040 | bytes(SelectorOffsets)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3041 | } |
| 3042 | } |
| 3043 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3044 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3045 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3046 | using namespace llvm; |
| 3047 | if (SemaRef.ReferencedSelectors.empty()) |
| 3048 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3049 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3050 | RecordData Record; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3051 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3052 | // Note: this writes out all references even for a dependent AST. But it is |
Sebastian Redl | 51c79d8 | 2010-08-04 22:21:29 +0000 | [diff] [blame] | 3053 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3054 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3055 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3056 | Selector Sel = SelectorAndLocation.first; |
| 3057 | SourceLocation Loc = SelectorAndLocation.second; |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3058 | AddSelectorRef(Sel, Record); |
| 3059 | AddSourceLocation(Loc, Record); |
| 3060 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3061 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3062 | } |
| 3063 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3064 | //===----------------------------------------------------------------------===// |
| 3065 | // Identifier Table Serialization |
| 3066 | //===----------------------------------------------------------------------===// |
| 3067 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3068 | /// Determine the declaration that should be put into the name lookup table to |
| 3069 | /// represent the given declaration in this module. This is usually D itself, |
| 3070 | /// but if D was imported and merged into a local declaration, we want the most |
| 3071 | /// recent local declaration instead. The chosen declaration will be the most |
| 3072 | /// recent declaration in any module that imports this one. |
| 3073 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3074 | NamedDecl *D) { |
| 3075 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3076 | return D; |
| 3077 | |
| 3078 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3079 | // For Redeclarable decls, a prior declaration might be local. |
| 3080 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
| 3081 | if (!Redecl->isFromASTFile()) |
| 3082 | return cast<NamedDecl>(Redecl); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3083 | // If we find a decl from a (chained-)PCH stop since we won't find a |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3084 | // local one. |
| 3085 | if (D->getOwningModuleID() == 0) |
| 3086 | break; |
| 3087 | } |
| 3088 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3089 | // For Mergeable decls, the first decl might be local. |
| 3090 | if (!First->isFromASTFile()) |
| 3091 | return cast<NamedDecl>(First); |
| 3092 | } |
| 3093 | |
| 3094 | // All declarations are imported. Our most recent declaration will also be |
| 3095 | // the most recent one in anyone who imports us. |
| 3096 | return D; |
| 3097 | } |
| 3098 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3099 | namespace { |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3100 | class ASTIdentifierTableTrait { |
| 3101 | ASTWriter &Writer; |
| 3102 | Preprocessor &PP; |
| 3103 | IdentifierResolver &IdResolver; |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3104 | |
| 3105 | /// \brief Determines whether this is an "interesting" identifier that needs a |
| 3106 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3107 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3108 | /// to check that. |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3109 | bool isInterestingIdentifier(IdentifierInfo *II, uint64_t MacroOffset) { |
| 3110 | if (MacroOffset || |
| 3111 | II->isPoisoned() || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3112 | II->isExtensionToken() || |
| 3113 | II->getObjCOrBuiltinID() || |
| 3114 | II->hasRevertedTokenIDToIdentifier() || |
| 3115 | II->getFETokenInfo<void>()) |
| 3116 | return true; |
| 3117 | |
| 3118 | return false; |
| 3119 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3120 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3121 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3122 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3123 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3124 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3125 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3126 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3127 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3128 | typedef unsigned hash_value_type; |
| 3129 | typedef unsigned offset_type; |
| 3130 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3131 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
| 3132 | IdentifierResolver &IdResolver) |
| 3133 | : Writer(Writer), PP(PP), IdResolver(IdResolver) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3134 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3135 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 3136 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3137 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3138 | |
| 3139 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3140 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3141 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3142 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3143 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3144 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3145 | DataLen += 2; // 2 bytes for builtin ID |
| 3146 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3147 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3148 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3149 | |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3150 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3151 | DEnd = IdResolver.end(); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3152 | D != DEnd; ++D) |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 3153 | DataLen += 4; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3154 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3155 | using namespace llvm::support; |
| 3156 | endian::Writer<little> LE(Out); |
| 3157 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3158 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3159 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3160 | // We emit the key length after the data length so that every |
| 3161 | // string is preceded by a 16-bit length. This matches the PTH |
| 3162 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3163 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3164 | return std::make_pair(KeyLen, DataLen); |
| 3165 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3167 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3168 | unsigned KeyLen) { |
| 3169 | // Record the location of the key data. This is used when generating |
| 3170 | // the mapping from persistent IDs to strings. |
| 3171 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3172 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3173 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3175 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3176 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3177 | using namespace llvm::support; |
| 3178 | endian::Writer<little> LE(Out); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3179 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3180 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3181 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3182 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3183 | return; |
| 3184 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3185 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3186 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3187 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3188 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3189 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3190 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3191 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3192 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3193 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3194 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3195 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3196 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3197 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3198 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3199 | if (HadMacroDefinition) |
| 3200 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3201 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3202 | // Emit the declaration IDs in reverse order, because the |
| 3203 | // IdentifierResolver provides the declarations as they would be |
| 3204 | // visible (e.g., the function "stat" would come before the struct |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3205 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3206 | // (so we need to see the struct "stat" before the function "stat"). |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3207 | // Only emit declarations that aren't from a chained PCH, though. |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3208 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), IdResolver.end()); |
| 3209 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3210 | DEnd = Decls.rend(); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3211 | D != DEnd; ++D) |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3212 | LE.write<uint32_t>( |
| 3213 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3214 | } |
| 3215 | }; |
| 3216 | } // end anonymous namespace |
| 3217 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3218 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3219 | /// |
| 3220 | /// The identifier table consists of a blob containing string data |
| 3221 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3222 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3223 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3224 | IdentifierResolver &IdResolver, |
| 3225 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3226 | using namespace llvm; |
| 3227 | |
| 3228 | // Create and write out the blob that contains the identifier |
| 3229 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3230 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3231 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3232 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3233 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3234 | // Look for any identifiers that were named while processing the |
| 3235 | // headers, but are otherwise not needed. We add these to the hash |
| 3236 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3237 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3238 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3239 | SmallVector<const IdentifierInfo *, 128> IIs; |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3240 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 3241 | IDEnd = PP.getIdentifierTable().end(); |
| 3242 | ID != IDEnd; ++ID) |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3243 | IIs.push_back(ID->second); |
| 3244 | // Sort the identifiers lexicographically before getting them references so |
| 3245 | // that their order is stable. |
| 3246 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 3247 | for (const IdentifierInfo *II : IIs) |
| 3248 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3249 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3250 | // Create the on-disk hash table representation. We only store offsets |
| 3251 | // for identifiers that appear here for the first time. |
| 3252 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3253 | for (auto IdentIDPair : IdentifierIDs) { |
| 3254 | IdentifierInfo *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
| 3255 | IdentID ID = IdentIDPair.second; |
| 3256 | assert(II && "NULL identifier in identifier table"); |
| 3257 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 3258 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3259 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3260 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3261 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3262 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3263 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3264 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3265 | using namespace llvm::support; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3266 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3267 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3268 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3269 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | // Create a blob abbreviation |
| 3273 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3274 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3275 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3276 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3277 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3278 | |
| 3279 | // Write the identifier table |
| 3280 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3281 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3282 | Record.push_back(BucketOffset); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3283 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3287 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3288 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3289 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3290 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3291 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3292 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3293 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3294 | #ifndef NDEBUG |
| 3295 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3296 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3297 | #endif |
| 3298 | |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3299 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3300 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3301 | Record.push_back(IdentifierOffsets.size()); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3302 | Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3303 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3304 | bytes(IdentifierOffsets)); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3305 | } |
| 3306 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3307 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3308 | // DeclContext's Name Lookup Table Serialization |
| 3309 | //===----------------------------------------------------------------------===// |
| 3310 | |
| 3311 | namespace { |
| 3312 | // Trait used for the on-disk hash table used in the method pool. |
| 3313 | class ASTDeclContextNameLookupTrait { |
| 3314 | ASTWriter &Writer; |
| 3315 | |
| 3316 | public: |
| 3317 | typedef DeclarationName key_type; |
| 3318 | typedef key_type key_type_ref; |
| 3319 | |
| 3320 | typedef DeclContext::lookup_result data_type; |
| 3321 | typedef const data_type& data_type_ref; |
| 3322 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3323 | typedef unsigned hash_value_type; |
| 3324 | typedef unsigned offset_type; |
| 3325 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3326 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3327 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3328 | hash_value_type ComputeHash(DeclarationName Name) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3329 | llvm::FoldingSetNodeID ID; |
| 3330 | ID.AddInteger(Name.getNameKind()); |
| 3331 | |
| 3332 | switch (Name.getNameKind()) { |
| 3333 | case DeclarationName::Identifier: |
| 3334 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 3335 | break; |
| 3336 | case DeclarationName::ObjCZeroArgSelector: |
| 3337 | case DeclarationName::ObjCOneArgSelector: |
| 3338 | case DeclarationName::ObjCMultiArgSelector: |
| 3339 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 3340 | break; |
| 3341 | case DeclarationName::CXXConstructorName: |
| 3342 | case DeclarationName::CXXDestructorName: |
| 3343 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3344 | break; |
| 3345 | case DeclarationName::CXXOperatorName: |
| 3346 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 3347 | break; |
| 3348 | case DeclarationName::CXXLiteralOperatorName: |
| 3349 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 3350 | case DeclarationName::CXXUsingDirective: |
| 3351 | break; |
| 3352 | } |
| 3353 | |
| 3354 | return ID.ComputeHash(); |
| 3355 | } |
| 3356 | |
| 3357 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3358 | EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3359 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3360 | using namespace llvm::support; |
| 3361 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3362 | unsigned KeyLen = 1; |
| 3363 | switch (Name.getNameKind()) { |
| 3364 | case DeclarationName::Identifier: |
| 3365 | case DeclarationName::ObjCZeroArgSelector: |
| 3366 | case DeclarationName::ObjCOneArgSelector: |
| 3367 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3368 | case DeclarationName::CXXLiteralOperatorName: |
| 3369 | KeyLen += 4; |
| 3370 | break; |
| 3371 | case DeclarationName::CXXOperatorName: |
| 3372 | KeyLen += 1; |
| 3373 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3374 | case DeclarationName::CXXConstructorName: |
| 3375 | case DeclarationName::CXXDestructorName: |
| 3376 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3377 | case DeclarationName::CXXUsingDirective: |
| 3378 | break; |
| 3379 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3380 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3381 | |
| 3382 | // 2 bytes for num of decls and 4 for each DeclID. |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3383 | unsigned DataLen = 2 + 4 * Lookup.size(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3384 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3385 | |
| 3386 | return std::make_pair(KeyLen, DataLen); |
| 3387 | } |
| 3388 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3389 | void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3390 | using namespace llvm::support; |
| 3391 | endian::Writer<little> LE(Out); |
| 3392 | LE.write<uint8_t>(Name.getNameKind()); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3393 | switch (Name.getNameKind()) { |
| 3394 | case DeclarationName::Identifier: |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3395 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3396 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3397 | case DeclarationName::ObjCZeroArgSelector: |
| 3398 | case DeclarationName::ObjCOneArgSelector: |
| 3399 | case DeclarationName::ObjCMultiArgSelector: |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3400 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getObjCSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3401 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3402 | case DeclarationName::CXXOperatorName: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3403 | assert(Name.getCXXOverloadedOperator() < NUM_OVERLOADED_OPERATORS && |
| 3404 | "Invalid operator?"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3405 | LE.write<uint8_t>(Name.getCXXOverloadedOperator()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3406 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3407 | case DeclarationName::CXXLiteralOperatorName: |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3408 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3409 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3410 | case DeclarationName::CXXConstructorName: |
| 3411 | case DeclarationName::CXXDestructorName: |
| 3412 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3413 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3414 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3415 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3416 | |
| 3417 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3418 | } |
| 3419 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3420 | void EmitData(raw_ostream& Out, key_type_ref, |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3421 | data_type Lookup, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3422 | using namespace llvm::support; |
| 3423 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3424 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3425 | LE.write<uint16_t>(Lookup.size()); |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3426 | for (DeclContext::lookup_iterator I = Lookup.begin(), E = Lookup.end(); |
| 3427 | I != E; ++I) |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3428 | LE.write<uint32_t>( |
| 3429 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), *I))); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3430 | |
| 3431 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3432 | } |
| 3433 | }; |
| 3434 | } // end anonymous namespace |
| 3435 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3436 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3437 | DeclContext *DC) { |
| 3438 | return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage; |
| 3439 | } |
| 3440 | |
| 3441 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3442 | DeclContext *DC) { |
| 3443 | for (auto *D : Result.getLookupResult()) |
| 3444 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3445 | return false; |
| 3446 | |
| 3447 | return true; |
| 3448 | } |
| 3449 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3450 | uint32_t |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3451 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3452 | llvm::SmallVectorImpl<char> &LookupTable) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3453 | assert(!ConstDC->HasLazyLocalLexicalLookups && |
| 3454 | !ConstDC->HasLazyExternalLexicalLookups && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3455 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3456 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3457 | // FIXME: We need to build the lookups table, which is logically const. |
| 3458 | DeclContext *DC = const_cast<DeclContext*>(ConstDC); |
| 3459 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3460 | |
| 3461 | // Create the on-disk hash table representation. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3462 | llvm::OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> |
| 3463 | Generator; |
| 3464 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3465 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3466 | // The first step is to collect the declaration names which we need to |
| 3467 | // serialize into the name lookup table, and to collect them in a stable |
| 3468 | // order. |
| 3469 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3470 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3471 | // We also build up small sets of the constructor and conversion function |
| 3472 | // names which are visible. |
| 3473 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3474 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3475 | for (auto &Lookup : *DC->buildLookup()) { |
| 3476 | auto &Name = Lookup.first; |
| 3477 | auto &Result = Lookup.second; |
| 3478 | |
| 3479 | // If there are no local declarations in our lookup result, we don't |
| 3480 | // need to write an entry for the name at all unless we're rewriting |
| 3481 | // the decl context. If we can't write out a lookup set without |
| 3482 | // performing more deserialization, just skip this entry. |
| 3483 | if (isLookupResultExternal(Result, DC) && !isRewritten(cast<Decl>(DC)) && |
| 3484 | isLookupResultEntirelyExternal(Result, DC)) |
| 3485 | continue; |
| 3486 | |
| 3487 | // We also skip empty results. If any of the results could be external and |
| 3488 | // the currently available results are empty, then all of the results are |
| 3489 | // external and we skip it above. So the only way we get here with an empty |
| 3490 | // results is when no results could have been external *and* we have |
| 3491 | // external results. |
| 3492 | // |
| 3493 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 3494 | // lookups into a decl context as an optimization, today we *have* to skip |
| 3495 | // them because there are names with empty lookup results in decl contexts |
| 3496 | // which we can't emit in any stable ordering: we lookup constructors and |
| 3497 | // conversion functions in the enclosing namespace scope creating empty |
| 3498 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 3499 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 3500 | // here by omitting lookups with empty results. |
| 3501 | if (Lookup.second.getLookupResult().empty()) |
| 3502 | continue; |
| 3503 | |
| 3504 | switch (Lookup.first.getNameKind()) { |
| 3505 | default: |
| 3506 | Names.push_back(Lookup.first); |
| 3507 | break; |
| 3508 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3509 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3510 | assert(isa<CXXRecordDecl>(DC) && |
| 3511 | "Cannot have a constructor name outside of a class!"); |
| 3512 | ConstructorNameSet.insert(Name); |
| 3513 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3514 | |
| 3515 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3516 | assert(isa<CXXRecordDecl>(DC) && |
| 3517 | "Cannot have a conversion function name outside of a class!"); |
| 3518 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3519 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3520 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3521 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3522 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3523 | // Sort the names into a stable order. |
| 3524 | std::sort(Names.begin(), Names.end()); |
| 3525 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3526 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3527 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3528 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3529 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3530 | // First we try the easy case by forming the current context's constructor |
| 3531 | // name and adding that name first. This is a very useful optimization to |
| 3532 | // avoid walking the lexical declarations in many cases, and it also |
| 3533 | // handles the only case where a constructor name can come from some other |
| 3534 | // lexical context -- when that name is an implicit constructor merged from |
| 3535 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 3536 | // conversion function which doesn't occur in all the lexical contexts |
| 3537 | // would be an ODR violation. |
| 3538 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 3539 | Context->getCanonicalType(Context->getRecordType(D))); |
| 3540 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 3541 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3542 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3543 | // If we still have constructors or conversion functions, we walk all the |
| 3544 | // names in the decl and add the constructors and conversion functions |
| 3545 | // which are visible in the order they lexically occur within the context. |
| 3546 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 3547 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 3548 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 3549 | auto Name = ChildND->getDeclName(); |
| 3550 | switch (Name.getNameKind()) { |
| 3551 | default: |
| 3552 | continue; |
| 3553 | |
| 3554 | case DeclarationName::CXXConstructorName: |
| 3555 | if (ConstructorNameSet.erase(Name)) |
| 3556 | Names.push_back(Name); |
| 3557 | break; |
| 3558 | |
| 3559 | case DeclarationName::CXXConversionFunctionName: |
| 3560 | if (ConversionNameSet.erase(Name)) |
| 3561 | Names.push_back(Name); |
| 3562 | break; |
| 3563 | } |
| 3564 | |
| 3565 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 3566 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3567 | } |
| 3568 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3569 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 3570 | "constructors by walking all the " |
| 3571 | "lexical members of the context."); |
| 3572 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 3573 | "conversion functions by walking all " |
| 3574 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3575 | } |
| 3576 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3577 | // Next we need to do a lookup with each name into this decl context to fully |
| 3578 | // populate any results from external sources. We don't actually use the |
| 3579 | // results of these lookups because we only want to use the results after all |
| 3580 | // results have been loaded and the pointers into them will be stable. |
| 3581 | for (auto &Name : Names) |
| 3582 | DC->lookup(Name); |
| 3583 | |
| 3584 | // Now we need to insert the results for each name into the hash table. For |
| 3585 | // constructor names and conversion function names, we actually need to merge |
| 3586 | // all of the results for them into one list of results each and insert |
| 3587 | // those. |
| 3588 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 3589 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 3590 | |
| 3591 | // Now loop over the names, either inserting them or appending for the two |
| 3592 | // special cases. |
| 3593 | for (auto &Name : Names) { |
| 3594 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 3595 | |
| 3596 | switch (Name.getNameKind()) { |
| 3597 | default: |
| 3598 | Generator.insert(Name, Result, Trait); |
| 3599 | break; |
| 3600 | |
| 3601 | case DeclarationName::CXXConstructorName: |
| 3602 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 3603 | break; |
| 3604 | |
| 3605 | case DeclarationName::CXXConversionFunctionName: |
| 3606 | ConversionDecls.append(Result.begin(), Result.end()); |
| 3607 | break; |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 3612 | // the first declaration's name here because the name itself isn't part of |
| 3613 | // the key, only the kind of name is used. |
| 3614 | if (!ConstructorDecls.empty()) |
| 3615 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
| 3616 | DeclContext::lookup_result(ConstructorDecls), Trait); |
| 3617 | if (!ConversionDecls.empty()) |
| 3618 | Generator.insert(ConversionDecls.front()->getDeclName(), |
| 3619 | DeclContext::lookup_result(ConversionDecls), Trait); |
| 3620 | |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3621 | // Create the on-disk hash table in a buffer. |
| 3622 | llvm::raw_svector_ostream Out(LookupTable); |
| 3623 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3624 | using namespace llvm::support; |
| 3625 | endian::Writer<little>(Out).write<uint32_t>(0); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3626 | return Generator.Emit(Out, Trait); |
| 3627 | } |
| 3628 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3629 | /// \brief Write the block containing all of the declaration IDs |
| 3630 | /// visible from the given DeclContext. |
| 3631 | /// |
| 3632 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3633 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3634 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3635 | DeclContext *DC) { |
| 3636 | if (DC->getPrimaryContext() != DC) |
| 3637 | return 0; |
| 3638 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3639 | // Skip contexts which don't support name lookup. |
| 3640 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3641 | return 0; |
| 3642 | |
| 3643 | // If not in C++, we perform name lookup for the translation unit via the |
| 3644 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3645 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3646 | return 0; |
| 3647 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3648 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3649 | // although we have two very different code paths, the serialized |
| 3650 | // representation is the same for both cases: a declaration name, |
| 3651 | // followed by a size, followed by references to the visible |
| 3652 | // declarations that have that name. |
| 3653 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3654 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3655 | if (!Map || Map->empty()) |
| 3656 | return 0; |
| 3657 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3658 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3659 | SmallString<4096> LookupTable; |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3660 | uint32_t BucketOffset = GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3661 | |
| 3662 | // Write the lookup table |
| 3663 | RecordData Record; |
| 3664 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 3665 | Record.push_back(BucketOffset); |
| 3666 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3667 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3668 | ++NumVisibleDeclContexts; |
| 3669 | return Offset; |
| 3670 | } |
| 3671 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3672 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3673 | /// |
| 3674 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3675 | /// DeclContext in a dependent AST file. As such, they only exist for the TU |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3676 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3677 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3678 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3679 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3680 | if (!Map || Map->empty()) |
| 3681 | return; |
| 3682 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3683 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3684 | SmallString<4096> LookupTable; |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3685 | uint32_t BucketOffset = GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3686 | |
| 3687 | // Write the lookup table |
| 3688 | RecordData Record; |
| 3689 | Record.push_back(UPDATE_VISIBLE); |
| 3690 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 3691 | Record.push_back(BucketOffset); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3692 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3693 | } |
| 3694 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3695 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3696 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 3697 | RecordData Record; |
| 3698 | Record.push_back(Opts.fp_contract); |
| 3699 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3700 | } |
| 3701 | |
| 3702 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3703 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3704 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3705 | return; |
| 3706 | |
| 3707 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3708 | RecordData Record; |
| 3709 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3710 | #include "clang/Basic/OpenCLExtensions.def" |
| 3711 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3712 | } |
| 3713 | |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3714 | void ASTWriter::WriteRedeclarations() { |
| 3715 | RecordData LocalRedeclChains; |
| 3716 | SmallVector<serialization::LocalRedeclarationsInfo, 2> LocalRedeclsMap; |
| 3717 | |
| 3718 | for (unsigned I = 0, N = Redeclarations.size(); I != N; ++I) { |
| 3719 | Decl *First = Redeclarations[I]; |
Rafael Espindola | 3f9e444 | 2013-10-19 02:13:21 +0000 | [diff] [blame] | 3720 | assert(First->isFirstDecl() && "Not the first declaration?"); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3721 | |
| 3722 | Decl *MostRecent = First->getMostRecentDecl(); |
| 3723 | |
| 3724 | // If we only have a single declaration, there is no point in storing |
| 3725 | // a redeclaration chain. |
| 3726 | if (First == MostRecent) |
| 3727 | continue; |
| 3728 | |
| 3729 | unsigned Offset = LocalRedeclChains.size(); |
| 3730 | unsigned Size = 0; |
| 3731 | LocalRedeclChains.push_back(0); // Placeholder for the size. |
| 3732 | |
| 3733 | // Collect the set of local redeclarations of this declaration. |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3734 | for (Decl *Prev = MostRecent; Prev != First; |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3735 | Prev = Prev->getPreviousDecl()) { |
| 3736 | if (!Prev->isFromASTFile()) { |
| 3737 | AddDeclRef(Prev, LocalRedeclChains); |
| 3738 | ++Size; |
| 3739 | } |
| 3740 | } |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3741 | |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3742 | LocalRedeclChains[Offset] = Size; |
| 3743 | |
| 3744 | // Reverse the set of local redeclarations, so that we store them in |
| 3745 | // order (since we found them in reverse order). |
| 3746 | std::reverse(LocalRedeclChains.end() - Size, LocalRedeclChains.end()); |
| 3747 | |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3748 | // Add the mapping from the first ID from the AST to the set of local |
| 3749 | // declarations. |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3750 | LocalRedeclarationsInfo Info = { getDeclID(First), Offset }; |
| 3751 | LocalRedeclsMap.push_back(Info); |
| 3752 | |
| 3753 | assert(N == Redeclarations.size() && |
| 3754 | "Deserialized a declaration we shouldn't have"); |
| 3755 | } |
| 3756 | |
| 3757 | if (LocalRedeclChains.empty()) |
| 3758 | return; |
| 3759 | |
| 3760 | // Sort the local redeclarations map by the first declaration ID, |
| 3761 | // since the reader will be performing binary searches on this information. |
| 3762 | llvm::array_pod_sort(LocalRedeclsMap.begin(), LocalRedeclsMap.end()); |
| 3763 | |
| 3764 | // Emit the local redeclarations map. |
| 3765 | using namespace llvm; |
| 3766 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3767 | Abbrev->Add(BitCodeAbbrevOp(LOCAL_REDECLARATIONS_MAP)); |
| 3768 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3769 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3770 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3771 | |
| 3772 | RecordData Record; |
| 3773 | Record.push_back(LOCAL_REDECLARATIONS_MAP); |
| 3774 | Record.push_back(LocalRedeclsMap.size()); |
| 3775 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3776 | reinterpret_cast<char*>(LocalRedeclsMap.data()), |
| 3777 | LocalRedeclsMap.size() * sizeof(LocalRedeclarationsInfo)); |
| 3778 | |
| 3779 | // Emit the redeclaration chains. |
| 3780 | Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedeclChains); |
| 3781 | } |
| 3782 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3783 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3784 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3785 | RecordData Categories; |
| 3786 | |
| 3787 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3788 | unsigned Size = 0; |
| 3789 | unsigned StartIndex = Categories.size(); |
| 3790 | |
| 3791 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3792 | |
| 3793 | // Allocate space for the size. |
| 3794 | Categories.push_back(0); |
| 3795 | |
| 3796 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3797 | for (ObjCInterfaceDecl::known_categories_iterator |
| 3798 | Cat = Class->known_categories_begin(), |
| 3799 | CatEnd = Class->known_categories_end(); |
| 3800 | Cat != CatEnd; ++Cat, ++Size) { |
| 3801 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 3802 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | // Update the size. |
| 3806 | Categories[StartIndex] = Size; |
| 3807 | |
| 3808 | // Record this interface -> category map. |
| 3809 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3810 | CategoriesMap.push_back(CatInfo); |
| 3811 | } |
| 3812 | |
| 3813 | // Sort the categories map by the definition ID, since the reader will be |
| 3814 | // performing binary searches on this information. |
| 3815 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3816 | |
| 3817 | // Emit the categories map. |
| 3818 | using namespace llvm; |
| 3819 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3820 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3821 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3822 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3823 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3824 | |
| 3825 | RecordData Record; |
| 3826 | Record.push_back(OBJC_CATEGORIES_MAP); |
| 3827 | Record.push_back(CategoriesMap.size()); |
| 3828 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3829 | reinterpret_cast<char*>(CategoriesMap.data()), |
| 3830 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
| 3831 | |
| 3832 | // Emit the category lists. |
| 3833 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3834 | } |
| 3835 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3836 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 3837 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 3838 | |
| 3839 | if (LPTMap.empty()) |
| 3840 | return; |
| 3841 | |
| 3842 | RecordData Record; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 3843 | for (auto LPTMapEntry : LPTMap) { |
| 3844 | const FunctionDecl *FD = LPTMapEntry.first; |
| 3845 | LateParsedTemplate *LPT = LPTMapEntry.second; |
| 3846 | AddDeclRef(FD, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3847 | AddDeclRef(LPT->D, Record); |
| 3848 | Record.push_back(LPT->Toks.size()); |
| 3849 | |
| 3850 | for (CachedTokens::iterator TokIt = LPT->Toks.begin(), |
| 3851 | TokEnd = LPT->Toks.end(); |
| 3852 | TokIt != TokEnd; ++TokIt) { |
| 3853 | AddToken(*TokIt, Record); |
| 3854 | } |
| 3855 | } |
| 3856 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 3857 | } |
| 3858 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3859 | /// \brief Write the state of 'pragma clang optimize' at the end of the module. |
| 3860 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 3861 | RecordData Record; |
| 3862 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 3863 | AddSourceLocation(PragmaLoc, Record); |
| 3864 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 3865 | } |
| 3866 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3867 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3868 | // General Serialization Routines |
| 3869 | //===----------------------------------------------------------------------===// |
| 3870 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3871 | /// \brief Write a record containing the given attributes. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3872 | void ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, |
| 3873 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3874 | Record.push_back(Attrs.size()); |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3875 | for (ArrayRef<const Attr *>::iterator i = Attrs.begin(), |
| 3876 | e = Attrs.end(); i != e; ++i){ |
| 3877 | const Attr *A = *i; |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3878 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 309b4c4 | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 3879 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3880 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3881 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3882 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3883 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3884 | } |
| 3885 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 3886 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 3887 | AddSourceLocation(Tok.getLocation(), Record); |
| 3888 | Record.push_back(Tok.getLength()); |
| 3889 | |
| 3890 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 3891 | // if it is needed. |
| 3892 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 3893 | // FIXME: Should translate token kind to a stable encoding. |
| 3894 | Record.push_back(Tok.getKind()); |
| 3895 | // FIXME: Should translate token flags to a stable encoding. |
| 3896 | Record.push_back(Tok.getFlags()); |
| 3897 | } |
| 3898 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3899 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3900 | Record.push_back(Str.size()); |
| 3901 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 3902 | } |
| 3903 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3904 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 3905 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3906 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 3907 | bool Changed = |
| 3908 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3909 | |
| 3910 | // Remove a prefix to make the path relative, if relevant. |
| 3911 | const char *PathBegin = Path.data(); |
| 3912 | const char *PathPtr = |
| 3913 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 3914 | if (PathPtr != PathBegin) { |
| 3915 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 3916 | Changed = true; |
| 3917 | } |
| 3918 | |
| 3919 | return Changed; |
| 3920 | } |
| 3921 | |
| 3922 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 3923 | SmallString<128> FilePath(Path); |
| 3924 | PreparePathForOutput(FilePath); |
| 3925 | AddString(FilePath, Record); |
| 3926 | } |
| 3927 | |
| 3928 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataImpl &Record, |
| 3929 | StringRef Path) { |
| 3930 | SmallString<128> FilePath(Path); |
| 3931 | PreparePathForOutput(FilePath); |
| 3932 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 3933 | } |
| 3934 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3935 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 3936 | RecordDataImpl &Record) { |
| 3937 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3938 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3939 | Record.push_back(*Minor + 1); |
| 3940 | else |
| 3941 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3942 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3943 | Record.push_back(*Subminor + 1); |
| 3944 | else |
| 3945 | Record.push_back(0); |
| 3946 | } |
| 3947 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3948 | /// \brief Note that the identifier II occurs at the given offset |
| 3949 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3950 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3951 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3952 | // Only store offsets new to this AST file. Other identifier names are looked |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3953 | // up earlier in the chain and thus don't need an offset. |
| 3954 | if (ID >= FirstIdentID) |
| 3955 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3956 | } |
| 3957 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3958 | /// \brief Note that the selector Sel occurs at the given offset |
| 3959 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3960 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3961 | unsigned ID = SelectorIDs[Sel]; |
| 3962 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3963 | // Don't record offsets for selectors that are also available in a different |
| 3964 | // file. |
| 3965 | if (ID < FirstSelectorID) |
| 3966 | return; |
| 3967 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3970 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 3971 | : Stream(Stream), Context(nullptr), PP(nullptr), Chain(nullptr), |
| 3972 | WritingModule(nullptr), WritingAST(false), |
| 3973 | DoneWritingDeclsAndTypes(false), ASTHasCompilerErrors(false), |
| 3974 | FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), |
| 3975 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
| 3976 | FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), |
| 3977 | FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID), |
| 3978 | FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
| 3979 | NextSubmoduleID(FirstSubmoduleID), |
| 3980 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
| 3981 | CollectedStmts(&StmtsToEmit), NumStatements(0), NumMacros(0), |
| 3982 | NumLexicalDeclContexts(0), NumVisibleDeclContexts(0), |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3983 | NextCXXBaseSpecifiersID(1), NextCXXCtorInitializersID(1), |
| 3984 | TypeExtQualAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 3985 | TypeFunctionProtoAbbrev(0), DeclParmVarAbbrev(0), |
| 3986 | DeclContextLexicalAbbrev(0), DeclContextVisibleLookupAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 3987 | UpdateVisibleAbbrev(0), DeclRecordAbbrev(0), DeclTypedefAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 3988 | DeclVarAbbrev(0), DeclFieldAbbrev(0), DeclEnumAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 3989 | DeclObjCIvarAbbrev(0), DeclCXXMethodAbbrev(0), DeclRefExprAbbrev(0), |
| 3990 | CharacterLiteralAbbrev(0), IntegerLiteralAbbrev(0), |
| 3991 | ExprImplicitCastAbbrev(0) {} |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3992 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3993 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 3994 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3995 | } |
| 3996 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3997 | const LangOptions &ASTWriter::getLangOpts() const { |
| 3998 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 3999 | return Context->getLangOpts(); |
| 4000 | } |
| 4001 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 4002 | void ASTWriter::WriteAST(Sema &SemaRef, |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 4003 | const std::string &OutputFile, |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4004 | Module *WritingModule, StringRef isysroot, |
| 4005 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4006 | WritingAST = true; |
| 4007 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4008 | ASTHasCompilerErrors = hasErrors; |
| 4009 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4010 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4011 | Stream.Emit((unsigned)'C', 8); |
| 4012 | Stream.Emit((unsigned)'P', 8); |
| 4013 | Stream.Emit((unsigned)'C', 8); |
| 4014 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4015 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4016 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4017 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4018 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4019 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4020 | this->WritingModule = WritingModule; |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 4021 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4022 | Context = nullptr; |
| 4023 | PP = nullptr; |
| 4024 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4025 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4026 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4027 | WritingAST = false; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4028 | } |
| 4029 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4030 | template<typename Vector> |
| 4031 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4032 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4033 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4034 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4035 | Writer.AddDeclRef(*I, Record); |
| 4036 | } |
| 4037 | } |
| 4038 | |
Argyrios Kyrtzidis | d7c16b2 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 4039 | void ASTWriter::WriteASTCore(Sema &SemaRef, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 4040 | StringRef isysroot, |
Douglas Gregor | f7a700fd | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 4041 | const std::string &OutputFile, |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4042 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4043 | using namespace llvm; |
| 4044 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4045 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4046 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4047 | // Make sure that the AST reader knows to finalize itself. |
| 4048 | if (Chain) |
| 4049 | Chain->finalizeForWriting(); |
| 4050 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4051 | ASTContext &Context = SemaRef.Context; |
| 4052 | Preprocessor &PP = SemaRef.PP; |
| 4053 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4054 | // Set up predefined declaration IDs. |
| 4055 | DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; |
Douglas Gregor | 3ea7269 | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4056 | if (Context.ObjCIdDecl) |
| 4057 | DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID; |
Douglas Gregor | 52e0280 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4058 | if (Context.ObjCSelDecl) |
| 4059 | DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4060 | if (Context.ObjCClassDecl) |
| 4061 | DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; |
Douglas Gregor | d53ae83 | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 4062 | if (Context.ObjCProtocolClassDecl) |
| 4063 | DeclIDs[Context.ObjCProtocolClassDecl] = PREDEF_DECL_OBJC_PROTOCOL_ID; |
Douglas Gregor | 801c99d | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4064 | if (Context.Int128Decl) |
| 4065 | DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; |
| 4066 | if (Context.UInt128Decl) |
| 4067 | DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; |
Douglas Gregor | bab8a96 | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 4068 | if (Context.ObjCInstanceTypeDecl) |
| 4069 | DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID; |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4070 | if (Context.BuiltinVaListDecl) |
| 4071 | DeclIDs[Context.getBuiltinVaListDecl()] = PREDEF_DECL_BUILTIN_VA_LIST_ID; |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4072 | if (Context.ExternCContext) |
| 4073 | DeclIDs[Context.ExternCContext] = PREDEF_DECL_EXTERN_C_CONTEXT_ID; |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4074 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4075 | // Build a record containing all of the tentative definitions in this file, in |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4076 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4077 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4078 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4079 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4080 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4081 | // Build a record containing all of the file scoped decls in this file. |
| 4082 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4083 | if (!isModule) |
| 4084 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4085 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4086 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4087 | // Build a record containing all of the delegating constructors we still need |
| 4088 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4089 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4090 | if (!isModule) |
| 4091 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4092 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4093 | // Write the set of weak, undeclared identifiers. We always write the |
| 4094 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4095 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4096 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4097 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4098 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4099 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4100 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4101 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4102 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4103 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4104 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4105 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4106 | // Build a record containing all of the ext_vector declarations. |
| 4107 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4108 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4109 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4110 | // Build a record containing all of the VTable uses information. |
| 4111 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4112 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4113 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4114 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4115 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4116 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4117 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4120 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4121 | RecordData UnusedLocalTypedefNameCandidates; |
| 4122 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4123 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4124 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4125 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4126 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4127 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4128 | I = SemaRef.PendingInstantiations.begin(), |
| 4129 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 4130 | AddDeclRef(I->first, PendingInstantiations); |
| 4131 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4132 | } |
| 4133 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4134 | "There are local ones at end of translation unit!"); |
| 4135 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4136 | // Build a record containing some declaration references. |
| 4137 | RecordData SemaDeclRefs; |
| 4138 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 4139 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4140 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 4141 | } |
| 4142 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4143 | RecordData CUDASpecialDeclRefs; |
| 4144 | if (Context.getcudaConfigureCallDecl()) { |
| 4145 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4146 | } |
| 4147 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4148 | // Build a record containing all of the known namespaces. |
| 4149 | RecordData KnownNamespaces; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4150 | for (llvm::MapVector<NamespaceDecl*, bool>::iterator |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4151 | I = SemaRef.KnownNamespaces.begin(), |
| 4152 | IEnd = SemaRef.KnownNamespaces.end(); |
| 4153 | I != IEnd; ++I) { |
| 4154 | if (!I->second) |
| 4155 | AddDeclRef(I->first, KnownNamespaces); |
| 4156 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4157 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4158 | // Build a record of all used, undefined objects that require definitions. |
| 4159 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4160 | |
| 4161 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4162 | SemaRef.getUndefinedButUsed(Undefined); |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4163 | for (SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> >::iterator |
| 4164 | I = Undefined.begin(), E = Undefined.end(); I != E; ++I) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4165 | AddDeclRef(I->first, UndefinedButUsed); |
| 4166 | AddSourceLocation(I->second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4169 | // Build a record containing all delete-expressions that we would like to |
| 4170 | // analyze later in AST. |
| 4171 | RecordData DeleteExprsToAnalyze; |
| 4172 | |
| 4173 | for (const auto &DeleteExprsInfo : |
| 4174 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4175 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4176 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4177 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4178 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4179 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4180 | } |
| 4181 | } |
| 4182 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4183 | // Write the control block |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 4184 | WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4185 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4186 | // Write the remaining AST contents. |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4187 | RecordData Record; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4188 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4189 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4190 | // This is so that older clang versions, before the introduction |
| 4191 | // of the control block, can read and reject the newer PCH format. |
| 4192 | Record.clear(); |
| 4193 | Record.push_back(VERSION_MAJOR); |
| 4194 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4195 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4196 | // Create a lexical update block containing all of the declarations in the |
| 4197 | // translation unit that do not come from other AST files. |
| 4198 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
| 4199 | SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 4200 | for (const auto *I : TU->noload_decls()) { |
| 4201 | if (!I->isFromASTFile()) |
| 4202 | NewGlobalDecls.push_back(std::make_pair(I->getKind(), GetDeclRef(I))); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4203 | } |
| 4204 | |
| 4205 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 4206 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4207 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4208 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 4209 | Record.clear(); |
| 4210 | Record.push_back(TU_UPDATE_LEXICAL); |
| 4211 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 4212 | bytes(NewGlobalDecls)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4213 | |
| 4214 | // And a visible updates block for the translation unit. |
| 4215 | Abv = new llvm::BitCodeAbbrev(); |
| 4216 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4217 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4218 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 4219 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4220 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 4221 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4222 | |
| 4223 | // If we have any extern "C" names, write out a visible update for them. |
| 4224 | if (Context.ExternCContext) |
| 4225 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4226 | |
| 4227 | // If the translation unit has an anonymous namespace, and we don't already |
| 4228 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4229 | // FIXME: Why do we not do this if there's already an update block? |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4230 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4231 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4232 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4233 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4234 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4235 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4236 | // Add update records for all mangling numbers and static local numbers. |
| 4237 | // These aren't really update records, but this is a convenient way of |
| 4238 | // tagging this rare extra data onto the declarations. |
| 4239 | for (const auto &Number : Context.MangleNumbers) |
| 4240 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4241 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4242 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4243 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4244 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4245 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4246 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4247 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4248 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 4249 | // an AST file, are registered for serialization. |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 4250 | for (SmallVectorImpl<const Decl *>::iterator |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4251 | I = UpdatingVisibleDecls.begin(), |
| 4252 | E = UpdatingVisibleDecls.end(); I != E; ++I) { |
| 4253 | GetDeclRef(*I); |
| 4254 | } |
| 4255 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4256 | // Make sure all decls associated with an identifier are registered for |
| 4257 | // serialization. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 4258 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4259 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 4260 | IDEnd = PP.getIdentifierTable().end(); |
| 4261 | ID != IDEnd; ++ID) { |
| 4262 | const IdentifierInfo *II = ID->second; |
Richard Smith | 9ab4cce | 2015-03-11 00:00:51 +0000 | [diff] [blame] | 4263 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 4264 | IIs.push_back(II); |
Richard Smith | 9ab4cce | 2015-03-11 00:00:51 +0000 | [diff] [blame] | 4265 | } |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 4266 | // Sort the identifiers to visit based on their name. |
| 4267 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 4268 | for (const IdentifierInfo *II : IIs) { |
Richard Smith | 9ab4cce | 2015-03-11 00:00:51 +0000 | [diff] [blame] | 4269 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4270 | DEnd = SemaRef.IdResolver.end(); |
| 4271 | D != DEnd; ++D) { |
| 4272 | GetDeclRef(*D); |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4273 | } |
| 4274 | } |
| 4275 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4276 | // Form the record of special types. |
| 4277 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4278 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4279 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4280 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4281 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4282 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4283 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4284 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4285 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4286 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4287 | if (Chain) { |
| 4288 | // Write the mapping information describing our module dependencies and how |
| 4289 | // each of those modules were mapped into our own offset/ID space, so that |
| 4290 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4291 | // The map consists solely of a blob with the following format: |
| 4292 | // *(module-name-len:i16 module-name:len*i8 |
| 4293 | // source-location-offset:i32 |
| 4294 | // identifier-id:i32 |
| 4295 | // preprocessed-entity-id:i32 |
| 4296 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4297 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4298 | // selector-id:i32 |
| 4299 | // declaration-id:i32 |
| 4300 | // c++-base-specifiers-id:i32 |
| 4301 | // type-id:i32) |
| 4302 | // |
| 4303 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 4304 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4305 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 4306 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4307 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4308 | { |
| 4309 | llvm::raw_svector_ostream Out(Buffer); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4310 | for (ModuleFile *M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4311 | using namespace llvm::support; |
| 4312 | endian::Writer<little> LE(Out); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4313 | StringRef FileName = M->FileName; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4314 | LE.write<uint16_t>(FileName.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4315 | Out.write(FileName.data(), FileName.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4316 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4317 | // Note: if a base ID was uint max, it would not be possible to load |
| 4318 | // another module after it or have more than one entity inside it. |
| 4319 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4320 | |
| 4321 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4322 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4323 | if (ShouldWrite) |
| 4324 | LE.write<uint32_t>(BaseID); |
| 4325 | else |
| 4326 | LE.write<uint32_t>(None); |
| 4327 | }; |
| 4328 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4329 | // These values should be unique within a chain, since they will be read |
| 4330 | // as keys into ContinuousRangeMaps. |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4331 | writeBaseIDOrNone(M->SLocEntryBaseOffset, M->LocalNumSLocEntries); |
| 4332 | writeBaseIDOrNone(M->BaseIdentifierID, M->LocalNumIdentifiers); |
| 4333 | writeBaseIDOrNone(M->BaseMacroID, M->LocalNumMacros); |
| 4334 | writeBaseIDOrNone(M->BasePreprocessedEntityID, |
| 4335 | M->NumPreprocessedEntities); |
| 4336 | writeBaseIDOrNone(M->BaseSubmoduleID, M->LocalNumSubmodules); |
| 4337 | writeBaseIDOrNone(M->BaseSelectorID, M->LocalNumSelectors); |
| 4338 | writeBaseIDOrNone(M->BaseDeclID, M->LocalNumDecls); |
| 4339 | writeBaseIDOrNone(M->BaseTypeIndex, M->LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | Record.clear(); |
| 4343 | Record.push_back(MODULE_OFFSET_MAP); |
| 4344 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4345 | Buffer.data(), Buffer.size()); |
| 4346 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4347 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4348 | RecordData DeclUpdatesOffsetsRecord; |
| 4349 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4350 | // Keep writing types, declarations, and declaration update records |
| 4351 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4352 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4353 | WriteTypeAbbrevs(); |
| 4354 | WriteDeclAbbrevs(); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4355 | for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), |
| 4356 | E = DeclsToRewrite.end(); |
| 4357 | I != E; ++I) |
| 4358 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4359 | do { |
| 4360 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4361 | while (!DeclTypesToEmit.empty()) { |
| 4362 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4363 | DeclTypesToEmit.pop(); |
| 4364 | if (DOT.isType()) |
| 4365 | WriteType(DOT.getType()); |
| 4366 | else |
| 4367 | WriteDecl(Context, DOT.getDecl()); |
| 4368 | } |
| 4369 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4370 | Stream.ExitBlock(); |
| 4371 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4372 | DoneWritingDeclsAndTypes = true; |
| 4373 | |
| 4374 | // These things can only be done once we've written out decls and types. |
| 4375 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4376 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 4377 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4378 | WriteCXXBaseSpecifiersOffsets(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4379 | WriteCXXCtorInitializersOffsets(); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4380 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4381 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4382 | |
| 4383 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4384 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4385 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4386 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4387 | WriteReferencedSelectorsPool(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4388 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4389 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4390 | WriteOpenCLExtensions(SemaRef); |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 4391 | WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4392 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4393 | // If we're emitting a module, write out the submodule information. |
| 4394 | if (WritingModule) |
| 4395 | WriteSubmodules(WritingModule); |
| 4396 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4397 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4398 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4399 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4400 | if (!EagerlyDeserializedDecls.empty()) |
| 4401 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4402 | |
| 4403 | // Write the record containing tentative definitions. |
| 4404 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4405 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4406 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4407 | // Write the record containing unused file scoped decls. |
| 4408 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4409 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4410 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4411 | // Write the record containing weak undeclared identifiers. |
| 4412 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4413 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4414 | WeakUndeclaredIdentifiers); |
| 4415 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4416 | // Write the record containing ext_vector type names. |
| 4417 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4418 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4419 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4420 | // Write the record containing VTable uses information. |
| 4421 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4422 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4423 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4424 | // Write the record containing potentially unused local typedefs. |
| 4425 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 4426 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 4427 | UnusedLocalTypedefNameCandidates); |
| 4428 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4429 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4430 | if (!PendingInstantiations.empty()) |
| 4431 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4432 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4433 | // Write the record containing declaration references of Sema. |
| 4434 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4435 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4436 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4437 | // Write the record containing CUDA-specific declaration references. |
| 4438 | if (!CUDASpecialDeclRefs.empty()) |
| 4439 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4440 | |
| 4441 | // Write the delegating constructors. |
| 4442 | if (!DelegatingCtorDecls.empty()) |
| 4443 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4444 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4445 | // Write the known namespaces. |
| 4446 | if (!KnownNamespaces.empty()) |
| 4447 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4448 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4449 | // Write the undefined internal functions and variables, and inline functions. |
| 4450 | if (!UndefinedButUsed.empty()) |
| 4451 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4452 | |
| 4453 | if (!DeleteExprsToAnalyze.empty()) |
| 4454 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 4455 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4456 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4457 | for (auto *DC : UpdatedDeclContexts) |
| 4458 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4459 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4460 | if (!WritingModule) { |
| 4461 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4462 | struct ModuleInfo { |
| 4463 | uint64_t ID; |
| 4464 | Module *M; |
| 4465 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 4466 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4467 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4468 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4469 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4470 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 4471 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4472 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4473 | |
| 4474 | if (!Imports.empty()) { |
| 4475 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4476 | return A.ID < B.ID; |
| 4477 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4478 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4479 | return A.ID == B.ID; |
| 4480 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4481 | |
| 4482 | // Sort and deduplicate module IDs. |
| 4483 | std::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4484 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4485 | Imports.end()); |
| 4486 | |
| 4487 | RecordData ImportedModules; |
| 4488 | for (const auto &Import : Imports) { |
| 4489 | ImportedModules.push_back(Import.ID); |
| 4490 | // FIXME: If the module has macros imported then later has declarations |
| 4491 | // imported, this location won't be the right one as a location for the |
| 4492 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4493 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4494 | } |
| 4495 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4496 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4497 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4498 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4499 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4500 | WriteDeclReplacementsBlock(); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 4501 | WriteRedeclarations(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4502 | WriteObjCCategories(); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4503 | WriteLateParsedTemplates(SemaRef); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4504 | if(!WritingModule) |
| 4505 | WriteOptimizePragmaOptions(SemaRef); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4506 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4507 | // Some simple statistics |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4508 | Record.clear(); |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4509 | Record.push_back(NumStatements); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 4510 | Record.push_back(NumMacros); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4511 | Record.push_back(NumLexicalDeclContexts); |
| 4512 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4513 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4514 | Stream.ExitBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4515 | } |
| 4516 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4517 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4518 | if (DeclUpdates.empty()) |
| 4519 | return; |
| 4520 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4521 | DeclUpdateMap LocalUpdates; |
| 4522 | LocalUpdates.swap(DeclUpdates); |
| 4523 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4524 | for (auto &DeclUpdate : LocalUpdates) { |
| 4525 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 4526 | if (isRewritten(D)) |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4527 | continue; // The decl will be written completely,no need to store updates. |
| 4528 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4529 | bool HasUpdatedBody = false; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4530 | RecordData Record; |
| 4531 | for (auto &Update : DeclUpdate.second) { |
| 4532 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 4533 | |
| 4534 | Record.push_back(Kind); |
| 4535 | switch (Kind) { |
| 4536 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 4537 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 4538 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4539 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4540 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 4541 | break; |
| 4542 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4543 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4544 | // An updated body is emitted last, so that the reader doesn't need |
| 4545 | // to skip over the lazy body to reach statements for other records. |
| 4546 | Record.pop_back(); |
| 4547 | HasUpdatedBody = true; |
| 4548 | break; |
| 4549 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4550 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
| 4551 | AddSourceLocation(Update.getLoc(), Record); |
| 4552 | break; |
| 4553 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4554 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4555 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 4556 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4557 | AddCXXDefinitionData(RD, Record); |
| 4558 | Record.push_back(WriteDeclContextLexicalBlock( |
| 4559 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 4560 | |
| 4561 | // This state is sometimes updated by template instantiation, when we |
| 4562 | // switch from the specialization referring to the template declaration |
| 4563 | // to it referring to the template definition. |
| 4564 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 4565 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
| 4566 | AddSourceLocation(MSInfo->getPointOfInstantiation(), Record); |
| 4567 | } else { |
| 4568 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 4569 | Record.push_back(Spec->getTemplateSpecializationKind()); |
| 4570 | AddSourceLocation(Spec->getPointOfInstantiation(), Record); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4571 | |
| 4572 | // The instantiation might have been resolved to a partial |
| 4573 | // specialization. If so, record which one. |
| 4574 | auto From = Spec->getInstantiatedFrom(); |
| 4575 | if (auto PartialSpec = |
| 4576 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 4577 | Record.push_back(true); |
| 4578 | AddDeclRef(PartialSpec, Record); |
| 4579 | AddTemplateArgumentList(&Spec->getTemplateInstantiationArgs(), |
| 4580 | Record); |
| 4581 | } else { |
| 4582 | Record.push_back(false); |
| 4583 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4584 | } |
| 4585 | Record.push_back(RD->getTagKind()); |
| 4586 | AddSourceLocation(RD->getLocation(), Record); |
| 4587 | AddSourceLocation(RD->getLocStart(), Record); |
| 4588 | AddSourceLocation(RD->getRBraceLoc(), Record); |
| 4589 | |
| 4590 | // Instantiation may change attributes; write them all out afresh. |
| 4591 | Record.push_back(D->hasAttrs()); |
| 4592 | if (Record.back()) |
Craig Topper | 8c2a2a0 | 2014-08-30 16:55:39 +0000 | [diff] [blame] | 4593 | WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(), |
| 4594 | D->getAttrs().size()), Record); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4595 | |
| 4596 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 4597 | break; |
| 4598 | } |
| 4599 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4600 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
| 4601 | AddDeclRef(Update.getDecl(), Record); |
| 4602 | break; |
| 4603 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4604 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 4605 | addExceptionSpec( |
| 4606 | *this, |
| 4607 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 4608 | Record); |
| 4609 | break; |
| 4610 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4611 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 4612 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 4613 | break; |
| 4614 | |
| 4615 | case UPD_DECL_MARKED_USED: |
| 4616 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4617 | |
| 4618 | case UPD_MANGLING_NUMBER: |
| 4619 | case UPD_STATIC_LOCAL_NUMBER: |
| 4620 | Record.push_back(Update.getNumber()); |
| 4621 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4622 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4623 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
| 4624 | AddSourceRange(D->getAttr<OMPThreadPrivateDeclAttr>()->getRange(), |
| 4625 | Record); |
| 4626 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4627 | |
| 4628 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 4629 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4630 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4631 | |
| 4632 | case UPD_ADDED_ATTR_TO_RECORD: |
| 4633 | WriteAttributes(llvm::makeArrayRef(Update.getAttr()), Record); |
| 4634 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4635 | } |
| 4636 | } |
| 4637 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4638 | if (HasUpdatedBody) { |
| 4639 | const FunctionDecl *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4640 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4641 | Record.push_back(Def->isInlined()); |
| 4642 | AddSourceLocation(Def->getInnerLocStart(), Record); |
| 4643 | AddFunctionDefinition(Def, Record); |
| 4644 | } |
| 4645 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4646 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 4647 | OffsetsRecord.push_back(Stream.GetCurrentBitNo()); |
| 4648 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4649 | Stream.EmitRecord(DECL_UPDATES, Record); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4650 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4651 | FlushPendingAfterDecl(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4652 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
Argyrios Kyrtzidis | 97bfda9 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 4655 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4656 | if (ReplacedDecls.empty()) |
| 4657 | return; |
| 4658 | |
| 4659 | RecordData Record; |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 4660 | for (SmallVectorImpl<ReplacedDeclInfo>::iterator |
| 4661 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
Argyrios Kyrtzidis | 6fb6003 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 4662 | Record.push_back(I->ID); |
| 4663 | Record.push_back(I->Offset); |
| 4664 | Record.push_back(I->Loc); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4665 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4666 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4667 | } |
| 4668 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4669 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4670 | Record.push_back(Loc.getRawEncoding()); |
| 4671 | } |
| 4672 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4673 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4674 | AddSourceLocation(Range.getBegin(), Record); |
| 4675 | AddSourceLocation(Range.getEnd(), Record); |
| 4676 | } |
| 4677 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4678 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4679 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4680 | const uint64_t *Words = Value.getRawData(); |
| 4681 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4682 | } |
| 4683 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4684 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4685 | Record.push_back(Value.isUnsigned()); |
| 4686 | AddAPInt(Value, Record); |
| 4687 | } |
| 4688 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4689 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4690 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 4691 | } |
| 4692 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4693 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4694 | Record.push_back(getIdentifierRef(II)); |
| 4695 | } |
| 4696 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4697 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4698 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4699 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4700 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4701 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4702 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4703 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4704 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4707 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4708 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 4709 | // have been redefined by the header (in which case they are not |
| 4710 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4711 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4712 | return 0; |
| 4713 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4714 | MacroID &ID = MacroIDs[MI]; |
| 4715 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4716 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4717 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 4718 | MacroInfosToEmit.push_back(Info); |
| 4719 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4720 | return ID; |
| 4721 | } |
| 4722 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4723 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4724 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4725 | return 0; |
| 4726 | |
| 4727 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 4728 | return MacroIDs[MI]; |
| 4729 | } |
| 4730 | |
| 4731 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 4732 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4735 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4736 | Record.push_back(getSelectorRef(SelRef)); |
| 4737 | } |
| 4738 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4739 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4740 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4741 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4742 | } |
| 4743 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4744 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4745 | if (SID == 0 && Chain) { |
| 4746 | // This might trigger a ReadSelector callback, which will set the ID for |
| 4747 | // this selector. |
| 4748 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4749 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4750 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4751 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4752 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4753 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4754 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4755 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4756 | } |
| 4757 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4758 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4759 | AddDeclRef(Temp->getDestructor(), Record); |
| 4760 | } |
| 4761 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4762 | void ASTWriter::AddCXXCtorInitializersRef(ArrayRef<CXXCtorInitializer *> Inits, |
| 4763 | RecordDataImpl &Record) { |
| 4764 | assert(!Inits.empty() && "Empty ctor initializer sets are not recorded"); |
| 4765 | CXXCtorInitializersToWrite.push_back( |
| 4766 | QueuedCXXCtorInitializers(NextCXXCtorInitializersID, Inits)); |
| 4767 | Record.push_back(NextCXXCtorInitializersID++); |
| 4768 | } |
| 4769 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4770 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4771 | CXXBaseSpecifier const *BasesEnd, |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4772 | RecordDataImpl &Record) { |
| 4773 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 4774 | CXXBaseSpecifiersToWrite.push_back( |
| 4775 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 4776 | Bases, BasesEnd)); |
| 4777 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 4778 | } |
| 4779 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4780 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4781 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4782 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4783 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4784 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4785 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4786 | break; |
| 4787 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4788 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4789 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4790 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4791 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4792 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4793 | break; |
| 4794 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4795 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4796 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4797 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4798 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4799 | case TemplateArgument::Null: |
| 4800 | case TemplateArgument::Integral: |
| 4801 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4802 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4803 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4804 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | } |
| 4808 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4809 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4810 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4811 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4812 | |
| 4813 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 4814 | bool InfoHasSameExpr |
| 4815 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 4816 | Record.push_back(InfoHasSameExpr); |
| 4817 | if (InfoHasSameExpr) |
| 4818 | return; // Avoid storing the same expr twice. |
| 4819 | } |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4820 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 4821 | Record); |
| 4822 | } |
| 4823 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4824 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 4825 | RecordDataImpl &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4826 | if (!TInfo) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4827 | AddTypeRef(QualType(), Record); |
| 4828 | return; |
| 4829 | } |
| 4830 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4831 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 4832 | } |
| 4833 | |
| 4834 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 4835 | AddTypeRef(TL.getType(), Record); |
| 4836 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4837 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4838 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4839 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4840 | } |
| 4841 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4842 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 4843 | Record.push_back(GetOrCreateTypeID(T)); |
| 4844 | } |
| 4845 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4846 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4847 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4848 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4849 | if (T.isNull()) |
| 4850 | return TypeIdx(); |
| 4851 | assert(!T.getLocalFastQualifiers()); |
| 4852 | |
| 4853 | TypeIdx &Idx = TypeIdxs[T]; |
| 4854 | if (Idx.getIndex() == 0) { |
| 4855 | if (DoneWritingDeclsAndTypes) { |
| 4856 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 4857 | return TypeIdx(); |
| 4858 | } |
| 4859 | |
| 4860 | // We haven't seen this type before. Assign it a new ID and put it |
| 4861 | // into the queue of types to emit. |
| 4862 | Idx = TypeIdx(NextTypeID++); |
| 4863 | DeclTypesToEmit.push(T); |
| 4864 | } |
| 4865 | return Idx; |
| 4866 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4867 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4868 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4869 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4870 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4871 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4872 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4873 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4874 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4875 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4876 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 4877 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 4878 | return I->second; |
| 4879 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4882 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4883 | Record.push_back(GetDeclRef(D)); |
| 4884 | } |
| 4885 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4886 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4887 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4888 | |
| 4889 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4890 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4891 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4892 | |
| 4893 | // If D comes from an AST file, its declaration ID is already known and |
| 4894 | // fixed. |
| 4895 | if (D->isFromASTFile()) |
| 4896 | return D->getGlobalID(); |
| 4897 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4898 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4899 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4900 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4901 | if (DoneWritingDeclsAndTypes) { |
| 4902 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 4903 | return 0; |
| 4904 | } |
| 4905 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4906 | // We haven't seen this declaration before. Give it a new ID and |
| 4907 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4908 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4909 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4912 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4915 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4916 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4917 | return 0; |
| 4918 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4919 | // If D comes from an AST file, its declaration ID is already known and |
| 4920 | // fixed. |
| 4921 | if (D->isFromASTFile()) |
| 4922 | return D->getGlobalID(); |
| 4923 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4924 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 4925 | return DeclIDs[D]; |
| 4926 | } |
| 4927 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4928 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4929 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4930 | assert(D); |
| 4931 | |
| 4932 | SourceLocation Loc = D->getLocation(); |
| 4933 | if (Loc.isInvalid()) |
| 4934 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4935 | |
| 4936 | // We only keep track of the file-level declarations of each file. |
| 4937 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 4938 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 4939 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 4940 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 4941 | if (isa<ParmVarDecl>(D)) |
| 4942 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4943 | |
| 4944 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4945 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4946 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4947 | FileID FID; |
| 4948 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 4949 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4950 | if (FID.isInvalid()) |
| 4951 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4952 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4953 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4954 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4955 | if (!Info) |
| 4956 | Info = new DeclIDInFileInfo(); |
| 4957 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4958 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4959 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 4960 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4961 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4962 | Decls.push_back(LocDecl); |
| 4963 | return; |
| 4964 | } |
| 4965 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 4966 | LocDeclIDsTy::iterator I = |
| 4967 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4968 | |
| 4969 | Decls.insert(I, LocDecl); |
| 4970 | } |
| 4971 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4972 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 4973 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4974 | Record.push_back(Name.getNameKind()); |
| 4975 | switch (Name.getNameKind()) { |
| 4976 | case DeclarationName::Identifier: |
| 4977 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 4978 | break; |
| 4979 | |
| 4980 | case DeclarationName::ObjCZeroArgSelector: |
| 4981 | case DeclarationName::ObjCOneArgSelector: |
| 4982 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4983 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4984 | break; |
| 4985 | |
| 4986 | case DeclarationName::CXXConstructorName: |
| 4987 | case DeclarationName::CXXDestructorName: |
| 4988 | case DeclarationName::CXXConversionFunctionName: |
| 4989 | AddTypeRef(Name.getCXXNameType(), Record); |
| 4990 | break; |
| 4991 | |
| 4992 | case DeclarationName::CXXOperatorName: |
| 4993 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 4994 | break; |
| 4995 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4996 | case DeclarationName::CXXLiteralOperatorName: |
| 4997 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 4998 | break; |
| 4999 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5000 | case DeclarationName::CXXUsingDirective: |
| 5001 | // No extra data to emit |
| 5002 | break; |
| 5003 | } |
| 5004 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5005 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5006 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5007 | assert(needsAnonymousDeclarationNumber(D) && |
| 5008 | "expected an anonymous declaration"); |
| 5009 | |
| 5010 | // Number the anonymous declarations within this context, if we've not |
| 5011 | // already done so. |
| 5012 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5013 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5014 | auto *DC = D->getLexicalDeclContext(); |
| 5015 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5016 | AnonymousDeclarationNumbers[ND] = Number; |
| 5017 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5018 | |
| 5019 | It = AnonymousDeclarationNumbers.find(D); |
| 5020 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5021 | "declaration not found within its lexical context"); |
| 5022 | } |
| 5023 | |
| 5024 | return It->second; |
| 5025 | } |
| 5026 | |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5027 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5028 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5029 | switch (Name.getNameKind()) { |
| 5030 | case DeclarationName::CXXConstructorName: |
| 5031 | case DeclarationName::CXXDestructorName: |
| 5032 | case DeclarationName::CXXConversionFunctionName: |
| 5033 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 5034 | break; |
| 5035 | |
| 5036 | case DeclarationName::CXXOperatorName: |
| 5037 | AddSourceLocation( |
| 5038 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 5039 | Record); |
| 5040 | AddSourceLocation( |
| 5041 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 5042 | Record); |
| 5043 | break; |
| 5044 | |
| 5045 | case DeclarationName::CXXLiteralOperatorName: |
| 5046 | AddSourceLocation( |
| 5047 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 5048 | Record); |
| 5049 | break; |
| 5050 | |
| 5051 | case DeclarationName::Identifier: |
| 5052 | case DeclarationName::ObjCZeroArgSelector: |
| 5053 | case DeclarationName::ObjCOneArgSelector: |
| 5054 | case DeclarationName::ObjCMultiArgSelector: |
| 5055 | case DeclarationName::CXXUsingDirective: |
| 5056 | break; |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5061 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5062 | AddDeclarationName(NameInfo.getName(), Record); |
| 5063 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 5064 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 5065 | } |
| 5066 | |
| 5067 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5068 | RecordDataImpl &Record) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5069 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5070 | Record.push_back(Info.NumTemplParamLists); |
| 5071 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 5072 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 5073 | } |
| 5074 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5075 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5076 | RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5077 | // Nested name specifiers usually aren't too long. I think that 8 would |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 5078 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5079 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5080 | |
| 5081 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5082 | while (NNS) { |
| 5083 | NestedNames.push_back(NNS); |
| 5084 | NNS = NNS->getPrefix(); |
| 5085 | } |
| 5086 | |
| 5087 | Record.push_back(NestedNames.size()); |
| 5088 | while(!NestedNames.empty()) { |
| 5089 | NNS = NestedNames.pop_back_val(); |
| 5090 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 5091 | Record.push_back(Kind); |
| 5092 | switch (Kind) { |
| 5093 | case NestedNameSpecifier::Identifier: |
| 5094 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 5095 | break; |
| 5096 | |
| 5097 | case NestedNameSpecifier::Namespace: |
| 5098 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 5099 | break; |
| 5100 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5101 | case NestedNameSpecifier::NamespaceAlias: |
| 5102 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 5103 | break; |
| 5104 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5105 | case NestedNameSpecifier::TypeSpec: |
| 5106 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 5107 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 5108 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5109 | break; |
| 5110 | |
| 5111 | case NestedNameSpecifier::Global: |
| 5112 | // Don't need to write an associated value. |
| 5113 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5114 | |
| 5115 | case NestedNameSpecifier::Super: |
| 5116 | AddDeclRef(NNS->getAsRecordDecl(), Record); |
| 5117 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5118 | } |
| 5119 | } |
| 5120 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5121 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5122 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 5123 | RecordDataImpl &Record) { |
| 5124 | // Nested name specifiers usually aren't too long. I think that 8 would |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 5125 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5126 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5127 | |
| 5128 | // Push each of the nested-name-specifiers's onto a stack for |
| 5129 | // serialization in reverse order. |
| 5130 | while (NNS) { |
| 5131 | NestedNames.push_back(NNS); |
| 5132 | NNS = NNS.getPrefix(); |
| 5133 | } |
| 5134 | |
| 5135 | Record.push_back(NestedNames.size()); |
| 5136 | while(!NestedNames.empty()) { |
| 5137 | NNS = NestedNames.pop_back_val(); |
| 5138 | NestedNameSpecifier::SpecifierKind Kind |
| 5139 | = NNS.getNestedNameSpecifier()->getKind(); |
| 5140 | Record.push_back(Kind); |
| 5141 | switch (Kind) { |
| 5142 | case NestedNameSpecifier::Identifier: |
| 5143 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 5144 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5145 | break; |
| 5146 | |
| 5147 | case NestedNameSpecifier::Namespace: |
| 5148 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 5149 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5150 | break; |
| 5151 | |
| 5152 | case NestedNameSpecifier::NamespaceAlias: |
| 5153 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 5154 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5155 | break; |
| 5156 | |
| 5157 | case NestedNameSpecifier::TypeSpec: |
| 5158 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 5159 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5160 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 5161 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 5162 | break; |
| 5163 | |
| 5164 | case NestedNameSpecifier::Global: |
| 5165 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 5166 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5167 | |
| 5168 | case NestedNameSpecifier::Super: |
| 5169 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl(), Record); |
| 5170 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5171 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5172 | } |
| 5173 | } |
| 5174 | } |
| 5175 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5176 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5177 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5178 | Record.push_back(Kind); |
| 5179 | switch (Kind) { |
| 5180 | case TemplateName::Template: |
| 5181 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 5182 | break; |
| 5183 | |
| 5184 | case TemplateName::OverloadedTemplate: { |
| 5185 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 5186 | Record.push_back(OvT->size()); |
| 5187 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 5188 | I != E; ++I) |
| 5189 | AddDeclRef(*I, Record); |
| 5190 | break; |
| 5191 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5192 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5193 | case TemplateName::QualifiedTemplate: { |
| 5194 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 5195 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 5196 | Record.push_back(QualT->hasTemplateKeyword()); |
| 5197 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 5198 | break; |
| 5199 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5200 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5201 | case TemplateName::DependentTemplate: { |
| 5202 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 5203 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 5204 | Record.push_back(DepT->isIdentifier()); |
| 5205 | if (DepT->isIdentifier()) |
| 5206 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 5207 | else |
| 5208 | Record.push_back(DepT->getOperator()); |
| 5209 | break; |
| 5210 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5211 | |
| 5212 | case TemplateName::SubstTemplateTemplateParm: { |
| 5213 | SubstTemplateTemplateParmStorage *subst |
| 5214 | = Name.getAsSubstTemplateTemplateParm(); |
| 5215 | AddDeclRef(subst->getParameter(), Record); |
| 5216 | AddTemplateName(subst->getReplacement(), Record); |
| 5217 | break; |
| 5218 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5219 | |
| 5220 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5221 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5222 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 5223 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 5224 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 5225 | break; |
| 5226 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5227 | } |
| 5228 | } |
| 5229 | |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5230 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5231 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5232 | Record.push_back(Arg.getKind()); |
| 5233 | switch (Arg.getKind()) { |
| 5234 | case TemplateArgument::Null: |
| 5235 | break; |
| 5236 | case TemplateArgument::Type: |
| 5237 | AddTypeRef(Arg.getAsType(), Record); |
| 5238 | break; |
| 5239 | case TemplateArgument::Declaration: |
| 5240 | AddDeclRef(Arg.getAsDecl(), Record); |
David Blaikie | 952a9b1 | 2014-10-17 18:00:12 +0000 | [diff] [blame] | 5241 | AddTypeRef(Arg.getParamTypeForDecl(), Record); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5242 | break; |
| 5243 | case TemplateArgument::NullPtr: |
| 5244 | AddTypeRef(Arg.getNullPtrType(), Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5245 | break; |
| 5246 | case TemplateArgument::Integral: |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 5247 | AddAPSInt(Arg.getAsIntegral(), Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5248 | AddTypeRef(Arg.getIntegralType(), Record); |
| 5249 | break; |
| 5250 | case TemplateArgument::Template: |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5251 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 5252 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5253 | case TemplateArgument::TemplateExpansion: |
| 5254 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5255 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5256 | Record.push_back(*NumExpansions + 1); |
| 5257 | else |
| 5258 | Record.push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5259 | break; |
| 5260 | case TemplateArgument::Expression: |
| 5261 | AddStmt(Arg.getAsExpr()); |
| 5262 | break; |
| 5263 | case TemplateArgument::Pack: |
| 5264 | Record.push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5265 | for (const auto &P : Arg.pack_elements()) |
| 5266 | AddTemplateArgument(P, Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5267 | break; |
| 5268 | } |
| 5269 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5270 | |
| 5271 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5272 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5273 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5274 | assert(TemplateParams && "No TemplateParams!"); |
| 5275 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 5276 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 5277 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 5278 | Record.push_back(TemplateParams->size()); |
| 5279 | for (TemplateParameterList::const_iterator |
| 5280 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 5281 | P != PEnd; ++P) |
| 5282 | AddDeclRef(*P, Record); |
| 5283 | } |
| 5284 | |
| 5285 | /// \brief Emit a template argument list. |
| 5286 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5287 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5288 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5289 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5290 | Record.push_back(TemplateArgs->size()); |
| 5291 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5292 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 5293 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5294 | |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5295 | void |
| 5296 | ASTWriter::AddASTTemplateArgumentListInfo |
| 5297 | (const ASTTemplateArgumentListInfo *ASTTemplArgList, RecordDataImpl &Record) { |
| 5298 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
| 5299 | AddSourceLocation(ASTTemplArgList->LAngleLoc, Record); |
| 5300 | AddSourceLocation(ASTTemplArgList->RAngleLoc, Record); |
| 5301 | Record.push_back(ASTTemplArgList->NumTemplateArgs); |
| 5302 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
| 5303 | for (int i=0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
| 5304 | AddTemplateArgumentLoc(TemplArgs[i], Record); |
| 5305 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5306 | |
| 5307 | void |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5308 | ASTWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5309 | Record.push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5310 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5311 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 5312 | AddDeclRef(I.getDecl(), Record); |
| 5313 | Record.push_back(I.getAccess()); |
| 5314 | } |
| 5315 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5316 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5317 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5318 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5319 | Record.push_back(Base.isVirtual()); |
| 5320 | Record.push_back(Base.isBaseOfClass()); |
| 5321 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5322 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5323 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5324 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5325 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 5326 | : SourceLocation(), |
| 5327 | Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5328 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5329 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5330 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 5331 | RecordData Record; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5332 | unsigned N = CXXBaseSpecifiersToWrite.size(); |
| 5333 | for (unsigned I = 0; I != N; ++I) { |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5334 | Record.clear(); |
| 5335 | |
| 5336 | // Record the offset of this base-specifier set. |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 5337 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5338 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 5339 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 5340 | else { |
| 5341 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 5342 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 5343 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 5344 | } |
| 5345 | |
| 5346 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 5347 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 5348 | Record.push_back(BEnd - B); |
| 5349 | for (; B != BEnd; ++B) |
| 5350 | AddCXXBaseSpecifier(*B, Record); |
| 5351 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | d585304 | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 5352 | |
| 5353 | // Flush any expressions that were written as part of the base specifiers. |
| 5354 | FlushStmts(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5357 | assert(N == CXXBaseSpecifiersToWrite.size() && |
| 5358 | "added more base specifiers while writing base specifiers"); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5359 | CXXBaseSpecifiersToWrite.clear(); |
| 5360 | } |
| 5361 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5362 | void ASTWriter::AddCXXCtorInitializers( |
| 5363 | const CXXCtorInitializer * const *CtorInitializers, |
| 5364 | unsigned NumCtorInitializers, |
| 5365 | RecordDataImpl &Record) { |
| 5366 | Record.push_back(NumCtorInitializers); |
| 5367 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 5368 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5369 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5370 | if (Init->isBaseInitializer()) { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5371 | Record.push_back(CTOR_INITIALIZER_BASE); |
Douglas Gregor | d73f3dd | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5372 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5373 | Record.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5374 | } else if (Init->isDelegatingInitializer()) { |
| 5375 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
Douglas Gregor | d73f3dd | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5376 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5377 | } else if (Init->isMemberInitializer()){ |
| 5378 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 5379 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5380 | } else { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5381 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5382 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5383 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5384 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5385 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 5386 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5387 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 5388 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 5389 | Record.push_back(Init->isWritten()); |
| 5390 | if (Init->isWritten()) { |
| 5391 | Record.push_back(Init->getSourceOrder()); |
| 5392 | } else { |
| 5393 | Record.push_back(Init->getNumArrayIndices()); |
| 5394 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 5395 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 5396 | } |
| 5397 | } |
| 5398 | } |
| 5399 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5400 | void ASTWriter::FlushCXXCtorInitializers() { |
| 5401 | RecordData Record; |
| 5402 | |
| 5403 | unsigned N = CXXCtorInitializersToWrite.size(); |
Daniel Jasper | c77b0a1 | 2015-03-24 08:06:38 +0000 | [diff] [blame] | 5404 | (void)N; // Silence unused warning in non-assert builds. |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5405 | for (auto &Init : CXXCtorInitializersToWrite) { |
| 5406 | Record.clear(); |
| 5407 | |
| 5408 | // Record the offset of this mem-initializer list. |
| 5409 | unsigned Index = Init.ID - 1; |
| 5410 | if (Index == CXXCtorInitializersOffsets.size()) |
| 5411 | CXXCtorInitializersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 5412 | else { |
| 5413 | if (Index > CXXCtorInitializersOffsets.size()) |
| 5414 | CXXCtorInitializersOffsets.resize(Index + 1); |
| 5415 | CXXCtorInitializersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 5416 | } |
| 5417 | |
| 5418 | AddCXXCtorInitializers(Init.Inits.data(), Init.Inits.size(), Record); |
| 5419 | Stream.EmitRecord(serialization::DECL_CXX_CTOR_INITIALIZERS, Record); |
| 5420 | |
| 5421 | // Flush any expressions that were written as part of the initializers. |
| 5422 | FlushStmts(); |
| 5423 | } |
| 5424 | |
| 5425 | assert(N == CXXCtorInitializersToWrite.size() && |
| 5426 | "added more ctor initializers while writing ctor initializers"); |
| 5427 | CXXCtorInitializersToWrite.clear(); |
| 5428 | } |
| 5429 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5430 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5431 | auto &Data = D->data(); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5432 | Record.push_back(Data.IsLambda); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5433 | Record.push_back(Data.UserDeclaredConstructor); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5434 | Record.push_back(Data.UserDeclaredSpecialMembers); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5435 | Record.push_back(Data.Aggregate); |
| 5436 | Record.push_back(Data.PlainOldData); |
| 5437 | Record.push_back(Data.Empty); |
| 5438 | Record.push_back(Data.Polymorphic); |
| 5439 | Record.push_back(Data.Abstract); |
Chandler Carruth | 583edf8 | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 5440 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | b196374 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 5441 | Record.push_back(Data.HasNoNonEmptyBases); |
| 5442 | Record.push_back(Data.HasPrivateFields); |
| 5443 | Record.push_back(Data.HasProtectedFields); |
| 5444 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 61226d3 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 5445 | Record.push_back(Data.HasMutableFields); |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 5446 | Record.push_back(Data.HasVariantMembers); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5447 | Record.push_back(Data.HasOnlyCMembers); |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 5448 | Record.push_back(Data.HasInClassInitializer); |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 5449 | Record.push_back(Data.HasUninitializedReferenceMember); |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 5450 | Record.push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 5451 | Record.push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 5452 | Record.push_back(Data.NeedOverloadResolutionForDestructor); |
| 5453 | Record.push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 5454 | Record.push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 5455 | Record.push_back(Data.DefaultedDestructorIsDeleted); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5456 | Record.push_back(Data.HasTrivialSpecialMembers); |
Richard Smith | b45a6f7 | 2014-04-17 20:33:01 +0000 | [diff] [blame] | 5457 | Record.push_back(Data.DeclaredNonTrivialSpecialMembers); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5458 | Record.push_back(Data.HasIrrelevantDestructor); |
Richard Smith | 111af8d | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 5459 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5460 | Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5461 | Record.push_back(Data.HasConstexprDefaultConstructor); |
Chandler Carruth | e71d062 | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 5462 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5463 | Record.push_back(Data.ComputedVisibleConversions); |
Alexis Hunt | ea6f032 | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 5464 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5465 | Record.push_back(Data.DeclaredSpecialMembers); |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 5466 | Record.push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 5467 | Record.push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 5468 | Record.push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 5469 | Record.push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5470 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5471 | |
| 5472 | Record.push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5473 | if (Data.NumBases > 0) |
| 5474 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 5475 | Record); |
| 5476 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5477 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 5478 | Record.push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5479 | if (Data.NumVBases > 0) |
| 5480 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 5481 | Record); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5482 | |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 5483 | AddUnresolvedSet(Data.Conversions.get(*Context), Record); |
| 5484 | AddUnresolvedSet(Data.VisibleConversions.get(*Context), Record); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5485 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 68ad0e7 | 2013-06-26 02:41:25 +0000 | [diff] [blame] | 5486 | AddDeclRef(D->getFirstFriend(), Record); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5487 | |
| 5488 | // Add lambda-specific data. |
| 5489 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5490 | auto &Lambda = D->getLambdaData(); |
Douglas Gregor | 680e9e0 | 2012-02-21 19:11:17 +0000 | [diff] [blame] | 5491 | Record.push_back(Lambda.Dependent); |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 5492 | Record.push_back(Lambda.IsGenericLambda); |
| 5493 | Record.push_back(Lambda.CaptureDefault); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5494 | Record.push_back(Lambda.NumCaptures); |
| 5495 | Record.push_back(Lambda.NumExplicitCaptures); |
Douglas Gregor | 6379854 | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 5496 | Record.push_back(Lambda.ManglingNumber); |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 5497 | AddDeclRef(Lambda.ContextDecl, Record); |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 5498 | AddTypeSourceInfo(Lambda.MethodTyInfo, Record); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5499 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5500 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5501 | AddSourceLocation(Capture.getLocation(), Record); |
| 5502 | Record.push_back(Capture.isImplicit()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5503 | Record.push_back(Capture.getCaptureKind()); |
| 5504 | switch (Capture.getCaptureKind()) { |
| 5505 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5506 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5507 | break; |
| 5508 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5509 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5510 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5511 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5512 | AddDeclRef(Var, Record); |
| 5513 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
| 5514 | : SourceLocation(), |
| 5515 | Record); |
| 5516 | break; |
| 5517 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5518 | } |
| 5519 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5520 | } |
| 5521 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5522 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5523 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5524 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5525 | assert(FirstDeclID == NextDeclID && |
| 5526 | FirstTypeID == NextTypeID && |
| 5527 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5528 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5529 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5530 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5531 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5532 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5533 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5534 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5535 | // Note, this will get called multiple times, once one the reader starts up |
| 5536 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5537 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5538 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5539 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5540 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5541 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5542 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5543 | NextDeclID = FirstDeclID; |
| 5544 | NextTypeID = FirstTypeID; |
| 5545 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5546 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5547 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5548 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5549 | } |
| 5550 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5551 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5552 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5553 | IdentID &StoredID = IdentifierIDs[II]; |
| 5554 | if (ID > StoredID) |
| 5555 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5556 | } |
| 5557 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5558 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5559 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5560 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5561 | if (ID > StoredID) |
| 5562 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5563 | } |
| 5564 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5565 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5566 | // Always take the highest-numbered type index. This copes with an interesting |
| 5567 | // case for chained AST writing where we schedule writing the type and then, |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5568 | // later, deserialize the type from another AST. In this case, we want to |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5569 | // keep the higher-numbered entry so that we can properly write it out to |
| 5570 | // the AST file. |
| 5571 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 5572 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 5573 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5574 | } |
| 5575 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5576 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5577 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5578 | SelectorID &StoredID = SelectorIDs[S]; |
| 5579 | if (ID > StoredID) |
| 5580 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5581 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5582 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5583 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5584 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5585 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5586 | MacroDefinitions[MD] = ID; |
| 5587 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5588 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5589 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 5590 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 5591 | SubmoduleIDs[Mod] = ID; |
| 5592 | } |
| 5593 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5594 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5595 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5596 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5597 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 5598 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5599 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5600 | // A forward reference was mutated into a definition. Rewrite it. |
| 5601 | // FIXME: This happens during template instantiation, should we |
| 5602 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5603 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 5604 | "completed a tag from another module but not by instantiation?"); |
| 5605 | DeclUpdates[RD].push_back( |
| 5606 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5607 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5608 | } |
| 5609 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5610 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5611 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
| 5612 | // TU and namespaces are handled elsewhere. |
| 5613 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 5614 | return; |
| 5615 | |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5616 | if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile())) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5617 | return; // Not a source decl added to a DeclContext from PCH. |
| 5618 | |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5619 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5620 | assert(!WritingAST && "Already writing the AST!"); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 5621 | UpdatedDeclContexts.insert(DC); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5622 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5623 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5624 | |
| 5625 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
| 5626 | assert(D->isImplicit()); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5627 | if (!(!D->isFromASTFile() && RD->isFromASTFile())) |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5628 | return; // Not a source member added to a class from PCH. |
| 5629 | if (!isa<CXXMethodDecl>(D)) |
| 5630 | return; // We are interested in lazily declared implicit methods. |
| 5631 | |
| 5632 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5633 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5634 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5635 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5636 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5637 | |
| 5638 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 5639 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | ef80a01 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 5640 | // The specializations set is kept in the canonical template. |
| 5641 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5642 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5643 | return; // Not a source specialization added to a template from PCH. |
| 5644 | |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5645 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5646 | DeclUpdates[TD].push_back(DeclUpdate(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, |
| 5647 | D)); |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5648 | } |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 5649 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5650 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 5651 | const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) { |
| 5652 | // The specializations set is kept in the canonical template. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5653 | TD = TD->getCanonicalDecl(); |
| 5654 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
| 5655 | return; // Not a source specialization added to a template from PCH. |
| 5656 | |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5657 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5658 | DeclUpdates[TD].push_back(DeclUpdate(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, |
| 5659 | D)); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 5662 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 5663 | const FunctionDecl *D) { |
| 5664 | // The specializations set is kept in the canonical template. |
| 5665 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5666 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 5667 | return; // Not a source specialization added to a template from PCH. |
| 5668 | |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5669 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5670 | DeclUpdates[TD].push_back(DeclUpdate(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, |
| 5671 | D)); |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 5672 | } |
| 5673 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5674 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5675 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 5676 | if (!Chain) return; |
| 5677 | Chain->forEachFormerlyCanonicalImportedDecl(FD, [&](const Decl *D) { |
| 5678 | // If we don't already know the exception specification for this redecl |
| 5679 | // chain, add an update record for it. |
| 5680 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 5681 | ->getType() |
| 5682 | ->castAs<FunctionProtoType>() |
| 5683 | ->getExceptionSpecType())) |
| 5684 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 5685 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5688 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
| 5689 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5690 | if (!Chain) return; |
| 5691 | Chain->forEachFormerlyCanonicalImportedDecl(FD, [&](const Decl *D) { |
| 5692 | DeclUpdates[D].push_back( |
| 5693 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 5694 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5697 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
| 5698 | const FunctionDecl *Delete) { |
| 5699 | assert(!WritingAST && "Already writing the AST!"); |
| 5700 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5701 | if (!Chain) return; |
| 5702 | Chain->forEachFormerlyCanonicalImportedDecl(DD, [&](const Decl *D) { |
| 5703 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 5704 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5705 | } |
| 5706 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5707 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5708 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5709 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5710 | return; // Declaration not imported from PCH. |
| 5711 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5712 | // Implicit function decl from a PCH was defined. |
| 5713 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5714 | } |
| 5715 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5716 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
| 5717 | assert(!WritingAST && "Already writing the AST!"); |
| 5718 | if (!D->isFromASTFile()) |
| 5719 | return; |
| 5720 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5721 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5722 | } |
| 5723 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5724 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5725 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5726 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5727 | return; |
| 5728 | |
| 5729 | // Since the actual instantiation is delayed, this really means that we need |
| 5730 | // to update the instantiation location. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5731 | DeclUpdates[D].push_back( |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5732 | DeclUpdate(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, |
| 5733 | D->getMemberSpecializationInfo()->getPointOfInstantiation())); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5734 | } |
| 5735 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5736 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 5737 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5738 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5739 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5740 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5741 | |
| 5742 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 5743 | ObjCClassesWithCategories.insert( |
| 5744 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5745 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5746 | |
Argyrios Kyrtzidis | 0ca3a8b | 2011-11-12 21:07:52 +0000 | [diff] [blame] | 5747 | |
Argyrios Kyrtzidis | 846e61a | 2011-11-14 04:52:29 +0000 | [diff] [blame] | 5748 | void ASTWriter::AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, |
| 5749 | const ObjCPropertyDecl *OrigProp, |
| 5750 | const ObjCCategoryDecl *ClassExt) { |
| 5751 | const ObjCInterfaceDecl *D = ClassExt->getClassInterface(); |
| 5752 | if (!D) |
| 5753 | return; |
| 5754 | |
| 5755 | assert(!WritingAST && "Already writing the AST!"); |
| 5756 | if (!D->isFromASTFile()) |
| 5757 | return; // Declaration not imported from PCH. |
| 5758 | |
| 5759 | RewriteDecl(D); |
| 5760 | } |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5761 | |
| 5762 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
| 5763 | assert(!WritingAST && "Already writing the AST!"); |
| 5764 | if (!D->isFromASTFile()) |
| 5765 | return; |
| 5766 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5767 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5768 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5769 | |
| 5770 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
| 5771 | assert(!WritingAST && "Already writing the AST!"); |
| 5772 | if (!D->isFromASTFile()) |
| 5773 | return; |
| 5774 | |
| 5775 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 5776 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5777 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5778 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5779 | assert(!WritingAST && "Already writing the AST!"); |
| 5780 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5781 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5782 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5783 | |
| 5784 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 5785 | const RecordDecl *Record) { |
| 5786 | assert(!WritingAST && "Already writing the AST!"); |
| 5787 | if (!Record->isFromASTFile()) |
| 5788 | return; |
| 5789 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 5790 | } |